sb-rotate-byte:rotate-byte broken on x86-64
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
Fix Released
|
High
|
Unassigned |
Bug Description
The function sb-rotate-
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
144320211531700
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 --> 169435459772094
8130673577157431119 30 --> 106487303430129
144320211531700
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.
uname -a
Linux paradicsom.
*features*
(:ASDF2 :ASDF :ASDF-UNIX :SB-XREF-
:SB-DOC :SB-TEST :SB-LDB :SB-PACKAGE-LOCKS :SB-UNICODE :SB-EVAL
:SB-SOURCE-
:LARGEFILE :GENCGC :STACK-
:LINKAGE-TABLE :COMPARE-
:RAW-INSTANCE-
:STACK-
:CYCLE-COUNTER :COMPLEX-FLOAT-VOPS :FLOAT-EQL-VOPS :INLINE-CONSTANTS
:MEMORY-
:OS-PROVIDES-
:OS-PROVIDES-
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 |
Changed in sbcl: | |
assignee: | Nikodemus Siivola (nikodemus) → nobody |
Changed in sbcl: | |
status: | Fix Committed → Fix Released |
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) 64-rotate- byte) :unsigned- reg) :target result)) unsigned- num) :unsigned- reg))) unsigned- num)
(:policy :fast-safe)
(:translate %unsigned-
(:note "inline 64-bit constant rotation")
(:args (integer :scs (sb-vm:
(:info count)
(:arg-types (:constant (integer -63 63)) sb-vm::
(:results (result :scs (sb-vm:
(:result-types sb-vm::
(:generator 5
(aver (not (= count 0)))
(move result integer)
(if (> count 0)
(inst rol result count)
(inst ror result (- count)))))