diff options
| author | Andrea Corallo | 2019-07-06 11:02:52 +0200 |
|---|---|---|
| committer | Andrea Corallo | 2020-01-01 11:33:49 +0100 |
| commit | 98b500a0a21b486a98bf4e1ae989fd38616164bc (patch) | |
| tree | c0c036525a4eaaf42da6288b422d40cec3ad5e24 /src/comp.c | |
| parent | 4992fba7c56a4e7de8af4e79305883b505a84da4 (diff) | |
| download | emacs-98b500a0a21b486a98bf4e1ae989fd38616164bc.tar.gz emacs-98b500a0a21b486a98bf4e1ae989fd38616164bc.zip | |
optimize outgoing native manyarg calls
Diffstat (limited to 'src/comp.c')
| -rw-r--r-- | src/comp.c | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/src/comp.c b/src/comp.c index 0fadeaad11c..d705b5fa70f 100644 --- a/src/comp.c +++ b/src/comp.c | |||
| @@ -2398,12 +2398,10 @@ compile_f (const char *lisp_f_name, const char *c_f_name, | |||
| 2398 | docall: | 2398 | docall: |
| 2399 | { | 2399 | { |
| 2400 | res = NULL; | 2400 | res = NULL; |
| 2401 | ptrdiff_t nargs = op + 1; | 2401 | pop (op + 1, &stack, args); |
| 2402 | pop (nargs, &stack, args); | ||
| 2403 | if (stack->const_set && | 2402 | if (stack->const_set && |
| 2404 | stack->type == Lisp_Symbol) | 2403 | stack->type == Lisp_Symbol) |
| 2405 | { | 2404 | { |
| 2406 | ptrdiff_t native_nargs = op; | ||
| 2407 | char *sym_name = (char *) SDATA (SYMBOL_NAME (stack->constant)); | 2405 | char *sym_name = (char *) SDATA (SYMBOL_NAME (stack->constant)); |
| 2408 | if (!strcmp (sym_name, | 2406 | if (!strcmp (sym_name, |
| 2409 | lisp_f_name)) | 2407 | lisp_f_name)) |
| @@ -2412,24 +2410,49 @@ compile_f (const char *lisp_f_name, const char *c_f_name, | |||
| 2412 | res = gcc_jit_context_new_call (comp.ctxt, | 2410 | res = gcc_jit_context_new_call (comp.ctxt, |
| 2413 | NULL, | 2411 | NULL, |
| 2414 | comp.func, | 2412 | comp.func, |
| 2415 | native_nargs, | 2413 | op, |
| 2416 | args + 1); | 2414 | args + 1); |
| 2417 | } else if (SUBRP ((XSYMBOL (stack->constant)->u.s.function))) | 2415 | } else if (SUBRP ((XSYMBOL (stack->constant)->u.s.function))) |
| 2418 | { | 2416 | { |
| 2419 | /* Optimize primitive native calls. */ | 2417 | /* Optimize primitive native calls. */ |
| 2420 | emit_comment (format_string ("Calling primitive %s", | 2418 | emit_comment (format_string ("Calling primitive %s", |
| 2421 | sym_name)); | 2419 | sym_name)); |
| 2420 | /* FIXME we really should check is a primitive too!! */ | ||
| 2422 | struct Lisp_Subr *subr = | 2421 | struct Lisp_Subr *subr = |
| 2423 | XSUBR ((XSYMBOL (stack->constant)->u.s.function)); | 2422 | XSUBR ((XSYMBOL (stack->constant)->u.s.function)); |
| 2424 | if (subr->max_args == MANY) | 2423 | if (subr->max_args == MANY) |
| 2425 | { | 2424 | { |
| 2426 | /* FIXME: do we want to optimize this case too? */ | 2425 | /* f (nargs, args); */ |
| 2427 | goto dofuncall; | 2426 | args[0] = |
| 2427 | gcc_jit_context_new_rvalue_from_int ( | ||
| 2428 | comp.ctxt, | ||
| 2429 | comp.ptrdiff_type, | ||
| 2430 | op); | ||
| 2431 | args[1] = | ||
| 2432 | gcc_jit_lvalue_get_address ((stack + 1)->gcc_lval, | ||
| 2433 | NULL); | ||
| 2434 | gcc_jit_type *types[] = | ||
| 2435 | { comp.ptrdiff_type, comp.lisp_obj_ptr_type }; | ||
| 2436 | gcc_jit_type *fn_ptr_type = | ||
| 2437 | gcc_jit_context_new_function_ptr_type ( | ||
| 2438 | comp.ctxt, | ||
| 2439 | NULL, | ||
| 2440 | comp.lisp_obj_type, | ||
| 2441 | 2, types, 0); | ||
| 2442 | res = | ||
| 2443 | gcc_jit_context_new_call_through_ptr ( | ||
| 2444 | comp.ctxt, | ||
| 2445 | NULL, | ||
| 2446 | gcc_jit_context_new_rvalue_from_ptr ( | ||
| 2447 | comp.ctxt, | ||
| 2448 | fn_ptr_type, | ||
| 2449 | subr->function.a0), | ||
| 2450 | 2, args); | ||
| 2428 | } else | 2451 | } else |
| 2429 | { | 2452 | { |
| 2430 | gcc_jit_type *types[native_nargs]; | 2453 | gcc_jit_type *types[op]; |
| 2431 | 2454 | ||
| 2432 | for (int i = 0; i < native_nargs; i++) | 2455 | for (int i = 0; i < op; i++) |
| 2433 | types[i] = comp.lisp_obj_type; | 2456 | types[i] = comp.lisp_obj_type; |
| 2434 | 2457 | ||
| 2435 | gcc_jit_type *fn_ptr_type = | 2458 | gcc_jit_type *fn_ptr_type = |
| @@ -2437,7 +2460,7 @@ compile_f (const char *lisp_f_name, const char *c_f_name, | |||
| 2437 | comp.ctxt, | 2460 | comp.ctxt, |
| 2438 | NULL, | 2461 | NULL, |
| 2439 | comp.lisp_obj_type, | 2462 | comp.lisp_obj_type, |
| 2440 | native_nargs, | 2463 | op, |
| 2441 | types, | 2464 | types, |
| 2442 | 0); | 2465 | 0); |
| 2443 | res = | 2466 | res = |
| @@ -2448,15 +2471,14 @@ compile_f (const char *lisp_f_name, const char *c_f_name, | |||
| 2448 | comp.ctxt, | 2471 | comp.ctxt, |
| 2449 | fn_ptr_type, | 2472 | fn_ptr_type, |
| 2450 | subr->function.a0), | 2473 | subr->function.a0), |
| 2451 | native_nargs, | 2474 | op, |
| 2452 | args + 1); | 2475 | args + 1); |
| 2453 | } | 2476 | } |
| 2454 | } | 2477 | } |
| 2455 | } | 2478 | } |
| 2456 | dofuncall: | ||
| 2457 | /* Fall back to regular funcall dispatch mechanism. */ | 2479 | /* Fall back to regular funcall dispatch mechanism. */ |
| 2458 | if (!res) | 2480 | if (!res) |
| 2459 | res = emit_call_n_ref ("Ffuncall", nargs, stack->gcc_lval); | 2481 | res = emit_call_n_ref ("Ffuncall", op + 1, stack->gcc_lval); |
| 2460 | 2482 | ||
| 2461 | PUSH_RVAL (res); | 2483 | PUSH_RVAL (res); |
| 2462 | break; | 2484 | break; |