Re: post declarations in lisp



On Fri, 30 Mar 2007 13:07:23 -0700, amolaggarwal@xxxxxxxxx wrote:

Kent M pitman mentioned in his slashdot article.
The initial focus in Lisp is on getting programs working. You can add
type declarations when you're done if you want to, in order to enable
additional compiler optimizations.
I want to know how it is done?

This is globally set here:

(proclaim '(optimize
(compilation-speed 0)
(debug 3)
(safety 3)
(space 0)
(speed 0)))


...then I do:

cl-user> (defun test (a b)
(+ a b))
test
cl-user> (disassemble 'test)
; 0B2AC989: 64 byte #X64 ; no-arg-parsing entry point
; 98A: 8B050C000000 mov eax, [#xC]
; 990: 8945CC mov [ebp-52], eax
; 993: 8B05D8000005 mov eax, [#x50000D8]
; 999: 64 byte #X64
; 99A: 8B00 mov eax, [eax]
; 99C: 8B0D18040005 mov ecx, [#x5000418]
; 9A2: 64 byte #X64
; 9A3: 8B09 mov ecx, [ecx]
; 9A5: 8945D0 mov [ebp-48], eax
; 9A8: 894DD4 mov [ebp-44], ecx
; 9AB: 8965C8 mov [ebp-56], esp
; 9AE: 8B1550C92A0B mov edx, [#xB2AC950] ; 'sb-c:debug-catch-tag
; 9B4: 8D4DD8 lea ecx, [ebp-40]
; 9B7: 8B05F8000005 mov eax, [#x50000F8]
; 9BD: 64 byte #X64
; 9BE: 8B00 mov eax, [eax]
; 9C0: 8901 mov [ecx], eax
; 9C2: 896904 mov [ecx+4], ebp
; 9C5: C7410821CA2A0B mov dword ptr [ecx+8], 187353633
; 9CC: 89510C mov [ecx+12], edx
; 9CF: 8B05D8000005 mov eax, [#x50000D8]
; 9D5: 64 byte #X64
; 9D6: 8B00 mov eax, [eax]
; 9D8: 894110 mov [ecx+16], eax
; 9DB: 8B05D8000005 mov eax, [#x50000D8]
; 9E1: 64 byte #X64
; 9E2: 8908 mov [eax], ecx
; 9E4: 64 byte #X64
; 9E5: 813D500000000B000005 cmp dword ptr [#x50], 83886091
; 9EF: 7402 jeq L0
; 9F1: CC0F break 15
; 9F3: L0: 8B55F4 mov edx, [ebp-12]
; 9F6: 8B7DF0 mov edi, [ebp-16]
; 9F9: E84A37D5F5 call #x1000148 ; generic-+
; 9FE: 7302 jnb L1
; A00: 8BE3 mov esp, ebx
; A02: L1: 8B0DD8000005 mov ecx, [#x50000D8]
; A08: 64 byte #X64
; A09: 8B09 mov ecx, [ecx]
; A0B: 8B4910 mov ecx, [ecx+16]
; A0E: 8B05D8000005 mov eax, [#x50000D8]
; A14: 64 byte #X64

;;; [3] (block test (+ a b))

; A15: 8908 mov [eax], ecx
; A17: 8D65F8 lea esp, [ebp-8]
; A1A: F8 clc
; A1B: 8B6DFC mov ebp, [ebp-4]
; A1E: C20400 ret 4
; A21: BA0B000005 mov edx, 83886091
; A26: E303 jecxz L2
; A28: 8B53FC mov edx, [ebx-4]
; A2B: L2: 8B65C8 mov esp, [ebp-56]
; A2E: 8BF2 mov esi, edx
; A30: 8B4DD0 mov ecx, [ebp-48]

; A33: 8B55D4 mov edx, [ebp-44]
; A36: 8B05D8000005 mov eax, [#x50000D8]
; A3C: 64 byte #X64
; A3D: 8908 mov [eax], ecx
; A3F: 8B0518040005 mov eax, [#x5000418]
; A45: 64 byte #X64
; A46: 8910 mov [eax], edx

;;; [1] (sb-int:named-lambda test (a b) (block test #))

; A48: 8B7DCC mov edi, [ebp-52]
; A4B: 64 byte #X64
; A4C: 8B150C000000 mov edx, [#xC]

; A52: 39D7 cmp edi, edx
; A54: 742C jeq L5
; A56: L3: 8B42FC mov eax, [edx-4]
; A59: 09C0 or eax, eax
; A5B: 7410 jeq L4
; A5D: 8B4AF8 mov ecx, [edx-8]
; A60: 8B5811 mov ebx, [eax+17]
; A63: 64 byte #X64
; A64: 890B mov [ebx], ecx
; A66: C742FC00000000 mov dword ptr [edx-4], 0
; A6D: L4: C742F800000000 mov dword ptr [edx-8], 0
; A74: 83EA08 sub edx, 8
; A77: 39D7 cmp edi, edx
; A79: 75DB jne L3
; A7B: 64 byte #X64
; A7C: 89150C000000 mov [#xC], edx
; A82: L5: 8BC6 mov eax, esi
; A84: 2407 and al, 7
; A86: 3C05 cmp al, 5
; A88: 7513 jne L6
; A8A: 8BC6 mov eax, esi
; A8C: 31C9 xor ecx, ecx
; A8E: FF75F8 push dword ptr [ebp-8]
; A91: FF60FF jmp dword ptr [eax-1]
; A94: 90 nop
; A95: 90 nop
; A96: 90 nop
; A97: 90 nop
; A98: CC0A break 10 ; error trap
; A9A: 02 byte #X02
; A9B: 18 byte #X18 ; INVALID-ARG-COUNT-ERROR
; A9C: 4D byte #X4D ; ECX
; A9D: L6: CC0A break 10 ; error trap
; A9F: 04 byte #X04
; AA0: 01 byte #X01 ; OBJECT-NOT-FUN-ERROR
; AA1: FE8E01 byte #XFE, #X8E, #X01 ; ESI
;
nil


Then I add some declarations:

cl-user> (defun test (a b)
(declare (fixnum a b)
(optimize (speed 3) (debug 0) (safety 0)))
(the fixnum (+ a b)))
style-warning: redefining test in DEFUN
test
cl-user> (disassemble 'test)
; 0B5B0452: 01FA add edx, edi ; no-arg-parsing entry point
; 54: 8D65F8 lea esp, [ebp-8]
; 57: F8 clc
; 58: 8B6DFC mov ebp, [ebp-4]
; 5B: C20400 ret 4
; 5E: 90 nop
; 5F: 90 nop
;
nil

--
Lars Rune Nøstdal
http://nostdal.org/
.



Relevant Pages

  • Re: post declarations in lisp
    ... type declarations when you're done if you want to, ... cl-user> (defun test (a b) ... cl-user> ... (declare (fixnum a b) ...
    (comp.lang.lisp)
  • Re: post declarations in lisp
    ... type declarations when you're done if you want to, ... cl-user> (defun test (a b) ... cl-user> ... (declare (fixnum a b) ...
    (comp.lang.lisp)
  • Re: lang effort: type conversions
    ... the variation does lead to the occurance that function declarations are ... rat, rational, fixnum, or on heap. ... have this explicit and under control of the programmer for maths reasons ... note, however, for other reasons closures may not be allowed as methods ...
    (comp.lang.misc)
  • Re: Optimizing n-gram generation
    ... I know nothing about declarations ... ... help if you wrap the GETHASH call in a (THE FIXNUM ...) form. ... Declaring types for data and maxn speeded it up by ... hash key might be better ...
    (comp.lang.lisp)
  • Re: Optimizing Numerical Code
    ... Try this one with type declarations for all variables: ... (loop for iterations fixnum below *max-iterations* ... for period fixnum from 1 ...
    (comp.lang.lisp)