ffi: use newer prim-closure representation for foreign functions
Cuts 1/3 of the time off a call for a micro-benchmark, since the path from JIT-generated code to C code is faster.
This commit is contained in:
parent
9e8477dd45
commit
42a0342109
|
@ -3041,9 +3041,10 @@ static void finish_ffi_call(ffi_cif *cif, void *c_func, intptr_t cfoff,
|
|||
ffi_call(cif, (VoidFun)W_OFFSET(c_func, cfoff), p, avalues);
|
||||
}
|
||||
|
||||
Scheme_Object *ffi_do_call(void *data, int argc, Scheme_Object *argv[])
|
||||
Scheme_Object *ffi_do_call(int argc, Scheme_Object *argv[], Scheme_Object *self)
|
||||
/* data := {name, c-function, itypes, otype, cif} */
|
||||
{
|
||||
Scheme_Object *data = SCHEME_PRIM_CLOSURE_ELS(self)[0];
|
||||
const char *name = SCHEME_BYTE_STR_VAL(SCHEME_VEC_ELS(data)[0]);
|
||||
void *c_func = (void*)(SCHEME_VEC_ELS(data)[1]);
|
||||
Scheme_Object *itypes = SCHEME_VEC_ELS(data)[2];
|
||||
|
@ -3174,7 +3175,7 @@ static Scheme_Object *foreign_ffi_call(int argc, Scheme_Object *argv[])
|
|||
{
|
||||
Scheme_Object *itypes = argv[1];
|
||||
Scheme_Object *otype = argv[2];
|
||||
Scheme_Object *obj, *data, *p, *base, *cp, *name;
|
||||
Scheme_Object *obj, *data, *p, *base, *cp, *name, *a[1];
|
||||
ffi_abi abi;
|
||||
intptr_t ooff;
|
||||
GC_CAN_IGNORE ffi_type *rtype, **atypes;
|
||||
|
@ -3247,9 +3248,11 @@ static Scheme_Object *foreign_ffi_call(int argc, Scheme_Object *argv[])
|
|||
SCHEME_VEC_ELS(data)[7] = (orig_place ? scheme_true : scheme_false);
|
||||
# endif /* MZ_USE_PLACES */
|
||||
scheme_register_finalizer(data, free_fficall_data, cif, NULL, NULL);
|
||||
return scheme_make_closed_prim_w_arity(ffi_do_call, (void*)data,
|
||||
SCHEME_BYTE_STR_VAL(name),
|
||||
nargs, nargs);
|
||||
a[0] = data;
|
||||
return scheme_make_prim_closure_w_arity(ffi_do_call,
|
||||
1, a,
|
||||
SCHEME_BYTE_STR_VAL(name),
|
||||
nargs, nargs);
|
||||
}
|
||||
#undef MYNAME
|
||||
|
||||
|
|
|
@ -2397,9 +2397,10 @@ static void finish_ffi_call(ffi_cif *cif, void *c_func, intptr_t cfoff,
|
|||
ffi_call(cif, (VoidFun)W_OFFSET(c_func, cfoff), p, avalues);
|
||||
}
|
||||
|
||||
Scheme_Object *ffi_do_call(void *data, int argc, Scheme_Object *argv[])
|
||||
Scheme_Object *ffi_do_call(int argc, Scheme_Object *argv[], Scheme_Object *self)
|
||||
/* data := {name, c-function, itypes, otype, cif} */
|
||||
{
|
||||
Scheme_Object *data = SCHEME_PRIM_CLOSURE_ELS(self)[0];
|
||||
const char *name = SCHEME_BYTE_STR_VAL(SCHEME_VEC_ELS(data)[0]);
|
||||
void *c_func = (void*)(SCHEME_VEC_ELS(data)[1]);
|
||||
Scheme_Object *itypes = SCHEME_VEC_ELS(data)[2];
|
||||
|
@ -2528,7 +2529,7 @@ static Scheme_Object *ffi_name = NULL;
|
|||
@cdefine[ffi-call 3 6]{
|
||||
Scheme_Object *itypes = argv[1];
|
||||
Scheme_Object *otype = argv[2];
|
||||
Scheme_Object *obj, *data, *p, *base, *cp, *name;
|
||||
Scheme_Object *obj, *data, *p, *base, *cp, *name, *a[1];
|
||||
ffi_abi abi;
|
||||
intptr_t ooff;
|
||||
GC_CAN_IGNORE ffi_type *rtype, **atypes;
|
||||
|
@ -2601,9 +2602,11 @@ static Scheme_Object *ffi_name = NULL;
|
|||
SCHEME_VEC_ELS(data)[7] = (orig_place ? scheme_true : scheme_false);
|
||||
}
|
||||
scheme_register_finalizer(data, free_fficall_data, cif, NULL, NULL);
|
||||
return scheme_make_closed_prim_w_arity(ffi_do_call, (void*)data,
|
||||
SCHEME_BYTE_STR_VAL(name),
|
||||
nargs, nargs);
|
||||
a[0] = data;
|
||||
return scheme_make_prim_closure_w_arity(ffi_do_call,
|
||||
1, a,
|
||||
SCHEME_BYTE_STR_VAL(name),
|
||||
nargs, nargs);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
Loading…
Reference in New Issue
Block a user