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

Bug #882151 reported by Robert Brown on 2011-10-26
This bug affects 1 person
Affects Status Importance Assigned to Milestone

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.

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

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.



sbcl --version

uname -a
Linux #2 SMP Wed Sep 14 13:43:05 PDT 2011 x86_64 GNU/Linux


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
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
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  Edit
Everyone can see this information.

Other bug subscribers

Bug attachments