ruby-changes:68738
From: Maxime <ko1@a...>
Date: Thu, 21 Oct 2021 08:13:09 +0900 (JST)
Subject: [ruby-changes:68738] 53bd13edf3 (master): Implement opt_and in ujit
https://git.ruby-lang.org/ruby.git/commit/?id=53bd13edf3 From 53bd13edf3b41b965297d4ed425a96b9b57dd053 Mon Sep 17 00:00:00 2001 From: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@s...> Date: Mon, 1 Feb 2021 11:51:47 -0500 Subject: Implement opt_and in ujit --- ujit_codegen.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/ujit_codegen.c b/ujit_codegen.c index 7c7457aea3..3dd6f174ac 100644 --- a/ujit_codegen.c +++ b/ujit_codegen.c @@ -588,6 +588,50 @@ gen_opt_lt(jitstate_t* jit, ctx_t* ctx) https://github.com/ruby/ruby/blob/trunk/ujit_codegen.c#L588 return true; } +static bool +gen_opt_and(jitstate_t* jit, ctx_t* ctx) +{ + // Create a size-exit to fall back to the interpreter + // Note: we generate the side-exit before popping operands from the stack + uint8_t* side_exit = ujit_side_exit(jit, ctx); + + // TODO: make a helper function for guarding on op-not-redefined + // Make sure that plus isn't redefined for integers + mov(cb, RAX, const_ptr_opnd(ruby_current_vm_ptr)); + test( + cb, + member_opnd_idx(RAX, rb_vm_t, redefined_flag, BOP_AND), + imm_opnd(INTEGER_REDEFINED_OP_FLAG) + ); + jnz_ptr(cb, side_exit); + + // Get the operands and destination from the stack + int arg1_type = ctx_get_top_type(ctx); + x86opnd_t arg1 = ctx_stack_pop(ctx, 1); + int arg0_type = ctx_get_top_type(ctx); + x86opnd_t arg0 = ctx_stack_pop(ctx, 1); + + // If not fixnums, fall back + if (arg0_type != T_FIXNUM) { + test(cb, arg0, imm_opnd(RUBY_FIXNUM_FLAG)); + jz_ptr(cb, side_exit); + } + if (arg1_type != T_FIXNUM) { + test(cb, arg1, imm_opnd(RUBY_FIXNUM_FLAG)); + jz_ptr(cb, side_exit); + } + + // Do the bitwise and arg0 & arg1 + mov(cb, REG0, arg0); + and(cb, REG0, arg1); + + // Push the output on the stack + x86opnd_t dst = ctx_stack_push(ctx, T_FIXNUM); + mov(cb, dst, REG0); + + return true; +} + static bool gen_opt_minus(jitstate_t* jit, ctx_t* ctx) { @@ -1146,6 +1190,7 @@ ujit_init_codegen(void) https://github.com/ruby/ruby/blob/trunk/ujit_codegen.c#L1190 ujit_reg_op(BIN(getinstancevariable), gen_getinstancevariable, false); ujit_reg_op(BIN(setinstancevariable), gen_setinstancevariable, false); ujit_reg_op(BIN(opt_lt), gen_opt_lt, false); + ujit_reg_op(BIN(opt_and), gen_opt_and, false); ujit_reg_op(BIN(opt_minus), gen_opt_minus, false); ujit_reg_op(BIN(opt_plus), gen_opt_plus, false); ujit_reg_op(BIN(branchif), gen_branchif, true); -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/