Appendix A. Examples of Generated Code

Table of Contents
A.1. The Sieve of Eratosthenes
A.2. Ackermann's Function

In this chapter we present examples of code generated by the Version 1.7 compiler.

A.1. The Sieve of Eratosthenes

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 checks suppressed.

Example A-2. Generated Code for Sieve


   1               		.file  "sieve_benchmark.adb"
   2               	gcc2_compiled.:
   3               	__gnu_compiled_ada:
   4               		.text
   5               	.global _ada_sieve_benchmark
   6               	_ada_sieve_benchmark:
   7 0000 4AF2 1FFF 		sim    r15,8191
   8 0004 9FEE      		pshm   r14,r14
   9 0006 81EF      		lr     r14,r15
  10 0008 8260      		lisp   r6,1
  11 000a 814F      		lr     r4,r15
  12 000c A146      		ar     r4,r6
  13               	.L5:
  14 000e E555      		xorr   r5,r5
  15 0010 8514 1FFE 		lim    r1,8190,r4
  16 0014 8104      		lr     r0,r4
  17               	.L9:
  18 0016 9111 0000 		stc    1,0,r1  
  19 001a B210      		sisp   r1,1
  20 001c F110      		cr     r1,r0
  21 001e 7BFC      		jge    .L9
  22 0020 E533      		xorr   r3,r3
  23               	.L15:
  24 0022 8114      		lr     r1,r4
  25 0024 A113      		ar     r1,r3
  26 0026 8001 0000 		l      r0,0,r1
  27 002a 4A0A 0000 		cim    r0,0
  28 002e 750F      		jez    .L14
  29 0030 8103      		lr     r0,r3
  30 0032 6000      		sll    r0,1
  31 0034 A202      		aisp   r0,3
  32 0036 8123      		lr     r2,r3
  33 0038 7405      		j      .L27
  34               	.L19:
  35 003a 8114      		lr     r1,r4
  36 003c A112      		ar     r1,r2
  37 003e 9101 0000 		stc    0,0,r1  
  38               	.L27:
  39 0042 A120      		ar     r2,r0
  40 0044 4A2A 1FFE 		cim    r2,8190
  41 0048 78F9      		jle    .L19
  42 004a A250      		aisp   r5,1
  43               	.L14:
  44 004c A230      		aisp   r3,1
  45 004e 4A3A 1FFE 		cim    r3,8190
  46 0052 78E8      		jle    .L15
  47 0054 A260      		aisp   r6,1
  48 0056 F269      		cisp   r6,10
  49 0058 78DB      		jle    .L5
  50 005a 8105      		lr     r0,r5
  51 005c 81FE      		lr     r15,r14
  52 005e 8FEE      		popm   r14,r14
  53 0060 4AF1 1FFF 		aim    r15,8191
  54 0064 7FF0      		urs    r15