Implement AND of fixnum = w. logxor/logior

Bug #1847348 reported by Paul F. Dietz on 2019-10-08
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Undecided
Unassigned

Bug Description

Wishlist: implement a short sequence of fixnum = comparisons with logxor and logior:

(and (= a b) (= c d)) ==> (eql (logior (logxor a b) (logxor c d)) 0)

On x86 the code is both shorter and faster (due to no conditional branches).

Example:

(defun f6 (x y z)
  (declare (type (integer 0 1000) x y z))
  (= x y z))

(defun f7 (x y z)
  (declare (type (integer 0 1000) x y z))
  (eql (logior (logxor x y) (logxor y z)) 0))

* (disassemble 'f6)
; disassembly for F6
; Size: 36 bytes. Origin: #x52D7B486
; 86: 4839D7 CMP RDI, RDX ; no-arg-parsing entry point
; 89: 740B JEQ L1
; 8B: BA17001050 MOV EDX, #x50100017 ; NIL
; 90: L0: 488BE5 MOV RSP, RBP
; 93: F8 CLC
; 94: 5D POP RBP
; 95: C3 RET
; 96: L1: 4839FE CMP RSI, RDI
; 99: BA17001050 MOV EDX, #x50100017 ; NIL
; 9E: 41BB4F001050 MOV R11D, #x5010004F ; T
; A4: 490F44D3 CMOVEQ RDX, R11
; A8: EBE6 JMP L0
NIL
* (disassemble 'f7)
; disassembly for F7
; Size: 33 bytes. Origin: #x52D7B516
; 16: 4831FA XOR RDX, RDI ; no-arg-parsing entry point
; 19: 4831F7 XOR RDI, RSI
; 1C: 4809FA OR RDX, RDI
; 1F: 4885D2 TEST RDX, RDX
; 22: BA17001050 MOV EDX, #x50100017 ; NIL
; 27: 41BB4F001050 MOV R11D, #x5010004F ; T
; 2D: 490F44D3 CMOVEQ RDX, R11
; 31: 488BE5 MOV RSP, RBP
; 34: F8 CLC
; 35: 5D POP RBP
; 36: C3 RET

Paul F. Dietz (paul-f-dietz) wrote :

The place this would really shine is string=.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers