Bad compilation of rotate-byte with constant rotation count

Bug #1586614 reported by Guillaume LE VAILLANT
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Fix Released
Medium
Unassigned

Bug Description

Hello,

I'm using the sb-rotate-byte:rotate-byte function with SBCL 1.3.5 on Linux x86-64, and sometimes for constant rotations it is not compiled correctly.

Rotating a 32-bit unsigned integer to the left works:

(defun rol32-3 (a)
  (declare (type (unsigned-byte 32) a))
  (sb-rotate-byte:rotate-byte 3 (byte 32 0) a))

(disassemble 'rol32-3)

; disassembly for ROL32-3
; Size: 29 bytes. Origin: #x1004D0946A
; 6A: 498B4C2460 MOV RCX, [R12+96] ; thread.binding-stack-pointer
                                                              ; no-arg-parsing entry point
; 6F: 48894DF8 MOV [RBP-8], RCX
; 73: 488BD3 MOV RDX, RBX
; 76: 48D1FA SAR RDX, 1
; 79: C1C203 ROL EDX, 3
; 7C: 48D1E2 SHL RDX, 1
; 7F: 488BE5 MOV RSP, RBP
; 82: F8 CLC
; 83: 5D POP RBP
; 84: C3 RET
; 85: CC10 BREAK 16 ; Invalid argument count trap

But rotating a 32-bit unsigned integer to the right doesn't give the right result:

(defun ror32-3 (a)
  (declare (type (unsigned-byte 32) a))
  (sb-rotate-byte:rotate-byte -3 (byte 32 0) a))

(disassemble 'ror32-3)

; disassembly for ROR32-3
; Size: 29 bytes. Origin: #x1004D2E30A
; 0A: 498B4C2460 MOV RCX, [R12+96] ; thread.binding-stack-pointer
                                                              ; no-arg-parsing entry point
; 0F: 48894DF8 MOV [RBP-8], RCX
; 13: 488BD3 MOV RDX, RBX
; 16: 48D1FA SAR RDX, 1
; 19: C1CAFD ROR EDX, 253
; 1C: 48D1E2 SHL RDX, 1
; 1F: 488BE5 MOV RSP, RBP
; 22: F8 CLC
; 23: 5D POP RBP
; 24: C3 RET
; 25: CC10 BREAK 16 ; Invalid argument count trap

Here we have a "ROR EDX, 253" instead of "ROR EDX, 3".

Stas Boukarev (stassats)
Changed in sbcl:
status: New → Triaged
importance: Undecided → Medium
Revision history for this message
Stas Boukarev (stassats) wrote :

In d457a3c61e7612fdbfb9afb76fbd267fbe4444ad.

Changed in sbcl:
status: Triaged → Fix Committed
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

Remote bug watches

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