Pristine Ack-5.5
[Ack-5.5.git] / doc / sparc / B
1 .In
2 .SH
3 B. IMPLEMENTATION
4 .SH
5 B.1. Excerpts from the non-optimized EM_table
6 .PP
7 Even though the non-optimized version of the EM_table is relatively
8 straight-forward, examples have never hurt anybody.
9 One of the simplest instructions is the \*(Siloc\*(So, which appears in
10 our EM_table as follows:
11 .DS
12 \f6
13 .TA 8 16 24 32 40 48 56 64
14 C_loc   ==>     "set    $1, T1";
15                 "dec    4, SP";
16                 "st     T1, [SP]".
17 \f1
18 .DE
19 Just as \*(SiSP\*(So is an alias for \*(Si%l0\*(So, \*(SiT1\*(So is
20 an alias for \*(Si%g1\*(So.
21 A little more complex is the \*(Siadi\*(So which performs integer
22 addition.
23 .DS
24 \f6
25 C_adi   ==>     "ld     [SP], T1";
26                 "ld     [SP+4], T2";
27                 "add    T1, T2, T3";
28                 "st     T3, [SP+4];
29                 "inc    4, SP".
30 \f1
31 .DE
32 We could go on with even more complex instructions, but since that would
33 not contribute to anything the reader is referred to the implementation
34 for more details.
35 .SH
36 B.2. Excerpts from the optimized EM_table
37 .PP
38 The optimized EM_table uses the cache primitives mentioned in chapter 4.
39 This means that the \*(Siloc\*(So this time appears as
40 .DS
41 \f6
42 C_loc   ==>     push_const($1).
43 \f1
44 .DE
45 The \*(Silol\*(So can now be written as
46 .DS
47 \f6
48 C_lol   ==>     push_reg(LB);
49                 inc_tos($1);
50                 push_const(4);
51                 C_los(4).
52 \f1
53 .DE
54 Due to the law of conservation of misery somebody has to do the dirty work.
55 In this case, it is the \*(Silos\*(So. To show just a small part of
56 the implementation of the \*(Silos\*(So:
57 .DS
58 \f6
59 C_los   $1 == 4 ==>
60                 if (type_of_tos() == T_cst) {
61                         arith size;
62                         const_str_t n;
63
64                         size= pop_const();
65                         if (size <= 4) {
66                                 reg_t a;
67                                 reg_t a;
68                                 char *LD;
69
70                                 switch (size) {
71                                 case 1: LD = "ldub"; break;
72                                 case 2: LD = "lduh"; break;
73                                 case 4: LD = "ld"; break;
74                                 default:        arg_error("C_los", size);
75                                 }
76                                 a = pop_reg_c13(n);
77                                 b = alloc_reg();
78                                 "$LD    [$a+$n], $b";
79                                 push_reg(b);
80                                 free_reg(a);
81                         } else ...
82 \f1
83 .DE
84 For the full implementation, the reader is again referred to the actual
85 implementation. Just to show how other instructions are affected
86 by the optimization we will show that implementation of the \*(Sitge\*(So
87 instruction:
88 .DS
89 \f6
90 C_tge   ==>     {
91                         reg_t a;
92                         reg_t b;
93
94                         a = pop_reg();
95                         b = alloc_reg();
96                         "       tst     $a";
97                         "       bge,a   1f";
98                         "       mov     1, $b";         /* delay slot */
99                         "       set     0, $b";
100                         "1:";
101                         free_reg(a);
102                         push_reg(b);
103                 }.
104
105 \f1
106 .DE
107 .SH
108 .bp
109 CREDITS
110 .PP
111 In order of appearance:
112 .TS
113 center;
114 r c l.
115 Original idea   -       Dick Grune
116 Design & implementation -       Philip Homburg
117         -       Raymond Michiels
118 Tutor   -       Dick Grune
119 Assistant Tutor -       Ceriel Jacobs
120 Proofreading    -       Dick Grune
121         -       Hans van Eck
122 .TE
123 .SH
124 REFERENCES
125 .PP
126 .[
127 $LIST$
128 .]