| M68K Ada Technical Summary: For mission-critical applications on Motorola M68000 family computers | ||
|---|---|---|
| Prev | Next | |
In this chapter we present examples of code generated by the Version 1.7 compiler.
Compiler writers use the Sieve of Eratosthenes benchmark to check code quality and to compare run-time performance among compilers, languages and computers.
The benchmark uses the sieve method to compute the number of odd primes between 3 and 16383.
Example A-1. Source Code for Sieve
procedure Sieve_Benchmark (Result : out Integer) is
Size : constant := 8190;
k, Prime : Natural;
Count : Integer;
type Ftype is array (0 .. Size) of Boolean;
Flags : Ftype;
begin
for Iter in 1 .. 10 loop
Count := 0;
for i in 0 .. Size loop
Flags (i) := True;
end loop;
for i in 0 .. Size loop
if Flags (i) then
Prime := i + i + 3;
k := i + Prime;
while k <= Size loop
Flags (k) := False;
k := k + Prime;
end loop;
Count := Count + 1;
end if;
end loop;
end loop;
Result := Count;
end Sieve_Benchmark;
The generated code is given in Example A-2. The code was generated at optimization level 2 with all checks included.
Example A-2. Generated Code for Sieve
1 .file "sieve.adb" 2 gcc2_compiled.: 3 __gnu_compiled_ada: 4 .text 5 .even 6 .globl _ada_sieve_benchmark 7 _ada_sieve_benchmark: 8 0000 4E56 0000 link.w %a6,#0 9 0004 48E7 3C20 movm.l #0x3c20,-(%sp) 10 0008 BBCF cmp.l %sp,%a5 11 000a 6B02 bmi.b .+4 12 000c 4E45 trap #5 13 000e 41EF E000 lea (-8192,%sp),%a0 14 0012 BBC8 cmp.l %a0,%a5 15 0014 6B02 bmi.b .+4 16 0016 4E45 trap #5 17 0018 2E48 move.l %a0,%sp 18 001a 244F move.l %sp,%a2 19 001c 7801 moveq.l #1,%d4 20 .even 21 .L5: 22 001e 4283 clr.l %d3 23 0020 203C 0000 move.l #8190,%d0 23 1FFE 24 0026 41F2 0800 lea (%a2,%d0.l),%a0 25 .even 26 .L9: 27 002a 10BC 0001 move.b #1,(%a0) 28 002e 5388 subq.l #1,%a0 29 0030 51C8 FFF8 dbra %d0,.L9 30 0034 4240 clr.w %d0 31 0036 5380 subq.l #1,%d0 32 0038 64F0 jbcc .L9 33 003a 4282 clr.l %d2 34 003c 224A move.l %a2,%a1 35 .even 36 .L15: 37 003e 4A19 tst.b (%a1)+ 38 0040 6728 jbeq .L14 39 0042 2002 move.l %d2,%d0 40 0044 D080 add.l %d0,%d0 41 0046 5680 addq.l #3,%d0 42 0048 2202 move.l %d2,%d1 43 004a 6012 jbra .L29 44 .even 45 .even 46 .L19: 47 004c 0C81 0000 cmp.l #8190,%d1 47 1FFE 48 0052 6204 jbhi .L20 49 0054 2041 move.l %d1,%a0 50 0056 6002 jbra .L21 51 .even 52 .L20: 53 0058 50FC trapt 54 .even 55 .L21: 56 005a 4230 A800 clr.b (%a0,%a2.l) 57 .L29: 58 005e D280 add.l %d0,%d1 59 0060 0C81 0000 cmp.l #8190,%d1 59 1FFE 60 0066 6FE4 jble .L19 61 0068 5283 addq.l #1,%d3 62 .L14: 63 006a 5282 addq.l #1,%d2 64 006c 0C82 0000 cmp.l #8190,%d2 64 1FFE 65 0072 6FCA jble .L15 66 0074 5284 addq.l #1,%d4 67 0076 7A0A moveq.l #10,%d5 68 0078 BA84 cmp.l %d4,%d5 69 007a 6CA2 jbge .L5 70 007c 2003 move.l %d3,%d0 71 007e 4CEE 043C movm.l -20(%a6),#0x43c 71 FFEC 72 0084 4E5E unlk %a6 73 0086 4E75 rts