[Ecls-list] Inline floating point operations.
Waldek Hebisch
hebisch at math.uni.wroc.pl
Tue Jul 30 23:47:28 UTC 2013
I wrote:
>
> Oops. I keep forgeting that ecl ignores optimize proclaims
> made before loading compiler. If I repeat proclaim and
> compilation the second compilation indeed produces
> optimized output.
ecl produced inline code for arithmetic operations, but
still produced generic calls for 'max' and comparisons.
Also, I used '(FLOAT-SIGN 1.0d0 x)' to compute absolute
value of x and ecl was unable to optimize it.
To get fully optimized code I had to add inline declarations
for comparisons, MIN, MAX and FLOAT-SIGN, see attached
diff to 'sysfun.lsp'.
Also, in the example code I copied arguments to local
variables. Without such copy on assignment to argument
ecl conses Lisp double float and assign it to the
argument. AFAICS in case of arguments of declared type
good tactic is to create "shadow variables" which have
appropriate C type, copy values of arguments on
entry to the function and then only use "shadow variables".
It would be nice if ecl could do this automatically,
without need for programmer declaring such variables
at Lisp level.
--
Waldek Hebisch
hebisch at math.uni.wroc.pl
-------------- next part --------------
diff -ru ../ecl-13.5.1/src/cmp/sysfun.lsp ecl-13.5.1/src/cmp/sysfun.lsp
--- ../ecl-13.5.1/src/cmp/sysfun.lsp 2013-07-30 18:07:10.000000000 +0000
+++ ecl-13.5.1/src/cmp/sysfun.lsp 2013-07-30 21:09:07.000000000 +0000
@@ -427,6 +424,9 @@
(def-inline denominator :unsafe (integer) integer "ecl_make_fixnum(1)")
(def-inline denominator :unsafe (ratio) integer "(#0)->ratio.den")
+(def-inline float-sign :always ((double-float 1.0d0 1.0d0) double-float)
+ :double "fabs(#1)")
+
(def-inline floor :always (t) (values &rest t) "ecl_floor1(#0)")
(def-inline floor :always (t t) (values &rest t) "ecl_floor2(#0,#1)")
#+(or) ; does not work well, no multiple values
@@ -453,35 +453,45 @@
(def-inline = :always (t t) :bool "ecl_number_equalp(#0,#1)")
(def-inline = :always (fixnum-float fixnum-float) :bool "(#0)==(#1)")
+(def-inline = :always (double-float double-float) :bool "((#0)==(#1))")
(def-inline /= :always (t t) :bool "!ecl_number_equalp(#0,#1)")
(def-inline /= :always (fixnum-float fixnum-float) :bool "(#0)!=(#1)")
+(def-inline /= :always (double-float double-float) :bool "((#0)!=(#1))")
(def-inline < :always (t t) :bool "ecl_number_compare(#0,#1)<0")
(def-inline < :always (fixnum-float fixnum-float) :bool "(#0)<(#1)")
(def-inline < :always (fixnum-float fixnum-float fixnum-float) :bool
"@012;((#0)<(#1) && (#1)<(#2))")
+(def-inline < :always (double-float double-float) :bool "((#0)<(#1))")
(def-inline > :always (t t) :bool "ecl_number_compare(#0,#1)>0")
(def-inline > :always (fixnum-float fixnum-float) :bool "(#0)>(#1)")
(def-inline > :always (fixnum-float fixnum-float fixnum-float) :bool
"@012;((#0)>(#1) && (#1)>(#2))")
+(def-inline > :always (double-float double-float) :bool "((#0)>(#1))")
(def-inline <= :always (t t) :bool "ecl_number_compare(#0,#1)<=0")
(def-inline <= :always (fixnum-float fixnum-float) :bool "(#0)<=(#1)")
(def-inline <= :always (fixnum-float fixnum-float fixnum-float) :bool
"@012;((#0)<=(#1) && (#1)<=(#2))")
+(def-inline <= :always (double-float double-float) :bool "((#0)<=(#1))")
(def-inline >= :always (t t) :bool "ecl_number_compare(#0,#1)>=0")
(def-inline >= :always (fixnum-float fixnum-float) :bool "(#0)>=(#1)")
(def-inline >= :always (fixnum-float fixnum-float fixnum-float) :bool
"@012;((#0)>=(#1) && (#1)>=(#2))")
+(def-inline >= :always (double-float double-float) :bool "((#0)>=(#1))")
(def-inline max :always (t t) t "@01;(ecl_number_compare(#0,#1)>=0?#0:#1)")
(def-inline max :always (fixnum fixnum) :fixnum "@01;(#0)>=(#1)?#0:#1")
+(def-inline max :always (double-float double-float) :double
+ "@01;((#0)>=(#1)?(#0):(#1))")
(def-inline min :always (t t) t "@01;(ecl_number_compare(#0,#1)<=0?#0:#1)")
(def-inline min :always (fixnum fixnum) :fixnum "@01;(#0)<=(#1)?#0:#1")
+(def-inline min :always (double-float double-float) :double
+ "@01;((#0)<=(#1)?(#0):(#1))")
;; file num_log.d
More information about the ecl-devel
mailing list