From 877cb438262b5ab98e25ae88fa66d9f22aace9cd Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 16 Nov 2018 07:26:54 -0800 Subject: compiler: use binary versions of common math functions. * arith.c (arith_init): Register functions in the sys package: b<, b>, b<=, b=, b+, b-, b*, b/ and neg. * share/txr/stdlib/compiler.tl (%nary-ops%, %bin-ops%, %bin-op%): New global variables. (compiler comp-fun-form): Transform two-argument calls to any of the variadic functions in %nary-ops% functions into calls to their binary counterpart. These calls are faster, since they bypass the wrapper which deals with the variable argument list. Also, we detect unary - and map it to the new sys:neg function, and reduce the one-argument cases of certain functions to noops. --- arith.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'arith.c') diff --git a/arith.c b/arith.c index ceb8d96e..90575fc5 100644 --- a/arith.c +++ b/arith.c @@ -3288,6 +3288,17 @@ void arith_init(void) reg_fun(intern(lit("poly"), user_package), func_n2(poly)); reg_fun(intern(lit("rpoly"), user_package), func_n2(rpoly)); + reg_fun(intern(lit("b<"), system_package), func_n2(lt)); + reg_fun(intern(lit("b>"), system_package), func_n2(gt)); + reg_fun(intern(lit("b<="), system_package), func_n2(le)); + reg_fun(intern(lit("b=>"), system_package), func_n2(ge)); + reg_fun(intern(lit("b="), system_package), func_n2(numeq)); + reg_fun(intern(lit("b+"), system_package), func_n2(plus)); + reg_fun(intern(lit("b-"), system_package), func_n2(minus)); + reg_fun(intern(lit("b*"), system_package), func_n2(mul)); + reg_fun(intern(lit("b/"), system_package), func_n2(divi)); + reg_fun(intern(lit("neg"), system_package), func_n1(neg)); + #if HAVE_ROUNDING_CTL_H reg_varl(intern(lit("flo-near"), user_package), num(FE_TONEAREST)); reg_varl(intern(lit("flo-down"), user_package), num(FE_DOWNWARD)); -- cgit v1.2.3