[Openmcl-devel] Wow, this is so not what I expected

Ron Garret ron at flownet.com
Wed Apr 12 23:11:27 PDT 2017


That the LABELS version would be so much shorter than the non-labels version.

But now that I look at it I see why: the LABELS function was compiled separately and does not appear in the disassembly of FOO2.  So never mind.

On Apr 12, 2017, at 7:19 PM, Shannon Spires <svs at bearlanding.com> wrote:

> What's unexpected about it?
> 
> On Apr 12, 2017, at 7:26 PM, Ron Garret wrote:
> 
>> Welcome to Clozure Common Lisp Version 1.10-r16479M  (DarwinX8664)!
>> 
>> ? (defun foo1 (n)
>> (if (<= n 0) 0 (foo1 (1- n))))
>> FOO1
>> 
>> ? (defun foo2 (n)
>> (labels ((foo (n) (if (<= n 0) 0 (foo (1- n)))))
>>   (foo n)))
>> FOO2
>> 
>> ? (disassemble 'foo1)
>> ;;; (defun foo1 (n) (if (<= n 0) 0 (foo1 (1- n))))
>> L0
>>   (leaq (@ (:^ L0) (% rip)) (% fn))       ;     [0]
>>   (cmpl ($ 8) (% nargs))                  ;     [7]
>>   (jne L141)                              ;    [10]
>>   (pushq (% rbp))                         ;    [16]
>>   (movq (% rsp) (% rbp))                  ;    [17]
>>   (pushq (% save0))                       ;    [20]
>>   (movq (% arg_z) (% save0))              ;    [22]
>> 
>> ;;; (<= n 0)
>> L25
>>   (movq (% save0) (% arg_y))              ;    [25]
>>   (testb ($ 7) (% arg_y.b))               ;    [28]
>>   (jne L41)                               ;    [32]
>>   (testq (% arg_y) (% arg_y))             ;    [34]
>>   (jle L66)                               ;    [37]
>>   (jmp L72)                               ;    [39]
>> L41
>>   (xorl (% arg_z.l) (% arg_z.l))          ;    [41]
>>   (nop)                                   ;    [43]
>>   (callq (@ .SPBUILTIN-LE))               ;    [46]
>>   (leaq (@ (:^ L0) (% rip)) (% fn))       ;    [53]
>>   (cmpb ($ 11) (% arg_z.b))               ;    [60]
>>   (je L72)                                ;    [64]
>> 
>> ;;; (if (<= n 0) 0 (foo1 (1- n)))
>> L66
>>   (xorl (% arg_z.l) (% arg_z.l))          ;    [66]
>>   (popq (% save0))                        ;    [68]
>>   (leaveq)                                ;    [70]
>>   (retq)                                  ;    [71]
>> 
>> ;;; (1- n)
>> L72
>>   (movq (% save0) (% arg_z))              ;    [72]
>>   (testb ($ 7) (% arg_z.b))               ;    [75]
>>   (jne L110)                              ;    [79]
>>   (addq ($ -8) (% arg_z))                 ;    [81]
>>   (jno L132)                              ;    [85]
>>   (nop)                                   ;    [87]
>>   (nop)                                   ;    [91]
>>   (callq (@ .SPFIX-OVERFLOW))             ;    [94]
>>   (leaq (@ (:^ L0) (% rip)) (% fn))       ;   [101]
>>   (jmp L132)                              ;   [108]
>> L110
>>   (movq ($ -8) (% arg_y))                 ;   [110]
>>   (nop)                                   ;   [117]
>>   (callq (@ .SPBUILTIN-PLUS))             ;   [118]
>>   (leaq (@ (:^ L0) (% rip)) (% fn))       ;   [125]
>> L132
>>   (movq (% arg_z) (% save0))              ;   [132]
>> 
>> ;;; (foo1 (1- n))
>>   (jmp L25)                               ;   [135]
>> 
>> ;;; #<no source text>
>> L141
>>   (uuo-error-wrong-number-of-args)        ;   [141]
>> NIL
>> 
>> ? (disassemble 'foo2)
>> ;;; (defun foo2 (n) (labels ((foo (n) (if (<= n 0) 0 (foo (1- n))))) (foo n)))
>> L0
>>   (leaq (@ (:^ L0) (% rip)) (% fn))       ;     [0]
>>   (cmpl ($ 8) (% nargs))                  ;     [7]
>>   (jne L45)                               ;    [10]
>>   (pushq (% rbp))                         ;    [12]
>>   (movq (% rsp) (% rbp))                  ;    [13]
>>   (pushq (% arg_z))                       ;    [16]
>> 
>> ;;; (foo n)
>>   (movl ($ 8) (% nargs))                  ;    [17]
>>   (movq (@ '#<Compiled-function (:INTERNAL FOO FOO2) (Non-Global)  #x30200110BE6F> (% fn)) (% temp0)) ;    [22]
>>   (leaveq)                                ;    [29]
>>   (movq (% fn) (% temp1))                 ;    [30]
>>   (movq (% temp0) (% fn))                 ;    [33]
>>   (jmpq (% fn))                           ;    [36]
>> 
>> ;;; #<no source text>
>> L45
>>   (uuo-error-wrong-number-of-args)        ;    [45]
>> NIL
>> _______________________________________________
>> Openmcl-devel mailing list
>> Openmcl-devel at clozure.com
>> https://lists.clozure.com/mailman/listinfo/openmcl-devel
> 




More information about the Openmcl-devel mailing list