26.10.2013 Views

Sieve of Eratosthenes benchmarks for the Z8 FORTH microcontroller

Sieve of Eratosthenes benchmarks for the Z8 FORTH microcontroller

Sieve of Eratosthenes benchmarks for the Z8 FORTH microcontroller

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

6. IMPROVING THE EFFICIENCY OF THE INNER LOOP<br />

To take advantage <strong>of</strong> an alternative method <strong>of</strong> marking <strong>the</strong> multiples, notice that <strong>the</strong><br />

BEGlN..WHlLE..LOOP consists <strong>of</strong> marking <strong>the</strong> last row <strong>of</strong> an N by SIZE/N matrix with<br />

zeros except <strong>for</strong> <strong>the</strong> cell in <strong>the</strong> first column. In <strong>the</strong> case <strong>of</strong> N=3, <strong>the</strong> result <strong>of</strong> <strong>the</strong><br />

inner calculation is:<br />

A1 A4 A? A10 ... ASIZE/3-2<br />

A2 A5 A8 All ... ASIZE/J-l<br />

1 0 0 0 ... 0<br />

Once <strong>the</strong> relation <strong>of</strong> <strong>the</strong> multiple-marking process to matrix operations is recognized, a<br />

more efficient method <strong>of</strong> initializing <strong>the</strong> FLAGS array is possible using a FOKTIl word<br />

(FILL-ROW) to initialize a row <strong>of</strong> a FLAGS array in matrix <strong>for</strong>mat.6 After using<br />

FILL-ROW, <strong>the</strong> program must reset <strong>the</strong> initial element <strong>of</strong> <strong>the</strong> row back to 1. The four<br />

arguments <strong>for</strong> <strong>the</strong> FILL-ROW word are similar to those <strong>for</strong> FILL, except that extra<br />

parameters <strong>for</strong> <strong>the</strong> row index and column length are inserted after <strong>the</strong> array-name<br />

argument. The stack situation when calling FILL-ROW must be programmed to be:<br />

Array name, Rou index, Colm length, Array size, Initialization value<br />

Modifying <strong>the</strong> <strong>FORTH</strong> program to use <strong>the</strong> word FILL-ROW results in <strong>the</strong> program shown<br />

at <strong>the</strong> top <strong>of</strong> <strong>the</strong> next page:<br />

‘An implementation <strong>of</strong> <strong>the</strong> word FILL-ROW <strong>for</strong> 28 <strong>FORTH</strong> is provided in Appendix B.<br />

13

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

Saved successfully!

Ooh no, something went wrong!