[gambit-list] Specialize equal?, eqv?, and = to eq? when one of the arguments is a fixnum constant.

Marc Feeley feeley at iro.umontreal.ca
Mon Aug 22 18:29:04 EDT 2005


On 22-Aug-05, at 5:22 PM, Bradley Lucier wrote:

> Marc:
>
> You should specialize equal?, eqv?, and = to eq? when one of the  
> arguments is a fixnum constant.
>
> Brad
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> http://mailman.iro.umontreal.ca/mailman/listinfo/gambit-list
>

For quite some time the specialisation from eqv? to eq? on eq?- 
testable constants (such as symbols, 32 bit fixnums, characters, #t,  
#f, etc) is performed by the compiler.  I have extended this to equal?.

For example, the following code

(declare (standard-bindings))
(define (f1 x) (if (equal? x 1000000) 'foo 'bar))
(define (f2 x) (if (equal? x 1000000000000000000000) 'foo 'bar))

now expands to

(define f1 (lambda (x) (if ('#<procedure #2 ##eq?> x 1000000) 'foo  
'bar)))
(define f2 (lambda (x) (if (equal? x 1000000000000000000000) 'foo  
'bar)))

So in compiled code, (equal? x '()) is as fast as (null? x)

Unfortunately the specialization of = to eq? on 32 bit fixnums does  
not work, because

        (= x 0)  !=  (eq? x 0)

when x is 0.0 .

Marc




More information about the Gambit-list mailing list