[Openmcl-devel] bug in optimizer on x86-64 (bignum code)

Gary Byers gb at clozure.com
Mon Jun 26 22:56:46 UTC 2006


Thanks; this is now fixed in CVS.

For the curious:

An even simpler (and more embarrassing ...) test case is:

(defun add2 (x y)
   "Just add two numbers together.  What could go wrong ?"
   (+ x y))

when called with two fixnum arguments whose sum is a bignum and when
compiled with SPEED more important than SPACE (the inlined overflow-
handling code was changing some bits in the result; with less
aggressive optimization settings, the overflow case was handled
correctly out-of-line.)

E.g.:

Welcome to OpenMCL Version 1.1-pre-060623 (Beta: LinuxX8664)!
? (defun add2 (x y)
     "Just add two numbers together.  What could go wrong ?"
     (+ x y))
ADD2
? (format t "~x" (add2 most-positive-fixnum 1))
1000000000000000  ; Looks good
NIL
? (declaim (optimize (speed 3) (space 1)))
NIL
? (defun add2 (x y)
     "Just add two numbers together.  What could go wrong ?"
     (+ x y))
ADD2
? (format t "~x" (add2 most-positive-fixnum 1))
FFF000000000000   ; Hmm.  Not so good ...
NIL
?

On Mon, 26 Jun 2006, Eric Marsden wrote:

> Hi,
>
> The following code (extracted from cl-bench, originally by Bruno
> Haible) illustrates a bug in the compiler on x86-64 (current CVS). The
> assertion is not triggered unless the optimization settings are
> enabled.
>
>
>
> #+bug
> (declaim (optimize (speed 3) (space 1) (safety 0) (debug 0) (compilation-speed 0)))
>
> (defvar *x1*)
> (defvar *x2*)
> (defvar *x3*)
> (defvar *y*)
> (defvar *z*)
>
> (defun pari-benchmark (N repeat)
>  (dotimes (count 3)
>    (dotimes (_ repeat)
>      (let ((u 1) (v 1) (p 1) (q 1))
>        (do ((k 1 (1+ k)))
>            ((> k N) (setq *y* p *z* q))
>          (let ((w (+ u v)))
>            (shiftf u v w)
>            (setq p (* p w))
>            (setq q (lcm q w)))))))
>  (integer-length (+ *y* *z*)))
>
> (defun run-pari-100-10 ()
>  (assert (eql 3529 (pari-benchmark 100 10))))
>
> -- 
> Eric Marsden
>
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
>
>



More information about the Openmcl-devel mailing list