[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: consing with +



I can think of two ways to get the information you want.
First, wrap your call to plus into a function

? (defun foo ()
     (let ((a 1) (b 2) (c 3) (d 4) (e 5) (f 6) (g 7) (h 8))
       (+ a b c d e f g h)))
FOO

Disassembly shows what the compiler did:

? (disassemble 'foo)
0 (JSR_SUBPRIM $SP-NOARGS)
4 (MOVEQ (FIXNUM 1) D3)
6 (VPUSH D3)
8 (MOVEQ (FIXNUM 2) D3)
10 (VPUSH D3)
12 (MOVEQ (FIXNUM 3) D3)
14 (VPUSH D3)
16 (MOVEQ (FIXNUM 4) D3)
18 (VPUSH D3)
20 (MOVEQ (FIXNUM 5) D3)
22 (VPUSH D3)
24 (MOVEQ (FIXNUM 6) D2)
26 (MOVEQ (FIXNUM 7) D1)
28 (MOVEQ (FIXNUM 8) D0)
30 (SET_NARGS 8)
32 (MOVE.L '#<+ Symbol Function Locative> ATEMP0)
38 (JMP_SUBPRIM $SP-TCALLSLIDE)

If you have a hard time reading the dissassembly, you can wrap
the trace around the form you're calling to prevent seeing every
call to + in MCL:

? (without-interrupts
   (unwind-protect
     (progn
       (trace +)
       (foo))
     (untrace)))
 Calling (+ 1 2 3 4 5 6 7 8) 
 + returned 36
36
?

You'll need to be careful with this second technique as if you trace
anything that needs to call + to display itself, you may get unexpected
results. For example, when I said (time (foo)) instead of just (foo)
in the form above, I saw some output due to TIME's calls of +.