Bug in code transform for EXPT

Bug #1958061 reported by Vasily Postnicov
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Fix Released
Undecided
Unassigned

Bug Description

Hi!

In src/compiler/float-tran.lisp you have the following:

(deftransform expt ((x y) (single-float integer) double-float)
  `(coerce (%pow (coerce x 'double-float) (coerce y 'double-float))
    'single-float))

the correct code should be

(deftransform expt ((x y) (single-float integer) single-float)
  `(coerce (%pow (coerce x 'double-float) (coerce y 'double-float))
    'single-float))

Check this function:

(defun foo (x)
  (declare (optimize (speed 3))
           (type single-float x))
  (expt x 44))

This is the produced assembly before the fix:

CL-USER> (disassemble 'lol)
; disassembly for LOL
; Size: 22 bytes. Origin: #x2263AF94 ; LOL
; 94: BF58000000 MOV EDI, 88
; 99: B904000000 MOV ECX, 4
; 9E: FF7508 PUSH QWORD PTR [RBP+8]
; A1: B8222E3720 MOV EAX, #x20372E22 ; #<FDEFN EXPT>
; A6: FFE0 JMP RAX
; A8: CC10 INT3 16 ; Invalid argument count trap
NIL

and after the fix:

CL-USER> (disassemble 'foo)
; disassembly for FOO
; Size: 61 bytes. Origin: #x2263BC7F ; FOO
; 7F: F30F5AC0 CVTSS2SD XMM0, XMM0
; 83: 488BDC MOV RBX, RSP
; 86: 4883E4F0 AND RSP, -16
; 8A: F20F100DB6FFFFFF MOVSD XMM1, [RIP-74] ; [#x2263BC48]
; 92: B802000000 MOV EAX, 2
; 97: FF1425F8040020 CALL QWORD PTR [#x200004F8] ; pow
; 9E: 488BE3 MOV RSP, RBX
; A1: F20F5AC0 CVTSD2SS XMM0, XMM0
; A5: 0FC6C0FC SHUFPS XMM0, XMM0, #4r3330
; A9: 660F7EC2 MOVD EDX, XMM0
; AD: 48C1E220 SHL RDX, 32
; B1: 80CA19 OR DL, 25
; B4: 488BE5 MOV RSP, RBP
; B7: F8 CLC
; B8: 5D POP RBP
; B9: C3 RET
; BA: CC10 INT3 16 ; Invalid argument count trap
NIL

Also I would like to ask a question: is there any particular reason not to use functions like powf, sinf and so on?

Revision history for this message
Stas Boukarev (stassats) wrote :

>Also I would like to ask a question: is there any particular reason not to use functions like powf, sinf and so on?

They used to not exist, then they used to be bad.

Changed in sbcl:
status: New → 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