mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
YJIT: Implement duphash (#5009)
`duphash` showed up in the top-20 most frequent exit ops for @jhawthorn's benchmark that renders github.com/about The implementation was almost exactly the same as `duparray` Co-authored-by: John Hawthorn <john@hawthorn.email> Co-authored-by: John Hawthorn <john@hawthorn.email>
This commit is contained in:
parent
1c0c8d5da2
commit
e943511455
Notes:
git
2021-10-25 23:40:55 +09:00
Merged-By: maximecb <maximecb@ruby-lang.org>
3 changed files with 32 additions and 0 deletions
|
@ -2268,3 +2268,13 @@ assert_equal "true", %q{
|
|||
|
||||
expected == events
|
||||
}
|
||||
|
||||
# duphash
|
||||
assert_equal '{:foo=>123}', %q{
|
||||
def foo
|
||||
{foo: 123}
|
||||
end
|
||||
|
||||
foo
|
||||
foo
|
||||
}
|
||||
|
|
|
@ -16903,6 +16903,7 @@ yjit.$(OBJEXT): $(top_srcdir)/internal/class.h
|
|||
yjit.$(OBJEXT): $(top_srcdir)/internal/compile.h
|
||||
yjit.$(OBJEXT): $(top_srcdir)/internal/compilers.h
|
||||
yjit.$(OBJEXT): $(top_srcdir)/internal/gc.h
|
||||
yjit.$(OBJEXT): $(top_srcdir)/internal/hash.h
|
||||
yjit.$(OBJEXT): $(top_srcdir)/internal/imemo.h
|
||||
yjit.$(OBJEXT): $(top_srcdir)/internal/object.h
|
||||
yjit.$(OBJEXT): $(top_srcdir)/internal/re.h
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "gc.h"
|
||||
#include "internal/compile.h"
|
||||
#include "internal/class.h"
|
||||
#include "internal/hash.h"
|
||||
#include "internal/object.h"
|
||||
#include "internal/sanitizers.h"
|
||||
#include "internal/string.h"
|
||||
|
@ -895,6 +896,25 @@ gen_duparray(jitstate_t *jit, ctx_t *ctx, codeblock_t *cb)
|
|||
return YJIT_KEEP_COMPILING;
|
||||
}
|
||||
|
||||
// dup hash
|
||||
static codegen_status_t
|
||||
gen_duphash(jitstate_t *jit, ctx_t *ctx, codeblock_t *cb)
|
||||
{
|
||||
VALUE hash = jit_get_arg(jit, 0);
|
||||
|
||||
// Save the PC and SP because we are allocating
|
||||
jit_prepare_routine_call(jit, ctx, REG0);
|
||||
|
||||
// call rb_hash_resurrect(VALUE hash);
|
||||
jit_mov_gc_ptr(jit, cb, C_ARG_REGS[0], hash);
|
||||
call_ptr(cb, REG0, (void *)rb_hash_resurrect);
|
||||
|
||||
x86opnd_t stack_ret = ctx_stack_push(ctx, TYPE_HASH);
|
||||
mov(cb, stack_ret, RAX);
|
||||
|
||||
return YJIT_KEEP_COMPILING;
|
||||
}
|
||||
|
||||
VALUE rb_vm_splat_array(VALUE flag, VALUE ary);
|
||||
|
||||
// call to_a on the array on the stack
|
||||
|
@ -4640,6 +4660,7 @@ yjit_init_codegen(void)
|
|||
yjit_reg_op(BIN(adjuststack), gen_adjuststack);
|
||||
yjit_reg_op(BIN(newarray), gen_newarray);
|
||||
yjit_reg_op(BIN(duparray), gen_duparray);
|
||||
yjit_reg_op(BIN(duphash), gen_duphash);
|
||||
yjit_reg_op(BIN(splatarray), gen_splatarray);
|
||||
yjit_reg_op(BIN(expandarray), gen_expandarray);
|
||||
yjit_reg_op(BIN(newhash), gen_newhash);
|
||||
|
|
Loading…
Add table
Reference in a new issue