summaryrefslogtreecommitdiff
path: root/builtin.h
diff options
context:
space:
mode:
author卜部昌平 <shyouhei@ruby-lang.org>2020-07-09 21:43:42 +0900
committer卜部昌平 <shyouhei@ruby-lang.org>2020-07-13 08:56:18 +0900
commitf66e0212efe4f6572d5e81741e831ab735cc2fee (patch)
tree94b45502a7d483489b697c3966b7d75e9cfd9b40 /builtin.h
parent5d02c1dd14648d95178ac5ec756f5b03fe00d549 (diff)
downloadruby-f66e0212efe4f6572d5e81741e831ab735cc2fee.tar.gz
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.
Diffstat (limited to 'builtin.h')
-rw-r--r--builtin.h24
1 files changed, 22 insertions, 2 deletions
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