summaryrefslogtreecommitdiff
path: root/yjit_codegen.c
diff options
context:
space:
mode:
authorJohn Hawthorn <john@hawthorn.email>2021-09-27 22:28:33 -0700
committerAlan Wu <XrXr@users.noreply.github.com>2021-10-20 18:19:41 -0400
commit5b68d14c2fcacc2f185a1933ce9b102cb06b1ba5 (patch)
tree9554e6c1389ad79767432f8a158286f5511a04d8 /yjit_codegen.c
parent5c15850ea622d8ad86fa14cb5b9ba6f03abb232e (diff)
Add optimized Thread.current
Diffstat (limited to 'yjit_codegen.c')
-rw-r--r--yjit_codegen.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/yjit_codegen.c b/yjit_codegen.c
index e788ac2797..7e765b2503 100644
--- a/yjit_codegen.c
+++ b/yjit_codegen.c
@@ -3053,6 +3053,23 @@ jit_rb_str_to_s(jitstate_t *jit, ctx_t *ctx, const struct rb_callinfo *ci, const
return false;
}
+static bool
+jit_thread_s_current(jitstate_t *jit, ctx_t *ctx, const struct rb_callinfo *ci, const rb_callable_method_entry_t *cme, rb_iseq_t *block, const int32_t argc, VALUE *recv_known_klass)
+{
+ ADD_COMMENT(cb, "Thread.current");
+ ctx_stack_pop(ctx, 1);
+
+ // ec->thread_ptr
+ mov(cb, REG0, member_opnd(REG_EC, rb_execution_context_t, thread_ptr));
+
+ // thread->self
+ mov(cb, REG0, member_opnd(REG0, rb_thread_t, self));
+
+ x86opnd_t stack_ret = ctx_stack_push(ctx, TYPE_HEAP);
+ mov(cb, stack_ret, REG0);
+ return true;
+}
+
// Check if we know how to codegen for a particular cfunc method
static method_codegen_t
lookup_cfunc_codegen(const rb_method_definition_t *def)
@@ -4493,4 +4510,7 @@ yjit_init_codegen(void)
// rb_str_to_s() methods in string.c
yjit_reg_method(rb_cString, "to_s", jit_rb_str_to_s);
yjit_reg_method(rb_cString, "to_str", jit_rb_str_to_s);
+
+ // Thread.current
+ yjit_reg_method(rb_singleton_class(rb_cThread), "current", jit_thread_s_current);
}