Skip to content

Commit 7b9aeaf

Browse files
author
Maxime Chevalier-Boisvert
authored
YJIT: shrink stack_size/sp_offet to u8/i8 (#7426)
1 parent 34026af commit 7b9aeaf

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

yjit/src/backend/ir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub enum Opnd
7373
InsnOut{ idx: usize, num_bits: u8 },
7474

7575
// Pointer to a slot on the VM stack
76-
Stack { idx: i32, sp_offset: i16, num_bits: u8 },
76+
Stack { idx: i32, sp_offset: i8, num_bits: u8 },
7777

7878
// Low-level operands, for lowering
7979
Imm(i64), // Raw signed immediate

yjit/src/codegen.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ fn verify_ctx(jit: &JITState, ctx: &Context) {
319319
}
320320

321321
// Verify stack operand types
322-
let top_idx = cmp::min(ctx.get_stack_size(), MAX_TEMP_TYPES as u16);
322+
let top_idx = cmp::min(ctx.get_stack_size(), MAX_TEMP_TYPES as u8);
323323
for i in 0..top_idx {
324324
let (learned_mapping, learned_type) = ctx.get_opnd_mapping(StackOpnd(i));
325325
let stack_val = jit.peek_at_stack(ctx, i as isize);
@@ -5854,7 +5854,7 @@ fn gen_send_iseq(
58545854

58555855
// Set the argument types in the callee's context
58565856
for arg_idx in 0..argc {
5857-
let stack_offs: u16 = (argc - arg_idx - 1).try_into().unwrap();
5857+
let stack_offs: u8 = (argc - arg_idx - 1).try_into().unwrap();
58585858
let arg_type = ctx.get_opnd_type(StackOpnd(stack_offs));
58595859
callee_ctx.set_local_type(arg_idx.try_into().unwrap(), arg_type);
58605860
}

yjit/src/core.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,13 @@ pub enum YARVOpnd {
340340
SelfOpnd,
341341

342342
// Temporary stack operand with stack index
343-
StackOpnd(u16),
343+
StackOpnd(u8),
344344
}
345345

346346
impl From<Opnd> for YARVOpnd {
347347
fn from(value: Opnd) -> Self {
348348
match value {
349-
Opnd::Stack { idx, .. } => StackOpnd(idx as u16),
349+
Opnd::Stack { idx, .. } => StackOpnd(idx.try_into().unwrap()),
350350
_ => unreachable!("{:?} cannot be converted to YARVOpnd", value)
351351
}
352352
}
@@ -358,11 +358,11 @@ impl From<Opnd> for YARVOpnd {
358358
#[derive(Clone, Default, PartialEq, Debug)]
359359
pub struct Context {
360360
// Number of values currently on the temporary stack
361-
stack_size: u16,
361+
stack_size: u8,
362362

363363
// Offset of the JIT SP relative to the interpreter SP
364364
// This represents how far the JIT's SP is from the "real" SP
365-
sp_offset: i16,
365+
sp_offset: i8,
366366

367367
// Depth of this block in the sidechain (eg: inline-cache chain)
368368
chain_depth: u8,
@@ -1265,15 +1265,15 @@ impl Block {
12651265
}
12661266

12671267
impl Context {
1268-
pub fn get_stack_size(&self) -> u16 {
1268+
pub fn get_stack_size(&self) -> u8 {
12691269
self.stack_size
12701270
}
12711271

1272-
pub fn get_sp_offset(&self) -> i16 {
1272+
pub fn get_sp_offset(&self) -> i8 {
12731273
self.sp_offset
12741274
}
12751275

1276-
pub fn set_sp_offset(&mut self, offset: i16) {
1276+
pub fn set_sp_offset(&mut self, offset: i8) {
12771277
self.sp_offset = offset;
12781278
}
12791279

@@ -1359,16 +1359,16 @@ impl Context {
13591359
}
13601360
}
13611361

1362-
self.stack_size -= n as u16;
1363-
self.sp_offset -= n as i16;
1362+
self.stack_size -= n as u8;
1363+
self.sp_offset -= n as i8;
13641364

13651365
return top;
13661366
}
13671367

13681368
pub fn shift_stack(&mut self, argc: usize) {
13691369
assert!(argc < self.stack_size.into());
13701370

1371-
let method_name_index = (self.stack_size - argc as u16 - 1) as usize;
1371+
let method_name_index = (self.stack_size as usize) - (argc as usize) - 1;
13721372

13731373
for i in method_name_index..(self.stack_size - 1) as usize {
13741374

0 commit comments

Comments
 (0)