blob: faf63d23ad27b630f0103f06ffd2a0a3c0fb7a17 (
plain)
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
|
#if __WORDSIZE == 32
# define SIZE 4
#else
# define SIZE 8
#endif
.data 8192
fmt:
.c "xfibs(%d) = %d\n"
/* Simulate a language specific stack */
.align SIZE
top:
/* Top, or base of the stack */
.size SIZE
stk:
.size 8160
.code
jmpi main
/* Usually a trampoline is created before the code that uses it, but
* for testing purposes it is not required.
* In this test case, it would mean "main" would be converted in a
* different jit_state_t to native code, before xfibs was know.
*/
name xfibs
xfibs:
/* return address is in %r0 */
/* argument and return value in %v0 */
prolog
tramp 64
blti_u out %v0 2
subi %v1 %v0 1 /* V1 = N-1 */
subi %v2 %v0 2 /* V1 = N-2 */
/* save return address */
ldi %r1 top
stxi $(SIZE * 0) %r1 %r0
/* save operands */
stxi $(SIZE * 1) %r1 %v0
stxi $(SIZE * 2) %r1 %v1
stxi $(SIZE * 3) %r1 %v2
/* adjust "language" stack */
addi %r1 %r1 $(SIZE * 4)
sti top %r1
/* return address */
movi %r0 ret1
/* argument */
movr %v0 %v1
/* indirect goto */
jmpi xfibs
ret1:
movr %v1 %v0 /* V1 = rfibs(N-1) */
/* save V1 */
ldi %r1 top
stxi $(-SIZE * 2) %r1 %v1
/* reload V2 */
ldxi %v2 %r1 $(-SIZE * 1)
/* return address */
movi %r0 ret2
/* argument */
movr %v0 %v2
/* indirect goto */
jmpi xfibs
ret2:
movr %v2 %v0 /* V2 = rfibs(N-2) */
/* reload return address */
ldi %r1 top
subi %r1 %r1 $(SIZE * 4)
ldxi %r0 %r1 $(SIZE * 0)
/* reload operands */
ldxi %v0 %r1 $(SIZE * 1)
ldxi %v1 %r1 $(SIZE * 2)
/* V2 already loaded */
/* update "language" stack */
sti top %r1
addi %v1 %v1 1
addr %v0 %v1 %v2
jmpr %r0
out:
movi %v0 1
jmpr %r0
epilog
name main
main:
prolog
frame 64
/* Initialize language stack */
movi %r0 stk
sti top %r0
/* return address */
movi %r0 done
/* argument */
movi %v0 32
jmpi xfibs
done:
prepare
pushargi fmt
ellipsis
pushargi 32
pushargr %v0
finishi @printf
ret
epilog
|