ruby-changes:68699
From: Maxime <ko1@a...>
Date: Thu, 21 Oct 2021 08:12:28 +0900 (JST)
Subject: [ruby-changes:68699] 3a74011ff8 (master): Introduce version_t struct. Will be needed for code invalidation.
https://git.ruby-lang.org/ruby.git/commit/?id=3a74011ff8 From 3a74011ff8e5b9b4bf07ef72d249d08b8c13c57e Mon Sep 17 00:00:00 2001 From: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@s...> Date: Tue, 12 Jan 2021 14:56:43 -0500 Subject: Introduce version_t struct. Will be needed for code invalidation. --- ujit_asm.c | 142 +++++++++++++++++++++++++++---------------------------- ujit_asm.h | 102 +++++++++++++++++++-------------------- ujit_asm_tests.c | 14 +++--- ujit_codegen.c | 16 +++---- ujit_codegen.h | 4 +- ujit_core.c | 57 +++++++++++----------- ujit_core.h | 24 +++++++++- 7 files changed, 187 insertions(+), 172 deletions(-) diff --git a/ujit_asm.c b/ujit_asm.c index 4fb0cc764a..231e83b5c8 100644 --- a/ujit_asm.c +++ b/ujit_asm.c @@ -14,7 +14,7 @@ https://github.com/ruby/ruby/blob/trunk/ujit_asm.c#L14 #include "ujit_asm.h" // Compute the number of bits needed to encode a signed value -size_t sig_imm_size(int64_t imm) +uint32_t sig_imm_size(int64_t imm) { // Compute the smallest size this immediate fits in if (imm >= -128 && imm <= 127) @@ -28,7 +28,7 @@ size_t sig_imm_size(int64_t imm) https://github.com/ruby/ruby/blob/trunk/ujit_asm.c#L28 } // Compute the number of bits needed to encode an unsigned value -size_t unsig_imm_size(uint64_t imm) +uint32_t unsig_imm_size(uint64_t imm) { // Compute the smallest size this immediate fits in if (imm <= 255) @@ -41,7 +41,7 @@ size_t unsig_imm_size(uint64_t imm) https://github.com/ruby/ruby/blob/trunk/ujit_asm.c#L41 return 64; } -x86opnd_t mem_opnd(size_t num_bits, x86opnd_t base_reg, int32_t disp) +x86opnd_t mem_opnd(uint32_t num_bits, x86opnd_t base_reg, int32_t disp) { bool is_iprel = base_reg.as.reg.reg_type == REG_IP; @@ -54,7 +54,7 @@ x86opnd_t mem_opnd(size_t num_bits, x86opnd_t base_reg, int32_t disp) https://github.com/ruby/ruby/blob/trunk/ujit_asm.c#L54 return opnd; } -x86opnd_t resize_opnd(x86opnd_t opnd, size_t num_bits) +x86opnd_t resize_opnd(x86opnd_t opnd, uint32_t num_bits) { assert (num_bits % 8 == 0); x86opnd_t sub = opnd; @@ -85,7 +85,7 @@ x86opnd_t const_ptr_opnd(const void *ptr) https://github.com/ruby/ruby/blob/trunk/ujit_asm.c#L85 } // Allocate a block of executable memory -uint8_t* alloc_exec_mem(size_t mem_size) +uint8_t* alloc_exec_mem(uint32_t mem_size) { #ifndef _WIN32 // Map the memory as executable @@ -112,7 +112,7 @@ uint8_t* alloc_exec_mem(size_t mem_size) https://github.com/ruby/ruby/blob/trunk/ujit_asm.c#L112 } // Initialize a code block object -void cb_init(codeblock_t* cb, uint8_t* mem_block, size_t mem_size) +void cb_init(codeblock_t* cb, uint8_t* mem_block, uint32_t mem_size) { cb->mem_block = mem_block; cb->mem_size = mem_size; @@ -122,30 +122,30 @@ void cb_init(codeblock_t* cb, uint8_t* mem_block, size_t mem_size) https://github.com/ruby/ruby/blob/trunk/ujit_asm.c#L122 } // Align the current write position to a multiple of bytes -void cb_align_pos(codeblock_t* cb, size_t multiple) +void cb_align_pos(codeblock_t* cb, uint32_t multiple) { // Compute the pointer modulo the given alignment boundary uint8_t* ptr = &cb->mem_block[cb->write_pos]; - size_t rem = ((size_t)ptr) % multiple; + uint32_t rem = ((uint32_t)ptr) % multiple; // If the pointer is already aligned, stop if (rem != 0) return; // Pad the pointer by the necessary amount to align it - size_t pad = multiple - rem; + uint32_t pad = multiple - rem; cb->write_pos += pad; } // Set the current write position -void cb_set_pos(codeblock_t* cb, size_t pos) +void cb_set_pos(codeblock_t* cb, uint32_t pos) { assert (pos < cb->mem_size); cb->write_pos = pos; } // Get a direct pointer into the executable memory block -uint8_t* cb_get_ptr(codeblock_t* cb, size_t index) +uint8_t* cb_get_ptr(codeblock_t* cb, uint32_t index) { assert (index < cb->mem_size); return &cb->mem_block[index]; @@ -160,12 +160,12 @@ void cb_write_byte(codeblock_t* cb, uint8_t byte) https://github.com/ruby/ruby/blob/trunk/ujit_asm.c#L160 } // Write multiple bytes starting from the current position -void cb_write_bytes(codeblock_t* cb, size_t num_bytes, ...) +void cb_write_bytes(codeblock_t* cb, uint32_t num_bytes, ...) { va_list va; va_start(va, num_bytes); - for (size_t i = 0; i < num_bytes; ++i) + for (uint32_t i = 0; i < num_bytes; ++i) { uint8_t byte = va_arg(va, int); cb_write_byte(cb, byte); @@ -175,7 +175,7 @@ void cb_write_bytes(codeblock_t* cb, size_t num_bytes, ...) https://github.com/ruby/ruby/blob/trunk/ujit_asm.c#L175 } // Write a signed integer over a given number of bits at the current position -void cb_write_int(codeblock_t* cb, uint64_t val, size_t num_bits) +void cb_write_int(codeblock_t* cb, uint64_t val, uint32_t num_bits) { assert (num_bits > 0); assert (num_bits % 8 == 0); @@ -210,10 +210,10 @@ void cb_write_int(codeblock_t* cb, uint64_t val, size_t num_bits) https://github.com/ruby/ruby/blob/trunk/ujit_asm.c#L210 default: { // Compute the size in bytes - size_t num_bytes = num_bits / 8; + uint32_t num_bytes = num_bits / 8; // Write out the bytes - for (size_t i = 0; i < num_bytes; ++i) + for (uint32_t i = 0; i < num_bytes; ++i) { uint8_t byte_val = (uint8_t)(val & 0xFF); cb_write_byte(cb, byte_val); @@ -224,7 +224,7 @@ void cb_write_int(codeblock_t* cb, uint64_t val, size_t num_bits) https://github.com/ruby/ruby/blob/trunk/ujit_asm.c#L224 } // Allocate a new label with a given name -size_t cb_new_label(codeblock_t* cb, const char* name) +uint32_t cb_new_label(codeblock_t* cb, const char* name) { //if (hasASM) // writeString(to!string(label) ~ ":"); @@ -232,7 +232,7 @@ size_t cb_new_label(codeblock_t* cb, const char* name) https://github.com/ruby/ruby/blob/trunk/ujit_asm.c#L232 assert (cb->num_labels < MAX_LABELS); // Allocate the new label - size_t label_idx = cb->num_labels++; + uint32_t label_idx = cb->num_labels++; // This label doesn't have an address yet cb->label_addrs[label_idx] = 0; @@ -242,14 +242,14 @@ size_t cb_new_label(codeblock_t* cb, const char* name) https://github.com/ruby/ruby/blob/trunk/ujit_asm.c#L242 } // Write a label at the current address -void cb_write_label(codeblock_t* cb, size_t label_idx) +void cb_write_label(codeblock_t* cb, uint32_t label_idx) { assert (label_idx < MAX_LABELS); cb->label_addrs[label_idx] = cb->write_pos; } // Add a label reference at the current write position -void cb_label_ref(codeblock_t* cb, size_t label_idx) +void cb_label_ref(codeblock_t* cb, uint32_t label_idx) { assert (label_idx < MAX_LABELS); assert (cb->num_refs < MAX_LABEL_REFS); @@ -262,17 +262,17 @@ void cb_label_ref(codeblock_t* cb, size_t label_idx) https://github.com/ruby/ruby/blob/trunk/ujit_asm.c#L262 // Link internal label references void cb_link_labels(codeblock_t* cb) { - size_t orig_pos = cb->write_pos; + uint32_t orig_pos = cb->write_pos; // For each label reference - for (size_t i = 0; i < cb->num_refs; ++i) + for (uint32_t i = 0; i < cb->num_refs; ++i) { - size_t ref_pos = cb->label_refs[i].pos; - size_t label_idx = cb->label_refs[i].label_idx; + uint32_t ref_pos = cb->label_refs[i].pos; + uint32_t label_idx = cb->label_refs[i].label_idx; assert (ref_pos < cb->mem_size); assert (label_idx < MAX_LABELS); - size_t label_addr = cb->label_addrs[label_idx]; + uint32_t label_addr = cb->label_addrs[label_idx]; assert (label_addr < cb->mem_size); // Compute the offset from the reference's end to the label @@ -327,7 +327,7 @@ bool sib_needed(x86opnd_t opnd) https://github.com/ruby/ruby/blob/trunk/ujit_asm.c#L327 } // Compute the size of the displacement field needed for a memory operand -size_t disp_size(x86opnd_t opnd) +uint32_t disp_size(x86opnd_t opnd) { assert (opnd.type == OPND_MEM); @@ -340,7 +340,7 @@ size_t disp_size(x86opnd_t opnd) https://github.com/ruby/ruby/blob/trunk/ujit_asm.c#L340 // Compute the required displacement size if (opnd.as.mem.disp != 0) { - size_t num_bits = sig_imm_size(opnd.as.mem.disp); + uint32_t num_bits = sig_imm_size(opnd.as.mem.disp); assert (num_bits <= 32 && "displacement does not fit in 32 bits"); // x86 can only encode 8-bit and 32-bit displacements @@ -400,7 +400,7 @@ void cb_write_rm( https://github.com/ruby/ruby/blob/trunk/ujit_asm.c#L400 x86opnd_t r_opnd, x86opnd_t rm_opnd, uint8_t opExt, - size_t op_len, + uint32_t op_len, ...) { assert (op_len > 0 && op_len <= 3); @@ -455,7 +455,7 @@ void cb_write_rm( https://github.com/ruby/ruby/blob/trunk/ujit_asm.c#L455 // Write the opcode bytes to the code block va_list va; va_start(va, op_len); - for (size_t i = 0; i < op_len; ++i) + for (uint32_t i = 0; i < op_len; ++i) { uint8_t byte = va_arg(va, int); cb_write_byte(cb, byte); @@ -479,7 +479,7 @@ void cb_write_rm( https://github.com/ruby/ruby/blob/trunk/ujit_asm.c#L479 } else { - size_t dsize = disp_size(rm_opnd); + uint32_t dsize = disp_size(rm_opnd); if (dsize == 0 || rm_opnd.as.mem.is_iprel) mod = 0; else if (dsize == 8) @@ -547,7 +547,7 @@ void cb_write_rm( https://github.com/ruby/ruby/blob/trunk/ujit_asm.c#L547 // Add the displacement if (rm_opnd.type == OPND_MEM) { - size_t dsize = disp_size(rm_opnd); + uint32_t dsize = disp_size(rm_opnd); if (dsize > 0) cb_write_int(cb, rm_opnd.as.mem.disp, dsize); } @@ -566,7 +566,7 @@ void write_rm_unary( https://github.com/ruby/ruby/blob/trunk/ujit_asm.c#L566 //cb.writeASM(mnem, opnd); // (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/