Re: 1 extra bytecode instruction per variable per loop

Bruno Haible <[email protected]> Sun, 24 Dec 2017 19:11:08 +0100
Newsgroups gmane.lisp.clisp.devel
Message-ID <1935342.R1x6rooelJ@omega>
Hi Sam,

> --8<---------------cut here---------------start------------->8---
> Disassembly of function :LAMBDA
> (CONST 0) = 100
> (CONST 1) = B
> (CONST 2) = Y
> 0 required arguments
> 0 optional arguments
> No rest parameter
> No keyword parameters
> reads special variables: Y B
> 27 byte-code instructions:
> 0     (CONST&PUSH 0)                      ; 100
> 1     (PUSH-NIL 4)
> 3     (GETVALUE 1)                        ; B
> 5     (STORE 3)
> 6     (GETVALUE 2)                        ; Y
> 8     (STORE 2)
> 9     (JMP L26)
> 11    L11
> --8<---------------cut here---------------end--------------->8---
> 
> becomes
> 
> --8<---------------cut here---------------start------------->8---
> Disassembly of function :LAMBDA
> (CONST 0) = B
> (CONST 1) = Y
> (CONST 2) = 100
> 0 required arguments
> 0 optional arguments
> No rest parameter
> No keyword parameters
> reads special variables: Y B
> 29 byte-code instructions:
> 0     (GETVALUE&PUSH 0)                   ; B
> 2     (GETVALUE&PUSH 1)                   ; Y
> 4     (CONST&PUSH 2)                      ; 100
> 5     (PUSH-NIL 4)
> 7     (LOAD 6)
> 8     (STORE 3)
> 9     (LOAD 5)
> 10    (STORE 2)
> 11    (JMP L28)
> 13    L13
> --8<---------------cut here---------------end--------------->8---
> 
> The cost is probably trivial, but I wonder if there is some simple
> compilation optimization missing here...

The missing compiler optimization is a full data flow analysis.

clisp's compiler supports data flow analysis for simple cases (e.g.
a variable that is only bound to an initform and never assigned).
More complex cases that would require multiple passes are not
implemented.

The LOOP macro (and other macros) have been written in a way to
generate good bytecode.

Bruno


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
clisp-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/clisp-devel