VOP for product of unsigned-reg and constant isn't used
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
New
|
Undecided
|
Unassigned |
Bug Description
Here my focus is on SBCL 2.1.9 for x86-64.
The following function multiplies unsigned-reg and constant, and returns the 63rd bit.
(defun test (x)
(declare (optimize (speed 3) (safety 0))
(ldb (byte 1 63) (ldb (byte 64 0) (* x (expt 10 15)))))
I think sb-vm::
;; Size: 35 bytes. Origin: #x52DE0272 ; TEST
;; 72: 48BB0080C6A47E8
;; 7C: 488BC2 MOV RAX, RDX
;; 7F: 48F7E3 MUL RAX, RBX
;; 82: 488BC8 MOV RCX, RAX
;; 85: 48C1E93F SHR RCX, 63
;; 89: 48D1E1 SHL RCX, 1
;; 8C: 488BD1 MOV RDX, RCX
;; 8F: 488BE5 MOV RSP, RBP
;; 92: F8 CLC
;; 93: 5D POP RBP
;; 94: C3 RET
https:/
As shown in this line, the cost for the "constant" VOP is equal to the "non-constant" one. So I reduced the former cost by 1 and the disassembly became as intended:
;; Size: 29 bytes. Origin: #x53639042 ; TEST
;; 42: 488BC2 MOV RAX, RDX
;; 45: 48F725CCFFFFFF MUL RAX, [RIP-52] ; [#x53639018] = #x38D7EA4C68000
;; 4C: 488BC8 MOV RCX, RAX
;; 4F: 48C1E93F SHR RCX, 63
;; 53: 48D1E1 SHL RCX, 1
;; 56: 488BD1 MOV RDX, RCX
;; 59: 488BE5 MOV RSP, RBP
;; 5C: F8 CLC
;; 5D: 5D POP RBP
;; 5E: C3 RET
Currently other "constant" VOPs for four arithemtic operations have less cost by 1 than their "non-constant" equivalents. My question is, is there any reason why this VOP is special?
https:/
These two VOPs, fast-*/
I'm not sure loading constants from memory is a good idea, though.