26.10.2013 Views

2 - Forth Interest Group

2 - Forth Interest Group

2 - Forth Interest Group

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Pinhole optimization. I<br />

These are samples of the pinhole optimizations in the system I'm using at the time<br />

of writing. They are subject to change without notice.<br />

A lowercase letter other than "b" represents a literal, constant, or variable. "b"<br />

represents a literal or constant that is a power of 2.<br />

n + x n + x + n + 0 + SWAP +<br />

n - x n - x + n - 0 - SWAP -<br />

x n * b * 1 * CHARS<br />

x n / 1 /<br />

X @ DUP @<br />

x ! SWAP !<br />

x + ! SWAP+!<br />

n < SWAP < 0 <<br />

n = n OVER = DUP n = 0 = FALSE =<br />

n ALIGNED<br />

n AND x n AND<br />

n >BODY [I] x >BODY [ '1 >BODY n CELLS +<br />

['I >BODY n CELLS + @ [ ' 1 >BODY n CELLS + !<br />

n CELLS<br />

n COUNT C" CCC" COUNT<br />

DUP IF ?DUP IF DUP O= IF ?DUP O= IF<br />

O< IF FALSE IF O< NOT IF O= NOT IF<br />

1 +LOOP 1 CHARS +LOOP<br />

x n LSHIFT x LSHIFT n LSHIFT n LSHIFT<br />

b MOD<br />

n OR x n OR<br />

0 PICK OVER 1 PICK 1 PICK n PICK<br />

ROT ROT ROT ROT ROT<br />

n RSHIFT x n RSHIFT<br />

n U< SWAP U<<br />

n UNDER+<br />

DUP UNTIL ?DUP UNTIL DUP O= UNTIL ?DUP O= UNTIL<br />

O< UNTIL FALSE UNTIL O< NOT UNTIL O= NOT UNTIL<br />

n XOR x n XOR<br />

DUP WHILE ?DUP WHILE DUP O= WHILE ?DUP O= WHILE<br />

O< WHILE FALSE WHILE O< NOT WHILE O= NOT WHILE<br />

AGAIN ; QUIT ; ABORT ; BYE ;<br />

Here is a typical implementation of the required control-flow words other than<br />

LEAVE. Words that contain one or more lowercase letters, or are a single uppercase<br />

letter other than I or J, are not in Standard <strong>Forth</strong>, and probably won't be available<br />

to you.<br />

Not all optimizations are given.<br />

branch, compiles part of an unconditional branch;<br />

?branch, compiles part of a conditional branch;<br />

do,, loop,, and +loop, compile parts of the execution semantics of DO, LOOP, and<br />

+LOOP.<br />

>mark puts the origin of a forward branch on the control-flow stack;<br />

resolve resolves the destination of a forward branch;<br />

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

Saved successfully!

Ooh no, something went wrong!