fixnum macros vs procedures Per Bothner (15 May 2017 05:22 UTC)
Re: fixnum macros vs procedures John Cowan (15 May 2017 15:29 UTC)
Re: fixnum macros vs procedures Per Bothner (15 May 2017 16:28 UTC)
Re: fixnum macros vs procedures John Cowan (15 May 2017 16:40 UTC)
Re: fixnum macros vs procedures Shiro Kawai (15 May 2017 22:27 UTC)
Re: fixnum macros vs procedures Alex Shinn (17 May 2017 10:34 UTC)
Re: fixnum macros vs procedures John Cowan (17 May 2017 12:00 UTC)

fixnum macros vs procedures Per Bothner 15 May 2017 05:22 UTC

Since the point is fixnum operators is performance, would it make sense to
make it unspecified whether the various operators (such as fx+) are procedures
or macros?

For example for Kawa it might make sense define fx+ as

(define-syntax fx+
   (syntax-rules ()
      ((_ x y)
       (+ (as int x) (as int y)))))

and that would provide decent performance, using an inline iadd JVM instruction.

However:

(define (fx+ x::int y::int)::int
   (+ x y))

would require a little more work for equivalent performance.
That definition would avoid boxing, and the JVM could probably
inline the method, but it would be better for Kawa to generate
the iadd opcode directly, rather then depend on the JVM.

It would not be difficult in Kawa to define fx+ so it would inline
to a single iadd instruction - but it would be a bit more work.
Using a macro would avoid that extra work.

Why would anyone ever want to use fx+ *except* in a procedure call?
--
	--Per Bothner
xxxxxx@bothner.com   http://per.bothner.com/