Skip to content

Commit

Permalink
YJIT: Extract SHAPE_ID_NUM_BITS into a constant (#6863)
Browse files Browse the repository at this point in the history
  • Loading branch information
jemmaissroff committed Dec 5, 2022
1 parent 1602d75 commit e7642d8
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 17 deletions.
8 changes: 1 addition & 7 deletions shape.c
Expand Up @@ -300,16 +300,10 @@ rb_shape_set_shape(VALUE obj, rb_shape_t* shape)
rb_shape_set_shape_id(obj, rb_shape_id(shape));
}

uint8_t
rb_shape_id_num_bits(void)
{
return SHAPE_ID_NUM_BITS;
}

int32_t
rb_shape_id_offset(void)
{
return 8 - rb_shape_id_num_bits() / 8;
return sizeof(uintptr_t) - SHAPE_ID_NUM_BITS / sizeof(uintptr_t);
}

rb_shape_t *
Expand Down
2 changes: 1 addition & 1 deletion yjit/bindgen/src/main.rs
Expand Up @@ -85,12 +85,12 @@ fn main() {
// From shape.h
.allowlist_function("rb_shape_get_shape_id")
.allowlist_function("rb_shape_get_shape_by_id")
.allowlist_function("rb_shape_id_num_bits")
.allowlist_function("rb_shape_id_offset")
.allowlist_function("rb_shape_get_iv_index")
.allowlist_function("rb_shape_get_next")
.allowlist_function("rb_shape_id")
.allowlist_function("rb_shape_transition_shape_capa")
.allowlist_var("SHAPE_ID_NUM_BITS")

// From ruby/internal/intern/object.h
.allowlist_function("rb_obj_is_kind_of")
Expand Down
9 changes: 3 additions & 6 deletions yjit/src/codegen.rs
Expand Up @@ -2045,9 +2045,8 @@ fn gen_get_ivar(
let embed_test_result = unsafe { FL_TEST_RAW(comptime_receiver, VALUE(ROBJECT_EMBED.as_usize())) != VALUE(0) };

let expected_shape = unsafe { rb_shape_get_shape_id(comptime_receiver) };
let shape_bit_size = unsafe { rb_shape_id_num_bits() }; // either 16 or 32 depending on RUBY_DEBUG
let shape_id_offset = unsafe { rb_shape_id_offset() };
let shape_opnd = Opnd::mem(shape_bit_size, recv, shape_id_offset);
let shape_opnd = Opnd::mem(SHAPE_ID_NUM_BITS as u8, recv, shape_id_offset);

asm.comment("guard shape");
asm.cmp(shape_opnd, Opnd::UImm(expected_shape as u64));
Expand Down Expand Up @@ -2269,9 +2268,8 @@ fn gen_setinstancevariable(
}

let expected_shape = unsafe { rb_shape_get_shape_id(comptime_receiver) };
let shape_bit_size = unsafe { rb_shape_id_num_bits() }; // either 16 or 32 depending on RUBY_DEBUG
let shape_id_offset = unsafe { rb_shape_id_offset() };
let shape_opnd = Opnd::mem(shape_bit_size, recv, shape_id_offset);
let shape_opnd = Opnd::mem(SHAPE_ID_NUM_BITS as u8, recv, shape_id_offset);

asm.comment("guard shape");
asm.cmp(shape_opnd, Opnd::UImm(expected_shape as u64));
Expand Down Expand Up @@ -2334,9 +2332,8 @@ fn gen_setinstancevariable(

asm.comment("write shape");

let shape_bit_size = unsafe { rb_shape_id_num_bits() }; // either 16 or 32 depending on RUBY_DEBUG
let shape_id_offset = unsafe { rb_shape_id_offset() };
let shape_opnd = Opnd::mem(shape_bit_size, recv, shape_id_offset);
let shape_opnd = Opnd::mem(SHAPE_ID_NUM_BITS as u8, recv, shape_id_offset);

// Store the new shape
asm.store(shape_opnd, Opnd::UImm(new_shape_id as u64));
Expand Down
4 changes: 1 addition & 3 deletions yjit/src/cruby_bindings.inc.rs
Expand Up @@ -123,6 +123,7 @@ impl<T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
}
}
impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {}
pub const SHAPE_ID_NUM_BITS: u32 = 32;
pub const INTEGER_REDEFINED_OP_FLAG: u32 = 1;
pub const FLOAT_REDEFINED_OP_FLAG: u32 = 2;
pub const STRING_REDEFINED_OP_FLAG: u32 = 4;
Expand Down Expand Up @@ -443,9 +444,6 @@ pub struct rb_shape {
pub parent_id: shape_id_t,
}
pub type rb_shape_t = rb_shape;
extern "C" {
pub fn rb_shape_id_num_bits() -> u8;
}
extern "C" {
pub fn rb_shape_id_offset() -> i32;
}
Expand Down

0 comments on commit e7642d8

Please sign in to comment.