4 ms·
Is Common Lisp the only language with this built-in? CL-USER> (defun foo (a b) (declare (optimize (speed 3)) (type f
by jlarocco 2y ago
Is Common Lisp the only language with this built-in?
CL-USER> (defun foo (a b)
(declare (optimize (speed 3))
(type fixnum a b))
(+ a b))
FOO
CL-USER> (disassemble #'foo)
; disassembly for FOO
; Size: 23 bytes. Origin: #x1002230744 ; FOO
; 44: 4801FA ADD RDX, RDI
; 47: 48D1E2 SHL RDX, 1
; 4A: 710A JNO L0
; 4C: 48D1DA RCR RDX, 1
; 4F: FF1425F00C1050 CALL [#x50100CF0] ; SB-VM::ALLOC-SIGNED-BIGNUM-IN-RDX
; 56: L0: C9 LEAVE
; 57: F8 CLC
; 58: C3 RET
; 59: CC10 INT3 16 ; Invalid argument count trap
NIL
CL-USER>
The Emacs Lisp mode has support for it, too - I have Alt-F8 open the disassembly of the current function in a new window next to the current window.
- nick__m 2y agoJulia has it it's called code_native http://www.jlhub.com/julia/manual/en/function/code_native http://www.jlhub.com/julia/manual/en/function/code_native
- deleted 2y ago[deleted]
- guenthert 2y agoyou 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.