diff options
| author | Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com> | 2022-05-24 12:03:21 -0400 |
|---|---|---|
| committer | Takashi Kokubun <takashikkbn@gmail.com> | 2022-08-29 08:46:53 -0700 |
| commit | 0032b02045af081df30f35b508b6b790e44fcdc2 (patch) | |
| tree | b9d37b1731693fcedbc719615e4b20fe76432912 | |
| parent | 872940e215dd571c45e9c30d96fa7b9f61dc0442 (diff) | |
Add gen_dupn
| -rw-r--r-- | yjit/src/backend/ir.rs | 4 | ||||
| -rw-r--r-- | yjit/src/codegen.rs | 48 |
2 files changed, 52 insertions, 0 deletions
diff --git a/yjit/src/backend/ir.rs b/yjit/src/backend/ir.rs index 22350ec506..932ba9f0be 100644 --- a/yjit/src/backend/ir.rs +++ b/yjit/src/backend/ir.rs @@ -631,6 +631,10 @@ def_push_2_opnd_no_out!(test, Op::Test); // They are just wrappers to convert from X86Opnd into the IR Opnd type impl Context { + pub fn ir_stack_opnd(&mut self, idx: i32) -> Opnd { + self.stack_opnd(idx).into() + } + pub fn ir_stack_pop(&mut self, n: usize) -> Opnd { self.stack_pop(n).into() } diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs index 1799036e46..834b75192a 100644 --- a/yjit/src/codegen.rs +++ b/yjit/src/codegen.rs @@ -932,6 +932,7 @@ fn gen_dup( +/* // duplicate stack top n elements fn gen_dupn( jit: &mut JITState, @@ -963,6 +964,53 @@ fn gen_dupn( KeepCompiling } +*/ + + +// duplicate stack top n elements +fn gen_dupn( + jit: &mut JITState, + ctx: &mut Context, + cb: &mut CodeBlock, + _ocb: &mut OutlinedCb, +) -> CodegenStatus { + + let mut asm = Assembler::new(); + + let nval: VALUE = jit_get_arg(jit, 0); + let VALUE(n) = nval; + + // In practice, seems to be only used for n==2 + if n != 2 { + return CantCompile; + } + + let opnd1: Opnd = ctx.ir_stack_opnd(1); + let opnd0: Opnd = ctx.ir_stack_opnd(0); + + let mapping1 = ctx.get_opnd_mapping(StackOpnd(1)); + let mapping0 = ctx.get_opnd_mapping(StackOpnd(0)); + + let dst1: Opnd = ctx.ir_stack_push_mapping(mapping1); + asm.mov(dst1, opnd1); + + let dst0: Opnd = ctx.ir_stack_push_mapping(mapping0); + asm.mov(dst0, opnd0); + + asm.compile(cb); + + KeepCompiling +} + + + + + + + + + + // Swap top 2 stack entries fn gen_swap( |
