2 ms·
you were probably looking for (defun foo (a b) (declare (optimize (speed 3)) (type fixnum a b)) (the fixnum (+ a b)))
by guenthert 2y ago
you were probably looking for
(defun foo (a b)
(declare (optimize (speed 3))
(type fixnum a b))
(the fixnum (+ a b)))
- jlarocco 2y agoHeh, I didn't really think about it, but to finish out the example: CL-USER> (defun foo (a b) (declare (optimize (speed 3)) (type fixnum a b)) (the fixnum (+ a b))) WARNING: redefining COMMON-LISP-USER::FOO in DEFUN FOO CL-USER> (disassemble #'foo) ; disassembly for FOO ; Size: 22 bytes. Origin: #x101127E9B4 ; FOO ; B4: 4801FA ADD RDX, RDI ; B7: 488BC2 MOV RAX, RDX ; BA: 48D1E0 SHL RAX, 1 ; BD: 7006 JO L0 ; BF: 48D1E2 SHL RDX, 1 ; C2: C9 LEAVE ; C3: F8 CLC ; C4: C3 RET ; C5: L0: CC59 INT3 89 ; OBJECT-NOT-FIXNUM-ERROR ; C7: 0A BYTE #X0A ; RDX(s) ; C8: CC10 INT3 16 ; Invalid argument count trap NIL CL-USER> And to optimize away everything: CL-USER> (defun foo (a b) (declare (optimize (speed 3) (safety 0) (debug 0) (space 3)) (type fixnum a b)) (the fixnum (+ a b))) WARNING: redefining COMMON-LISP-USER::FOO in DEFUN FOO CL-USER> (disassemble #'foo) ; disassembly for FOO ; Size: 6 bytes. Origin: #x101127F026 ; FOO ; 6: 4801FA ADD RDX, RDI ; 9: C9 LEAVE ; A: F8 CLC ; B: C3 RET NIL CL-USER>
- guenthert 2y agoIndeed. Keep in mind though that the disassembly begins at an offset and doesn't contain the function header, i.e. FOO is quite a bit larger than 6 bytes.