diff options
author | John Hawthorn <john@hawthorn.email> | 2021-05-26 12:40:50 -0700 |
---|---|---|
committer | Alan Wu <XrXr@users.noreply.github.com> | 2021-10-20 18:19:35 -0400 |
commit | 9283fc1bb554da800fe02bdd1653520f8b743344 (patch) | |
tree | c009d34703d19d194464746282bb7fdbce89849f /yjit_codegen.c | |
parent | b415ceb92e464011a9326c9cb5e15a84c39da330 (diff) |
Implement opt_freeze and opt_uminus (#49)
Diffstat (limited to 'yjit_codegen.c')
-rw-r--r-- | yjit_codegen.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/yjit_codegen.c b/yjit_codegen.c index 6b32b4e4e7..c2bdd96e86 100644 --- a/yjit_codegen.c +++ b/yjit_codegen.c @@ -1734,6 +1734,40 @@ gen_opt_empty_p(jitstate_t* jit, ctx_t* ctx) } static codegen_status_t +gen_opt_str_freeze(jitstate_t* jit, ctx_t* ctx) +{ + if (!assume_bop_not_redefined(jit->block, STRING_REDEFINED_OP_FLAG, BOP_FREEZE)) { + return YJIT_CANT_COMPILE; + } + + VALUE str = jit_get_arg(jit, 0); + jit_mov_gc_ptr(jit, cb, REG0, str); + + // Push the return value onto the stack + x86opnd_t stack_ret = ctx_stack_push(ctx, TYPE_STRING); + mov(cb, stack_ret, REG0); + + return YJIT_KEEP_COMPILING; +} + +static codegen_status_t +gen_opt_str_uminus(jitstate_t* jit, ctx_t* ctx) +{ + if (!assume_bop_not_redefined(jit->block, STRING_REDEFINED_OP_FLAG, BOP_UMINUS)) { + return YJIT_CANT_COMPILE; + } + + VALUE str = jit_get_arg(jit, 0); + jit_mov_gc_ptr(jit, cb, REG0, str); + + // Push the return value onto the stack + x86opnd_t stack_ret = ctx_stack_push(ctx, TYPE_STRING); + mov(cb, stack_ret, REG0); + + return YJIT_KEEP_COMPILING; +} + +static codegen_status_t gen_opt_not(jitstate_t* jit, ctx_t* ctx) { // Defer compilation so we can specialize type of argument @@ -2837,6 +2871,8 @@ yjit_init_codegen(void) yjit_reg_op(BIN(opt_ltlt), gen_opt_ltlt); yjit_reg_op(BIN(opt_nil_p), gen_opt_nil_p); yjit_reg_op(BIN(opt_empty_p), gen_opt_empty_p); + yjit_reg_op(BIN(opt_str_freeze), gen_opt_str_freeze); + yjit_reg_op(BIN(opt_str_uminus), gen_opt_str_uminus); yjit_reg_op(BIN(opt_not), gen_opt_not); yjit_reg_op(BIN(opt_getinlinecache), gen_opt_getinlinecache); yjit_reg_op(BIN(branchif), gen_branchif); |