23.10.2013 Views

FAST Forth Native-Language Embedded Computers

FAST Forth Native-Language Embedded Computers

FAST Forth Native-Language Embedded Computers

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

- -<br />

Table Three. Code generated for six words with Voffs in~or~orated.1<br />

V. Combining Generated<br />

dup (state = 0) ............ MOV EAX, [EDI]+ Voffs ....... (new state = 1) Code Instructions<br />

dup (state = 1) ............ MOV EBX, EAX ..................... (new state = 4) The optimizations discussed<br />

dup (state = 12) .......... cVoffs += -4><br />

previously relate to improving<br />

MOV [ED!]+ Voffs, EBX<br />

the speed of the generated code<br />

MOV EDX, EBX ................... (new state = 13) by reducing the number of indrop<br />

(state = 0) ........... cVoffs += +4> ..................... state unchanged)<br />

structions, and the number of<br />

...................................... <br />

memory accesses, needed to<br />

drop (state = 1) ........... ................. (new state = 0)<br />

drop (state = 12) ......... ................. (new state = 5) manipulate items on the data<br />

swap (state = 0) ......... MOV EAX, [EDI]+ Voffs<br />

stack. There is an additional class<br />

MOV EBX, [EDI]+ voffs+4<br />

of optimizations for the genercVoffs<br />

+= +8> ......................... (new state = 6) ated machine code, which takes<br />

swap (state = 1 ) ......... MOV EBX, [EDI]+ Voffs<br />

advantage of the fact that genercVoffs<br />

+= +4> ......................... (new state = 6) ated code instructions can often<br />

swap (state = 12) ....... ............... (new state = 10) be combined into a smaller numrot<br />

(state = 0) .............. MOV EAX, [EDI]+ Voffs<br />

ber of faster instructions.<br />

MOV EBX, [ED[]+ Voffs+4<br />

The most obvious area in<br />

MOV EDX, [EDI]+ Voffs+8<br />

which generated instructions can<br />

..................... (new state = 14)<br />

rot (state = 1 ) .............. MOV EBX, [ED!]+ Voffs<br />

be combined is when literal val-<br />

MOV EDX, CEDI]+ Voffs+4<br />

ues are used. Frequently, the litcVoffs<br />

+= +8> ....................... (new state = 14) eral is consumed by the next<br />

rot (state = 12) ............ ............... (new state = 15) word. If the word following the<br />

xor (state = 0) ............. MOV EAX, [EDI]+ Voffs<br />

literal is a simple word (i.e., a<br />

XOR EAX, [EDI]+ Voffs+4<br />

word that is subject to machinecVoffs<br />

+= +8> ......................... (new state = 1) code optimization), it is often<br />

xor (state = 1 ) ............. XOR EAX, [EDI]+ Voffs<br />

possible to combine the literal<br />

cVoffs += +4> ..................... state unchanged) with the code that is generated by<br />

xor (state = 12) ........... XOR EAX, EBX ..................... (new state = 5)<br />

the simple word. For example,<br />

exit (state = 0) ............ MOV EAX, [EDI]+ Voffs<br />

ADD EDI, Voffs+4<br />

the non-combined way of gener-<br />

RET<br />

ating code for the sequence 15 +<br />

cVoffs = 0> ........................... . (new state = 1) from stack state 1 would be:5<br />

exit (state = 1 ) ............ ADD ED!, Voffs<br />

MOV EBX, 15<br />

RET<br />

(push literal 15 onto data stack)<br />

cVoffs = 0> .......................... state unchanged) ADD EAX, EBX<br />

exit (state = 12) .......... ADD EDI, Voffs-8<br />

(add pushed value to prior top item)<br />

MOV [EDI], EAX<br />

1<br />

MOV [ED1]+4, EDX<br />

However, when these two<br />

MOV EAX, EBX<br />

code instructions are combined,<br />

RET<br />

a single code instruction can be<br />

~Voffs = 0> ............................. (new state = 1 ) used instead:<br />

ADD EAX, 15<br />

Figure Two-d. XOK'S generated code and change-of-stack-state. I (add literal 15 directly to top item)<br />

-<br />

When a named constant is<br />

called, it operates much like a<br />

literal, in that the constant value is<br />

pushed onto the data stack. A<br />

variable operates in much the same<br />

1<br />

EDX<br />

[EDI]<br />

3rd item<br />

1) 2nd item<br />

(1 [EDI] 3rd item (was 4th) I<br />

1 1 [ED1+4] 4th item (was 5th) I<br />

[ED1+8] 5th item (was 6th)<br />

way, except that the constant being<br />

pushed is the variable's address.<br />

In both cases, the pushed<br />

value can often be combined into<br />

the next instruction in much the<br />

[ED1+4]<br />

1 [EDl+l:]<br />

3rd item<br />

5th item 1 1<br />

[ED1+12] 6th item (was 7th)<br />

same way as a literal. For example,<br />

the code instructions to access the<br />

contents of a variable, as generated<br />

by the sequence vl @ (where vl is<br />

defined by the phrase variable<br />

vl), might initially appear as:<br />

A 71<br />

1 Starting stack state = 12 New stack state =5<br />

<strong>Forth</strong> Dimensions 3 7<br />

1<br />

In all the examples in this section, I am<br />

assuming that the starting stack state is state<br />

1 ; the use of Voffs is omitted.<br />

March 1994 April

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!