Improve CONSTANTLY on constant argument

Bug #1852585 reported by Paul F. Dietz
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
SBCL
Fix Released
Undecided
Unassigned

Bug Description

(moved from a comment in 1852475)

Add a deftransform (or compiler macro?) for CONSTANTLY to optimize the case of a constant argument.

(declaim (optimize (speed 3) (safety 0) (debug 0)))

* (defun f () (lambda (&rest args) (declare (ignore args)) t))
F
* (defun g () (constantly t))
G
* (disassemble 'f)
; disassembly for F
; Size: 13 bytes. Origin: #x52D489A6 ; F
; A6: 488B15D3FFFFFF MOV RDX, [RIP-45] ; #<FUNCTION (LAMBDA
                                                              ; ( ..))>
; AD: 488BE5 MOV RSP, RBP
; B0: F8 CLC
; B1: 5D POP RBP
; B2: C3 RET
NIL
* (disassemble (f))
; disassembly for (LAMBDA (&REST ARGS) :IN F)
; Size: 11 bytes. Origin: #x52D489D6 ; (LAMBDA
                                                                    (
                                                                     &REST
                                                                     ARGS)
                                                                  :IN
                                                                  F)
; D6: BA4F001050 MOV EDX, #x5010004F ; T
; DB: 488BE5 MOV RSP, RBP
; DE: F8 CLC
; DF: 5D POP RBP
; E0: C3 RET
NIL
* (disassemble 'g)
; disassembly for G
; Size: 20 bytes. Origin: #x52D48A56 ; G
; 56: BA4F001050 MOV EDX, #x5010004F ; T
; 5B: B902000000 MOV ECX, 2
; 60: FF7508 PUSH QWORD PTR [RBP+8]
; 63: B8C21A4450 MOV EAX, #x50441AC2 ; #<FDEFN CONSTANTLY>
; 68: FFE0 JMP RAX
NIL
* (disassemble (g))
; disassembly for (LAMBDA (&REST SB-IMPL::ARGUMENTS) :IN CONSTANTLY)
; Size: 17 bytes. Origin: #x5216BB7A ; (LAMBDA
                                                                    (
                                                                     &REST
                                                                     SB-IMPL::ARGUMENTS)
                                                                  :IN
                                                                  CONSTANTLY)
; 7A: 488BE5 MOV RSP, RBP
; 7D: F8 CLC
; 7E: 5D POP RBP
; 7F: C3 RET
; 80: CC10 INT3 16 ; Invalid argument count trap
; 82: 6A20 PUSH 32
; 84: E89747F9FF CALL #x52100320 ; ALLOC-TRAMP-R11
; 89: EB9E JMP #x5216BB29
NIL
*

Most of the uses of CONSTANTLY in the sbcl source are on a constant argument.

description: updated
description: updated
Stas Boukarev (stassats)
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.

Duplicates of this bug

Other bug subscribers

Remote bug watches

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