@@ -4135,6 +4135,40 @@ gen_getblockparamproxy(jitstate_t *jit, ctx_t *ctx)
4135
4135
return YJIT_KEEP_COMPILING ;
4136
4136
}
4137
4137
4138
+ static codegen_status_t
4139
+ gen_invokebuiltin (jitstate_t * jit , ctx_t * ctx )
4140
+ {
4141
+ const struct rb_builtin_function * bf = (struct rb_builtin_function * )jit_get_arg (jit , 0 );
4142
+
4143
+ // ec, self, and arguments
4144
+ if (bf -> argc + 2 > NUM_C_ARG_REGS ) {
4145
+ return YJIT_CANT_COMPILE ;
4146
+ }
4147
+
4148
+ // If the calls don't allocate, do they need up to date PC, SP?
4149
+ jit_prepare_routine_call (jit , ctx , REG0 );
4150
+
4151
+ // Call the builtin func (ec, recv, arg1, arg2, ...)
4152
+ mov (cb , C_ARG_REGS [0 ], REG_EC );
4153
+ mov (cb , C_ARG_REGS [1 ], member_opnd (REG_CFP , rb_control_frame_t , self ));
4154
+
4155
+ // Copy arguments from locals
4156
+ for (int32_t i = 0 ; i < bf -> argc ; i ++ ) {
4157
+ x86opnd_t stack_opnd = ctx_stack_opnd (ctx , bf -> argc - i - 1 );
4158
+ x86opnd_t c_arg_reg = C_ARG_REGS [2 + i ];
4159
+ mov (cb , c_arg_reg , stack_opnd );
4160
+ }
4161
+
4162
+ call_ptr (cb , REG0 , (void * )bf -> func_ptr );
4163
+
4164
+ // Push the return value
4165
+ ctx_stack_pop (ctx , bf -> argc );
4166
+ x86opnd_t stack_ret = ctx_stack_push (ctx , TYPE_UNKNOWN );
4167
+ mov (cb , stack_ret , RAX );
4168
+
4169
+ return YJIT_KEEP_COMPILING ;
4170
+ }
4171
+
4138
4172
// opt_invokebuiltin_delegate calls a builtin function, like
4139
4173
// invokebuiltin does, but instead of taking arguments from the top of the
4140
4174
// stack uses the argument locals (and self) from the current method.
@@ -4144,7 +4178,8 @@ gen_opt_invokebuiltin_delegate(jitstate_t *jit, ctx_t *ctx)
4144
4178
const struct rb_builtin_function * bf = (struct rb_builtin_function * )jit_get_arg (jit , 0 );
4145
4179
int32_t start_index = (int32_t )jit_get_arg (jit , 1 );
4146
4180
4147
- if (bf -> argc + 2
8000
span> >= NUM_C_ARG_REGS ) {
4181
+ // ec, self, and arguments
4182
+ if (bf -> argc + 2 > NUM_C_ARG_REGS ) {
4148
4183
return YJIT_CANT_COMPILE ;
4149
4184
}
4150
4185
@@ -4386,6 +4421,7 @@ yjit_init_codegen(void)
4386
4421
yjit_reg_op (BIN (opt_length ), gen_opt_length );
4387
4422
yjit_reg_op (BIN (opt_regexpmatch2 ), gen_opt_regexpmatch2 );
4388
4423
yjit_reg_op (BIN (opt_getinlinecache ), gen_opt_getinlinecache );
4424
+ yjit_reg_op (BIN (invokebuiltin ), gen_invokebuiltin );
4389
4425
yjit_reg_op (BIN (opt_invokebuiltin_delegate ), gen_opt_invokebuiltin_delegate );
4390
4426
yjit_reg_op (BIN (opt_invokebuiltin_delegate_leave ), gen_opt_invokebuiltin_delegate );
4391
4427
yjit_reg_op (BIN (opt_case_dispatch ), gen_opt_case_dispatch );
0 commit comments