sb-rotate-byte:rotate-byte broken on x86-64

Bug #882151 reported by Robert Brown
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Fix Released
High
Unassigned

Bug Description

The function sb-rotate-byte:rotate-byte produces incorrect results
on x86-64 hosts when inlined.

Reproduce by doing the following:

Extract the attached file, bug.lisp.

Start SBCL on a 64-bit Intel host.

Evaluate
  (require 'sb-rotate-byte)
  (load "bug.lisp")
  (doit)

You should see the following output:

2987261130318898290 43 --> 5005609889943596700
8130673577157431119 30 --> 4358988824820830761
14432021153170023510 20 --> 17745709223287481625

Edit bug.lisp. Uncomment the SBCL-specific code in the
function rotate-right-64 and comment out the generic code.
Reload bug.lisp and evaluat
e (doit) again. You should see:

2987261130318898290 43 --> 16943545977209445855
8130673577157431119 30 --> 10648730343012924706
14432021153170023510 20 --> 7810677674261382285

The last number is different. It is the result of rotating right
by 21 bits instead of by 20.

bob

==========

sbcl --version
SBCL 1.0.52.31-05bb9b2-dirty

uname -a
Linux paradicsom.nyc.corp.google.com 2.6.38.8-gg621 #2 SMP Wed Sep 14 13:43:05 PDT 2011 x86_64 GNU/Linux

*features*
(:ASDF2 :ASDF :ASDF-UNIX :SB-XREF-FOR-INTERNAL :ANSI-CL :COMMON-LISP :SBCL
 :SB-DOC :SB-TEST :SB-LDB :SB-PACKAGE-LOCKS :SB-UNICODE :SB-EVAL
 :SB-SOURCE-LOCATIONS :IEEE-FLOATING-POINT :X86-64 :UNIX :ELF :LINUX :SB-THREAD
 :LARGEFILE :GENCGC :STACK-GROWS-DOWNWARD-NOT-UPWARD :C-STACK-IS-CONTROL-STACK
 :LINKAGE-TABLE :COMPARE-AND-SWAP-VOPS :UNWIND-TO-FRAME-AND-CALL-VOP
 :RAW-INSTANCE-INIT-VOPS :STACK-ALLOCATABLE-CLOSURES :STACK-ALLOCATABLE-VECTORS
 :STACK-ALLOCATABLE-LISTS :STACK-ALLOCATABLE-FIXED-OBJECTS :ALIEN-CALLBACKS
 :CYCLE-COUNTER :COMPLEX-FLOAT-VOPS :FLOAT-EQL-VOPS :INLINE-CONSTANTS
 :MEMORY-BARRIER-VOPS :MULTIPLY-HIGH-VOPS :OS-PROVIDES-DLOPEN
 :OS-PROVIDES-DLADDR :OS-PROVIDES-PUTWC :OS-PROVIDES-SUSECONDS-T
 :OS-PROVIDES-GETPROTOBY-R :OS-PROVIDES-POLL)

Revision history for this message
Robert Brown (robert-brown) wrote :
Changed in sbcl:
assignee: nobody → Nikodemus Siivola (nikodemus)
importance: Undecided → High
status: New → In Progress
Changed in sbcl:
importance: High → Undecided
status: In Progress → Incomplete
status: Incomplete → In Progress
Revision history for this message
Nikodemus Siivola (nikodemus) wrote :

The bug occurs only if ROTATE-RIGHT-64 is inlined -- when the %64bit-rotate-byte/c version of the VOP is used.

Here's the fixed version -- commit coming tomorrowish.

(define-vop (%64bit-rotate-byte/c)
  (:policy :fast-safe)
  (:translate %unsigned-64-rotate-byte)
  (:note "inline 64-bit constant rotation")
  (:args (integer :scs (sb-vm::unsigned-reg) :target result))
  (:info count)
  (:arg-types (:constant (integer -63 63)) sb-vm::unsigned-num)
  (:results (result :scs (sb-vm::unsigned-reg)))
  (:result-types sb-vm::unsigned-num)
  (:generator 5
    (aver (not (= count 0)))
    (move result integer)
    (if (> count 0)
        (inst rol result count)
        (inst ror result (- count)))))

Changed in sbcl:
importance: Undecided → High
Revision history for this message
Nikodemus Siivola (nikodemus) wrote :

commit 6a71280af32d6bb02ed07d1a576df2cd9c5dfb79
Author: Nikodemus Siivola <email address hidden>
Date: Sat Oct 29 21:13:07 2011 +0300

    fix ROTATE-BYTE on 64-bit words using constant negative rotation

      Fixes lp#882151.

Changed in sbcl:
status: In Progress → Fix Committed
Changed in sbcl:
assignee: Nikodemus Siivola (nikodemus) → nobody
Changed in sbcl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.