aboutsummaryrefslogtreecommitdiff
path: root/deps/lightning/check/ldstxr.tst
blob: 14620dc732e20b10aa23455b559494cc5e82c6b2 (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
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
#include "ldst.inc"

#if __WORDSIZE == 64
#  define LDSTL(N, R0, R1, R2)					\
	movi %R2 $offui						\
	stxr_i %R2 %R0 %R1					\
	movi %R1 L##N						\
	movi %R2 $offl						\
	stxr_l %R2 %R0 %R1

#  define SI(C, N, x, X, R0, R1, R2)				\
	movi %R2 $off##x					\
	ldxr_##x %R1 %R0 %R2					\
	beqi L##x##C %R1 L##X##N				\
	calli @abort						\
L##x##C:

#  define LDRL(C, N, R0, R1, R2)				\
	UI(C, N, i, I, R0, R1, R2)				\
	SI(C, N, l, L, R0, R1, R2)
#else
#  define LDSTL(C, R0, R1, R2)
#  define SI(C, N, x, X, R0, R1, R2)				\
	movi %R2 $off##x					\
	ldxr_##x %R1 %R0 %R2					\
	beqi L##x##C %R1 I##X##N				\
	calli @abort						\
L##x##C:

#  define LDRL(C, N, R0, R1, R2)

#endif

#define UI(C, N, x, X, R0, R1, R2)				\
	movi %R2 $offu##x					\
	ldxr_u##x %R1 %R0 %R2					\
	beqi Lu##x##C %R1 X##N					\
	calli @abort						\
Lu##x##C:

#define FF(C, N, x, X, R0, R1, F0)				\
	movi %R1 $off##x					\
	ldxr_##x %F0 %R0 %R1					\
	beqi_##x L##x##C %F0 X##N				\
L##x##C:

#define LDST1(X, N, R0, R1, R2, F0)				\
	movi %R0 t0						\
	movi %R1 C##N						\
	movi %R2 $offc						\
	stxr_c %R2 %R0 %R1					\
	movi %R2 $offuc						\
	stxr_c %R2 %R0 %R1					\
	movi %R1 S##N						\
	movi %R2 $offs						\
	stxr_s %R2 %R0 %R1					\
	movi %R2 $offus						\
	stxr_s %R2 %R0 %R1					\
	movi %R1 I##N						\
	movi %R2 $offi						\
	stxr_i %R2 %R0 %R1					\
	LDSTL(N, R0, R1, R2)					\
	movi_f %F0 F##N						\
	movi %R2 $offf						\
	stxr_f %R2 %R0 %F0					\
	movi_d %F0 D##N						\
	movi %R2 $offd						\
	stxr_d %R2 %R0 %F0					\
	SI(X, N, c, C, R0, R1, R2)				\
	UI(X, N, c, C, R0, R1, R2)				\
	SI(X, N, s, S, R0, R1, R2)				\
	UI(X, N, s, S, R0, R1, R2)				\
	SI(X, N, i, I, R0, R1, R2)				\
	LDRL(X, N, R0, R1, R2)					\
	FF(X, N, f, F, R0, R1, F0)				\
	FF(X, N, d, D, R0, R1, F0)

#define LDST0(R0, R1, R2, F0)					\
	LDST1(0_##R0##_##R1##_##R2##_##F0, 0, R0, R1, R2, F0)	\
	LDST1(1_##R0##_##R1##_##R2##_##F0, 1, R0, R1, R2, F0)	\
	LDST1(2_##R0##_##R1##_##R2##_##F0, 2, R0, R1, R2, F0)	\
	LDST1(3_##R0##_##R1##_##R2##_##F0, 3, R0, R1, R2, F0)

#define LDST(V0, V1, V2, R0, R1, R2, F0, F1, F2, F3, F4, F5)	\
	LDST0(V0, V1, R0, F0)					\
	LDST0(V0, V1, R1, F1)					\
	LDST0(V0, V1, R2, F2)					\
	LDST0(V0, V2, R0, F3)					\
	LDST0(V0, V2, R1, F4)					\
	LDST0(V0, V2, R2, F5)					\
	LDST0(V0, R0, V1, F0)					\
	LDST0(V0, R0, V2, F1)					\
	LDST0(V0, R0, R1, F2)					\
	LDST0(V0, R0, R2, F3)					\
	LDST0(V0, R0, V1, F4)					\
	LDST0(V0, R1, V1, F5)					\
	LDST0(V0, R1, V2, F0)					\
	LDST0(V0, R1, R0, F1)					\
	LDST0(V0, R1, R2, F2)					\
	LDST0(V0, V1, V2, F3)					\
	LDST0(V0, R1, R0, F4)					\
	LDST0(V0, R1, R2, F5)					\
	LDST0(R0, V1, V0, F0)					\
	LDST0(R0, V1, R1, F1)					\
	LDST0(R0, V1, R2, F2)					\
	LDST0(R0, V2, V0, F3)					\
	LDST0(R0, V2, R1, F4)					\
	LDST0(R0, V2, R2, F5)					\
	LDST0(R0, V0, V1, F0)					\
	LDST0(R0, V0, V2, F1)					\
	LDST0(R0, V0, R1, F2)					\
	LDST0(R0, V0, R2, F3)					\
	LDST0(R0, V0, V1, F4)					\
	LDST0(R0, R1, V1, F5)					\
	LDST0(R0, R1, V2, F0)					\
	LDST0(R0, R1, V0, F1)					\
	LDST0(R0, R1, R2, F2)					\
	LDST0(R0, V1, V2, F3)					\
	LDST0(R0, R1, V0, F4)					\
	LDST0(R0, R1, R2, F5)

.code
	prolog

	/* Simple test to simplify validating encodings before
	 * brute force tests */
	movi %r0 t0
	movi %r1 0x81
	movi %r2 $offc
	stxr_c %r2 %r0 %r1
	movi %r2 $offuc
	stxr_c %r2 %r0 %r1
	movi %r1 0x8001
	movi %r2 $offs
	stxr_s %r2 %r0 %r1
	movi %r2 $offus
	stxr_s %r2 %r0 %r1
	movi %r1 0x80000001
	movi %r2 $offi
	stxr_i %r2 %r0 %r1
#if __WORDSIZE == 64
	movi %r2 $offui
	stxr_i %r2 %r0 %r1
	movi %r1 0x8000000000000001
	movi %r2 $offl
	stxr_l %r2 %r0 %r1
#endif
	movi_f %f0 0.5
	movi %r2 $offf
	stxr_f %r2 %r0 %f0
	movi_d %f0 0.25
	movi %r2 $offd
	stxr_d %r2 %r0 %f0
	movi %r2 $offc
	ldxr_c %r1 %r0 %r2
	beqi Lc %r1 XC
	calli @abort
Lc:
	movi %r2 $offuc
	ldxr_uc %r1 %r0 %r2
	beqi Luc %r1 0x81
	calli @abort
Luc:
	movi %r2 $offs
	ldxr_s %r1 %r0 %r2
	beqi Ls %r1 XS
	calli @abort
Ls:
	movi %r2 $offus
	ldxr_us %r1 %r0 %r2
	beqi Lus %r1 0x8001
	calli @abort
Lus:
	movi %r2 $offi
	ldxr_i %r1 %r0 %r2
	beqi Li %r1 XI
	calli @abort
Li:
#if __WORDSIZE == 64
	movi %r2 $offui
	ldxr_ui %r1 %r0 %r2
	beqi Lui %r1 0x80000001
	calli @abort
Lui:
	movi %r2 $offl
	ldxr_l %r1 %r0 %r2
	beqi Ll %r1 0x8000000000000001
	calli @abort
Ll:
#endif
	movi %r2 $offf
	ldxr_f %f0 %r0 %r2
	beqi_f Lf %f0 0.5
	calli @abort
Lf:
	movi %r2 $offd
	ldxr_d %f0 %r0 %r2
	beqi_d Ld %f0 0.25
	calli @abort
Ld:

	LDST(v0, v1, v2, r0, r1, r2, f0, f1, f2, f3, f4, f5)
	// just to know did not abort
	prepare
		pushargi ok
		ellipsis
	finishi @printf
	ret
	epilog