1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
#define def_wi(i) \
name _w##i \
_w##i: \
prolog \
arg $arg##i \
getarg##i %r0 $arg##i \
retr %r0 \
epilog
#define def_wf(f) \
name _w##f \
_w##f: \
prolog \
arg##f $arg##f \
getarg##f %f0 $arg##f \
truncr##f %r0 %f0 \
retr %r0 \
epilog
#define def_fi(f, i) \
name f##i \
f##i: \
prolog \
arg $arg##i \
getarg##i %r0 $arg##i \
extr##f %f0 %r0 \
retr##f %f0 \
epilog
#define def_f(f) \
name f##f \
f##f: \
prolog \
arg##f $arg##f \
getarg##f %f0 $arg##f \
retr##f %f0 \
epilog
#define def_ff(f, g) \
name f##g \
name f##g \
f##g: \
prolog \
arg##g $arg##g \
getarg##g %f0 $arg##g \
extr##g##f %f0 %f0 \
retr##f %f0 \
epilog
.data 32
fstr:
.c "forward"
bstr:
.c "backward"
.code
jmpi main
def_wi(_c)
def_wi(_uc)
def_wi(_s)
def_wi(_us)
#if __WORDSIZE == 64
def_wi(_i)
def_wi(_ui)
#endif
def_wf(_f)
def_wf(_d)
def_fi(_f, _c)
def_fi(_f, _uc)
def_fi(_f, _s)
def_fi(_f, _us)
def_fi(_f, _i)
#if __WORDSIZE == 64
def_fi(_f, _ui)
def_fi(_f, _l)
#endif
def_fi(_d, _c)
def_fi(_d, _uc)
def_fi(_d, _s)
def_fi(_d, _us)
def_fi(_d, _i)
#if __WORDSIZE == 64
def_fi(_d, _ui)
def_fi(_d, _l)
#endif
def_f(_f)
def_f(_d)
def_ff(_f, _d)
def_ff(_d, _f)
name main
main:
prolog
#define _call_w(n, i, a, r) \
prepare \
pushargi a \
finishi _w##i \
retval %r0 \
extr##i %r0 %r0 \
beqi _w##i##_##n %r0 r \
calli @abort \
_w##i##_##n:
#define call_w(n, i, a, r) _call_w(n, i, a, r)
#define _call_wf(n, f, a, r) \
prepare \
pushargi##f a \
finishi _w##f \
retval %r0 \
extr##f %f0 %r0 \
beqi##f _w##f##_##n %f0 r \
calli @abort \
_w##f##_##n:
#define call_wf(n, f, a, r) _call_wf(n, f, a, r)
#define _call_fi(n, f, i, a, r) \
prepare \
pushargi a \
finishi f##i \
retval##f %f0 \
beqi##f f##i##n %f0 r \
calli @abort \
f##i##n:
#define call_fi(n, f, i, a, r) _call_fi(n, f, i, a, r)
#define _call_f(n, f, a, r) \
prepare \
pushargi##f a \
finishi f##f \
retval##f %f0 \
beqi##f f##f##n %f0 r \
calli @abort \
f##f##n:
#define call_f(n, f, a, r) _call_f(n, f, a, r)
#define _call_ff(n, f, g, a, r) \
prepare \
pushargi##g a \
finishi f##g \
retval##f %f0 \
beqi##f f##g##n %f0 r \
calli @abort \
f##g##n:
#define call_ff(n, f, g, a, r) _call_ff(n, f, g, a, r)
#define c7f 0x7f
#define c80 0x80
#define c81 0x81
#define cff 0xff
#define s7f 0x7fff
#define s80 0x8000
#define s81 0x8001
#define i7f 0x7fffffff
#define i80 0x80000000
#define i81 0x80000001
#define iff 0xffffffff
#define l7f 0x7fffffffffffffff
#define l80 0x8000000000000000
#define l81 0x8000000000000001
#define f7f 127.0
#define f80 -128.0
#define f81 -127.0
#define uf80 128.0
#define uf81 127.0
#if __WORDSIZE == 32
# define wc80 0xffffff80
# define wc81 0xffffff81
# define ws80 0xffff8000
# define ws81 0xffff8001
#else
# define wc80 0xffffffffffffff80
# define wc81 0xffffffffffffff81
# define ws80 0xffffffffffff8000
# define ws81 0xffffffffffff8001
# define wi80 0xffffffff80000000
# define wi81 0xffffffff80000001
#endif
call_w(__LINE__, _c, c7f, c7f)
call_w(__LINE__, _c, c80, wc80)
call_w(__LINE__, _c, c81, wc81)
call_w(__LINE__, _uc, c7f, c7f)
call_w(__LINE__, _uc, c80, c80)
call_w(__LINE__, _uc, c81, c81)
call_w(__LINE__, _s, s7f, s7f)
call_w(__LINE__, _s, s80, ws80)
call_w(__LINE__, _s, s81, ws81)
call_w(__LINE__, _us, s7f, s7f)
call_w(__LINE__, _us, s80, s80)
call_w(__LINE__, _us, s81, s81)
#if __WORDSIZE == 64
call_w(__LINE__, _i, i7f, i7f)
call_w(__LINE__, _i, i80, wi80)
call_w(__LINE__, _i, i81, wi81)
call_w(__LINE__, _ui, i7f, i7f)
call_w(__LINE__, _ui, i80, i80)
call_w(__LINE__, _ui, i81, i81)
#endif
call_wf(__LINE__, _f, c7f, f7f)
call_wf(__LINE__, _f, wc80, f80)
call_wf(__LINE__, _f, wc81, f81)
call_wf(__LINE__, _d, c7f, f7f)
call_wf(__LINE__, _d, wc80, f80)
call_wf(__LINE__, _d, wc81, f81)
call_fi(__LINE__, _f, _c, c7f, f7f)
call_fi(__LINE__, _f, _c, c80, f80)
call_fi(__LINE__, _f, _uc, c7f, f7f)
call_fi(__LINE__, _f, _uc, c80, uf80)
call_fi(__LINE__, _f, _s, c7f, f7f)
call_fi(__LINE__, _f, _s, c80, uf80)
call_fi(__LINE__, _f, _us, c7f, f7f)
call_fi(__LINE__, _f, _us, c80, uf80)
call_fi(__LINE__, _f, _i, c7f, f7f)
call_fi(__LINE__, _f, _i, c80, uf80)
#if __WORDSIZE == 64
call_fi(__LINE__, _f, _ui, c7f, f7f)
call_fi(__LINE__, _f, _ui, c80, uf80)
call_fi(__LINE__, _f, _l, c7f, f7f)
call_fi(__LINE__, _f, _l, c80, uf80)
#endif
call_fi(__LINE__, _d, _c, c7f, f7f)
call_fi(__LINE__, _d, _c, c80, f80)
call_fi(__LINE__, _d, _uc, c7f, f7f)
call_fi(__LINE__, _d, _uc, c80, uf80)
call_fi(__LINE__, _d, _s, c7f, f7f)
call_fi(__LINE__, _d, _s, c80, uf80)
call_fi(__LINE__, _d, _us, c7f, f7f)
call_fi(__LINE__, _d, _us, c80, uf80)
call_fi(__LINE__, _d, _i, c7f, f7f)
call_fi(__LINE__, _d, _i, c80, uf80)
#if __WORDSIZE == 64
call_fi(__LINE__, _d, _ui, c7f, f7f)
call_fi(__LINE__, _d, _ui, c80, uf80)
call_fi(__LINE__, _d, _l, c7f, f7f)
call_fi(__LINE__, _d, _l, c80, uf80)
#endif
call_f(__LINE__, _f, f7f, f7f)
call_f(__LINE__, _d, f7f, f7f)
call_ff(__LINE__, _f, _d, f80, f80)
call_ff(__LINE__, _d, _f, f81, f81)
movi %r0 forward
callr %r0
calli iforward
ret
epilog
name backward
backward:
prolog
prepare
pushargi bstr
finishi @puts
ret
epilog
name forward
forward:
prolog
prepare
pushargi fstr
finishi @puts
movi %r0 backward
callr %r0
ret
epilog
name iforward
iforward:
prolog
prepare
pushargi fstr
finishi @puts
calli backward
ret
epilog
|