fix ROTATE-BYTE on 64-bit words using constant negative rotation
authorNikodemus Siivola <nikodemus@random-state.net>
Sat, 29 Oct 2011 18:13:07 +0000 (21:13 +0300)
committerNikodemus Siivola <nikodemus@random-state.net>
Sat, 29 Oct 2011 18:34:29 +0000 (21:34 +0300)
  Fixes lp#882151.

NEWS
contrib/sb-rotate-byte/rotate-byte-tests.lisp
contrib/sb-rotate-byte/x86-64-vm.lisp

diff --git a/NEWS b/NEWS
index e1b4f28..64fdd90 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,8 @@ changes relative to sbcl-1.0.52:
   * bug fix: floating-point traps now work on darwin/x86 and /x86-64.
   * bug fix: repair crash in x86oid darwin signal handling emulation
     when built with certain compilers.
+  * bug fix: SB-ROTATE-BYTE misrotated to the right when using constant
+    rotation arguments on x86-64. (lp#882151)
 
 changes in sbcl-1.0.52 relative to sbcl-1.0.51:
   * enhancement: ASDF has been updated to version 2.017.
index 11f9b63..6e6b7f6 100644 (file)
   (declare (type (unsigned-byte 64) integer))
   (rotate-byte 6 (byte 64 0) integer))
 
-(assert (= (ub64/c 5) 320))
-(assert (= (ub64/c 1) 64))
-(assert (= (ub64/c (ash 1 57)) (ash 1 63)))
-(assert (= (ub64/c (ash 1 58)) 1))
+(defun ub64/-c (integer)
+  (declare (type (unsigned-byte 64) integer))
+  (rotate-byte -6 (byte 64 0) integer))
+
+(assert (= (ub64/-c 320) 5))
+(assert (= (ub64/-c 64) 1))
+(assert (= (ub64/-c (ash 1 63)) (ash 1 57)))
+(assert (= (ub64/-c 1) (ash 1 58)))
 
 (defun ub64 (count integer)
   (declare (type (unsigned-byte 64) integer)
index d45b596..a311933 100644 (file)
@@ -59,7 +59,7 @@
     (move result integer)
     (if (> count 0)
         (inst rol result count)
-        (inst ror result count))))
+        (inst ror result (- count)))))
 
 (define-vop (%64bit-rotate-byte)
   (:policy :fast-safe)