[cmucl-ticket] #21: Modular arith bug 3

cmucl cmucl-devel at common-lisp.net
Thu Aug 21 20:48:45 UTC 2008


#21: Modular arith bug 3
--------------------+-------------------------------------------------------
 Reporter:  rtoy    |       Owner:  somebody
     Type:  defect  |      Status:  new     
 Priority:  major   |   Milestone:          
Component:  Core    |     Version:  2008-08 
 Keywords:          |  
--------------------+-------------------------------------------------------
 The following code doesn't use modular arithmetic for ash:

 {{{
 (defun bug (v)
   (declare (type (unsigned-byte 32) v)
            (optimize (speed 3) (safety 0)))
   (logand #xffffffff (logxor v (ash v (- -16)))))
 }}}

 You get compiler warnings about {{{ASH}}}.
 But the equivalent code is ok:

 {{{
 (defun bug-a (v)
   (declare (type (unsigned-byte 32) v)
            (optimize (speed 3) (safety 0)))
   (ldb (byte 32 0) (logxor v (ash v (- -16)))))
 }}}

 Also, if in {{{bug}}}, you change {{{(- -16)}}} to the obvious {{{16}}},
 the compiler notes are gone, and the generated code is as expected.

 What appears to be happening is that when {{{logand-defopt-helper}}} is
 run, the compiler doesn't know the type of the shift for {{{ASH}}}.
 Hence, it can't do modular arithmetic stuff.  However, when the code is
 finally generated, you can see that the shift is now a known constant
 value of 16.  I don't know why.

-- 
Ticket URL: <http://trac.common-lisp.net/cmucl/ticket/21>
cmucl <http://common-lisp.net/project/cmucl>
cmucl


More information about the cmucl-ticket mailing list