[cmucl-ticket] #18: Modular arith bug 1

cmucl cmucl-devel at common-lisp.net
Tue Aug 12 16:10:38 UTC 2008


#18: Modular arith bug 1
--------------------+-------------------------------------------------------
 Reporter:  rtoy    |       Owner:  somebody
     Type:  defect  |      Status:  new     
 Priority:  minor   |   Milestone:          
Component:  Core    |     Version:  19d     
 Keywords:          |  
--------------------+-------------------------------------------------------
 Not really a bug, but a deficiency.

 {{{
 (defun ref (a n)
   (declare (type (simple-array single-float (*)) a)
            (type (integer 0 15) n)
            (optimize (speed 3) (safety 0)))
   (aref a (logand #xf (+ n 15))))
 }}}

 Relevant disassembly on sparc:

 {{{
       68:       SRA        %A1, 2, %NL0                ; %A1 = N
                                                        ; No-arg-parsing
 entry point
                                                        ; [:NON-LOCAL-
 ENTRY]
       6C:       ADD        15, %NL0
       70:       AND        15, %NL0
       74:       SLL        %NL0, 2, %NL1
       78:       ADD        %NL1, 1, %NL0
       7C:       LDF        [%A0+%NL0], %F0             ; %A0 = A
 }}}

 So {{{N}}} is converted from a fixnum to an integer, the appropriate
 operations are done, and then converted back to a fixnum.  All of this
 could have been done without the conversion like so:

 {{{
       40:       ADD        60, %A1                     ; %A1 = N
                                                        ; No-arg-parsing
 entry point
                                                        ; [:NON-LOCAL-
 ENTRY]
       44:       AND        60, %A1
       48:       ADD        %A1, 1, %NL0
       4C:       LDF        [%A0+%NL0], %F0             ; %A0 = A
 }}}

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


More information about the cmucl-ticket mailing list