From f66e0212efe4f6572d5e81741e831ab735cc2fee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Thu, 9 Jul 2020 21:43:42 +0900 Subject: precalc invokebuiltin destinations Noticed that struct rb_builtin_function is a purely compile-time constant. MJIT can eliminate some runtime calculations by statically generate dedicated C code generator for each builtin functions. --- builtin.h | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'builtin.h') diff --git a/builtin.h b/builtin.h index ce02720e32..be7bb16a28 100644 --- a/builtin.h +++ b/builtin.h @@ -11,13 +11,17 @@ struct rb_builtin_function { // for load const int index; const char * const name; + + // for jit + void (*compiler)(FILE *, long); }; -#define RB_BUILTIN_FUNCTION(_i, _name, _fname, _arity) { \ +#define RB_BUILTIN_FUNCTION(_i, _name, _fname, _arity, _compiler) {\ .name = #_name, \ .func_ptr = (void *)_fname, \ .argc = _arity, \ - .index = _i \ + .index = _i, \ + .compiler = _compiler, \ } void rb_load_with_builtin_functions(const char *feature_name, const struct rb_builtin_function *table); @@ -76,4 +80,20 @@ struct builtin_binary { size_t bin_size; }; +// mjit + +RBIMPL_ATTR_MAYBE_UNUSED() +static void +mjit_invokebuiltin_default_compiler(FILE *f, const struct rb_builtin_function *bf, long index) +{ + if (index >= 0) { + fprintf(f, "val = vm_invoke_builtin(ec, GET_CFP(), %p, STACK_ADDR_FROM_TOP(%d));\n", + (const void *)bf, bf->argc); + } + else { + fprintf(f, "val = vm_invoke_builtin_delegate(ec, GET_CFP(), %p, %ld);\n", + (const void *)bf, index); + } +} + #endif // BUILTIN_H_INCLUDED -- cgit v1.2.1