1 /*
2 * Copyright (C) 2013-2019 Free Software Foundation, Inc.
3 *
4 * This file is part of GNU lightning.
5 *
6 * GNU lightning is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation; either version 3, or (at your option)
9 * any later version.
10 *
11 * GNU lightning is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 * License for more details.
15 *
16 * Authors:
17 * Paulo Cesar Pereira de Andrade
18 */
19
20 #if PROTO
21
22 /* FIXME should actually be hw model/version/etc or other constraint
23 * that causes a SIGSEGV/SIGILL if using these instructions */
24 #if 1 //defined(__hpux)
25 # define FSTXR 0
26 # define FLDXR 0
27 #else
28 # define FSTXR 1
29 # define FLDXR 1
30 #endif
31
32 #define f39(o,b,x,t) _f39(_jit,o,b,x,t)
33 static void _f39(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t,jit_int32_t);
34 #define f40(o,b,x,r) _f40(_jit,o,b,x,r)
35 static void _f40(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t,jit_int32_t)
36 maybe_unused;
37 #define f41(o,b,x,t) _f41(_jit,o,b,x,t)
38 static void _f41(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t,jit_int32_t);
39 #define f42(o,b,i,r) _f42(_jit,o,b,i,r)
40 static void _f42(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t,jit_int32_t);
41 #define f43(o,b,t,i) f1(o,b,t,i)
42 #define f45(o,r,a,b,fmt,c,d,e,t) _f45(_jit,o,r,a,b,fmt,c,d,e,t)
43 static void _f45(jit_state_t*,jit_int32_t,
44 jit_int32_t,jit_int32_t,jit_int32_t,jit_int32_t,
45 jit_int32_t,jit_int32_t,jit_int32_t,jit_int32_t) maybe_unused;
46 #define f46(o,r,a,s,df,sf,b,c,d,t) _f46(_jit,o,r,a,s,df,sf,b,c,d,t)
47 static void _f46(jit_state_t*,jit_int32_t,jit_int32_t,
48 jit_int32_t,jit_int32_t,jit_int32_t,jit_int32_t,
49 jit_int32_t,jit_int32_t,jit_int32_t,jit_int32_t);
50 #define f47(o,r1,r2,a,fmt,b,c,d,t) f47_48(o,r1,r2,a,fmt,b,c,d,t)
51 #define f48(o,r1,r2,a,fmt,b,c,d,t) f47_48(o,r1,r2,a,fmt,b,c,d,t)
52 #define f47_48(o,r1,r2,y,fmt,b,c,d,t) _f47_48(_jit,o,r1,r2,y,fmt,b,c,d,t)
53 static void _f47_48(jit_state_t*,jit_int32_t,
54 jit_int32_t,jit_int32_t,jit_int32_t,jit_int32_t,
55 jit_int32_t,jit_int32_t,jit_int32_t,jit_int32_t);
56 #define f49(o,r,a,b,c,f,d,e,g,h,i,t) f49_52(o,r,a,b,c,f,d,e,g,h,i,t)
57 #define f51(o,r1,r2,y,a,f,b,d,e,g,h,c) f49_52(o,r1,r2,y,a,f,b,d,e,g,h,c)
58 #define f52(o,r1,r2,a,b,f,c,d,e,g,h,t) f49_52(o,r1,r2,a,b,f,c,d,e,g,h,t)
59 #define f49_52(o,r1,r2,y,v,f,a,b,u,c,d,t) _f49_52(_jit,o,r1,r2,y,v,f,a,b,u,c,d,t)
60 static void _f49_52(jit_state_t*,jit_int32_t,
61 jit_int32_t,jit_int32_t,jit_int32_t,
62 jit_int32_t,jit_int32_t,jit_int32_t,jit_int32_t,
63 jit_int32_t,jit_int32_t,jit_int32_t,jit_int32_t);
64 #define f53(o,r1,r2,ta,ra,f,tm) _f53(_jit,o,r1,r2,ta,ra,f,tm)
65 static void _f53(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t,
66 jit_int32_t,jit_int32_t,jit_int32_t,jit_int32_t) maybe_unused;
67 #define f54(o,r1,r2,a,b,f,c,d,e,g,t) _f54(_jit,o,r1,r2,a,b,f,c,d,e,g,t)
68 static void _f54(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t,
69 jit_int32_t,jit_int32_t,jit_int32_t,jit_int32_t,
70 jit_int32_t,jit_int32_t,jit_int32_t,jit_int32_t) maybe_unused;
71 #define FABS_(f,r,t) f49(0xe,r,0,3,0,f,0,0,0,0,0,t)
72 #define FABS_S(r,t) FABS_(0,r,t)
73 #define FABS_D(r,t) FABS_(1,r,t)
74 #define FABS_Q(r,t) f45(0xc,r,0,3,3,0,0,0,t)
75 #define FADD_(f,r1,r2,t) f52(0xe,r1,r2,0,0,f,3,0,0,0,0,t)
76 #define FADD_S(r1,r2,t) FADD_(0,r1,r2,t)
77 #define FADD_D(r1,r2,t) FADD_(1,r1,r2,t)
78 #define FADD_Q(r1,r2,t) f48(0xc,r1,r2,0,3,3,0,0,t)
79 #define FPSR_GT 1
80 #define FPSR_LT 2
81 #define FPSR_EQ 4
82 #define FPSR_UN 8
83 /*
84 Actually these are reversed, but easier for the FTEST after the FCMP
85 fcmp,dbl,false? fr4,fr12 0
86 fcmp,dbl,false fr4,fr12 1
87 fcmp,dbl,? fr4,fr12 2
88 fcmp,dbl,!<=> fr4,fr12 3 ORD
89 fcmp,dbl,= fr4,fr12 4 NE
90 fcmp,dbl,=t fr4,fr12 5
91 fcmp,dbl,?= fr4,fr12 6
92 fcmp,dbl,!<> fr4,fr12 7 LTGT
93 fcmp,dbl,!?>= fr4,fr12 8
94 fcmp,dbl,< fr4,fr12 9 UNGE
95 fcmp,dbl,?< fr4,fr12 10
96 fcmp,dbl,!>= fr4,fr12 11 GE
97 fcmp,dbl,!?> fr4,fr12 12
98 fcmp,dbl,<= fr4,fr12 13 UNGT
99 fcmp,dbl,?<= fr4,fr12 14
100 fcmp,dbl,!> fr4,fr12 15 GT
101 fcmp,dbl,!?<= fr4,fr12 16
102 fcmp,dbl,> fr4,fr12 17 UNLE
103 fcmp,dbl,?> fr4,fr12 18
104 fcmp,dbl,!<= fr4,fr12 19 LE
105 fcmp,dbl,!?< fr4,fr12 20
106 fcmp,dbl,>= fr4,fr12 21 UNLT
107 fcmp,dbl,?>= fr4,fr12 22
108 fcmp,dbl,!< fr4,fr12 23 LT
109 fcmp,dbl,!?= fr4,fr12 24
110 fcmp,dbl,<> fr4,fr12 25 UNEQ
111 fcmp,dbl,!= fr4,fr12 26 EQ
112 fcmp,dbl,!=t fr4,fr12 27
113 fcmp,dbl,!? fr4,fr12 28
114 fcmp,dbl,<=> fr4,fr12 29 UNORD
115 fcmp,dbl,true? fr4,fr12 30
116 fcmp,dbl,true fr4,fr12 31
117 */
118 #define FCMP_LT 23
119 #define FCMP_LE 19
120 #define FCMP_EQ 26
121 #define FCMP_GE 11
122 #define FCMP_GT 15
123 #define FCMP_NE 4
124 #define FCMP_UNLT 21
125 #define FCMP_UNLE 17
126 #define FCMP_UNEQ 25
127 #define FCMP_UNGE 9
128 #define FCMP_UNGT 13
129 #define FCMP_LTGT 7
130 #define FCMP_ORD 3
131 #define FCMP_UNORD 29
132 #define FCMP_(f,r1,r2,c) f51(0xe,r1,r2,0,0,f,2,0,0,0,0,c)
133 #define FCMP_S_(r1,r2,c) FCMP_(0,r1,r2,c)
134 #define FCMP_D_(r1,r2,c) FCMP_(1,r1,r2,c)
135 #define FCMP_Q_(r1,r2,c) f47(0xc,r1,r2,0,3,2,0,0,c)
136 #define FCMP_S_LT(r1,r2) FCMP_S_(r1,r2,FCMP_LT)
137 #define FCMP_D_LT(r1,r2) FCMP_D_(r1,r2,FCMP_LT)
138 #define FCMP_Q_LT(r1,r2) FCMP_Q_(r1,r2,FCMP_LT)
139 #define FCMP_S_LE(r1,r2) FCMP_S_(r1,r2,FCMP_LE)
140 #define FCMP_D_LE(r1,r2) FCMP_D_(r1,r2,FCMP_LE)
141 #define FCMP_Q_LE(r1,r2) FCMP_Q_(r1,r2,FCMP_LE)
142 #define FCMP_S_EQ(r1,r2) FCMP_S_(r1,r2,FCMP_EQ)
143 #define FCMP_D_EQ(r1,r2) FCMP_D_(r1,r2,FCMP_EQ)
144 #define FCMP_Q_EQ(r1,r2) FCMP_Q_(r1,r2,FCMP_EQ)
145 #define FCMP_S_GE(r1,r2) FCMP_S_(r1,r2,FCMP_GE)
146 #define FCMP_D_GE(r1,r2) FCMP_D_(r1,r2,FCMP_GE)
147 #define FCMP_Q_GE(r1,r2) FCMP_Q_(r1,r2,FCMP_GE)
148 #define FCMP_S_GT(r1,r2) FCMP_S_(r1,r2,FCMP_GT)
149 #define FCMP_D_GT(r1,r2) FCMP_D_(r1,r2,FCMP_GT)
150 #define FCMP_Q_GT(r1,r2) FCMP_Q_(r1,r2,FCMP_GT)
151 #define FCMP_S_NE(r1,r2) FCMP_S_(r1,r2,FCMP_NE)
152 #define FCMP_D_NE(r1,r2) FCMP_D_(r1,r2,FCMP_NE)
153 #define FCMP_Q_NE(r1,r2) FCMP_Q_(r1,r2,FCMP_NE)
154 #define FCMP_S_UNLT(r1,r2) FCMP_S_(r1,r2,FCMP_UNLT)
155 #define FCMP_D_UNLT(r1,r2) FCMP_D_(r1,r2,FCMP_UNLT)
156 #define FCMP_Q_UNLT(r1,r2) FCMP_Q_(r1,r2,FCMP_UNLT)
157 #define FCMP_S_UNLE(r1,r2) FCMP_S_(r1,r2,FCMP_UNLE)
158 #define FCMP_D_UNLE(r1,r2) FCMP_D_(r1,r2,FCMP_UNLE)
159 #define FCMP_Q_UNLE(r1,r2) FCMP_Q_(r1,r2,FCMP_UNLE)
160 #define FCMP_S_UNEQ(r1,r2) FCMP_S_(r1,r2,FCMP_UNEQ)
161 #define FCMP_D_UNEQ(r1,r2) FCMP_D_(r1,r2,FCMP_UNEQ)
162 #define FCMP_Q_UNEQ(r1,r2) FCMP_Q_(r1,r2,FCMP_UNEQ)
163 #define FCMP_S_UNGE(r1,r2) FCMP_S_(r1,r2,FCMP_UNGE)
164 #define FCMP_D_UNGE(r1,r2) FCMP_D_(r1,r2,FCMP_UNGE)
165 #define FCMP_Q_UNGE(r1,r2) FCMP_Q_(r1,r2,FCMP_UNGE)
166 #define FCMP_S_UNGT(r1,r2) FCMP_S_(r1,r2,FCMP_UNGT)
167 #define FCMP_D_UNGT(r1,r2) FCMP_D_(r1,r2,FCMP_UNGT)
168 #define FCMP_Q_UNGT(r1,r2) FCMP_Q_(r1,r2,FCMP_UNGT)
169 #define FCMP_S_LTGT(r1,r2) FCMP_S_(r1,r2,FCMP_LTGT)
170 #define FCMP_D_LTGT(r1,r2) FCMP_D_(r1,r2,FCMP_LTGT)
171 #define FCMP_Q_LTGT(r1,r2) FCMP_Q_(r1,r2,FCMP_LTGT)
172 #define FCMP_S_ORD(r1,r2) FCMP_S_(r1,r2,FCMP_ORD)
173 #define FCMP_D_ORD(r1,r2) FCMP_D_(r1,r2,FCMP_ORD)
174 #define FCMP_Q_ORD(r1,r2) FCMP_Q_(r1,r2,FCMP_ORD)
175 #define FCMP_S_UNORD(r1,r2) FCMP_S_(r1,r2,FCMP_UNORD)
176 #define FCMP_D_UNORD(r1,r2) FCMP_D_(r1,r2,FCMP_UNORD)
177 #define FCMP_Q_UNORD(r1,r2) FCMP_Q_(r1,r2,FCMP_UNORD)
178 #define XFNVFF(s,d,r,t) f46(0xc,r,0,0,d,s,1,0,0,t)
179 #define FCNVFF_Q_S(r,t) XFNVFF(3,0,r,t)
180 #define FCNVFF_Q_D(r,t) XFNVFF(3,1,r,t)
181 #define FCNVFF_S_Q(r,t) XFNVFF(0,3,r,t)
182 #define FCNVFF_D_Q(r,t) XFNVFF(1,3,r,t)
183 #define FCNVFF_(s,d,r,t) f46(0xc,r,0,0,d,s,1,0,0,t)
184 #define FCNVFF_S_D(r,t) FCNVFF_(0,1,r,t)
185 #define FCNVFF_D_S(r,t) FCNVFF_(1,0,r,t)
186 #define FCNVXF_(s,d,r,t) f46(0xc,r,0,1,d,s,1,0,0,t)
187 #define FCNVXF_S_S(r,t) FCNVXF_(0,0,r,t)
188 #define FCNVXF_S_D(r,t) FCNVXF_(0,1,r,t)
189 #define FCNVXT_(s,d,r,t) f46(0xc,r,0,3,d,s,1,0,0,t)
190 #define FCNVXT_S_S(r,t) FCNVXT_(0,0,r,t)
191 #define FCNVXT_D_S(r,t) FCNVXT_(1,0,r,t)
192 #define FCPY_(f,r,t) f49(0xe,r,0,2,0,f,0,0,0,0,0,t)
193 #define FCPY_S(r,t) FCPY_(0,r,t)
194 #define FCPY_D(r,t) FCPY_(1,r,t)
195 #define FCPY_Q(r,t) f45(0xc,r,0,2,2,0,0,0,t)
196 #define FDIV_(f,r1,r2,t) f52(0xe,r1,r2,3,0,f,3,0,0,0,0,t)
197 #define FDIV_S(r1,r2,t) FDIV_(0,r1,r2,t)
198 #define FDIV_D(r1,r2,t) FDIV_(1,r1,r2,t)
199 #define FDIV_Q(r1,r2,t) f48(0xc,r1,r2,3,3,3,0,0,t)
200 #define FID() f45(0xc,0,0,0,2,0,0,0,0)
201 #define FLDDL(i,b,t) f3(0x14,b,t,i,1)
202 #define FLDD(x,b,t) f39(0xb,b,x,t)
203 #define FLDDI(i,b,t) f41(0xb,b,i,t)
204 #define FLDWL(i,b,t) f43(0x17,b,t,i)
205 #define FLDW(x,b,t) f39(0x9,b,x,t)
206 #define FLDWI(i,b,t) f41(0x9,b,i,t)
207 #define FMPY_(f,r1,r2,t) f52(0xe,r1,r2,2,0,f,3,0,0,0,0,t)
208 #define FMPY_S(r1,r2,t) FMPY_(0,r1,r2,t)
209 #define FMPY_D(r1,r2,t) FMPY_(1,r1,r2,t)
210 #define FMPY_Q(r1,r2,t) f48(0xc,r1,r2,2,3,3,0,0,t)
211 /* FIXME not disassembled */
212 #define FMPYADD_(f,r1,r2,ta,ra,tm) f53(0x6,r1,r2,ta,ra,f,tm)
213 #define FMPYADD_S(r1,r2,ta,ra,tm) FMPYADD_(0,r1,r2,ta,ra,tm)
214 #define FMPYADD_D(r1,r2,ta,ra,tm) FMPYADD_(1,r1,r2,ta,ra,tm)
215 #define FMPYFADD_(f,r1,r2,ra,t) f54(0x2e,r1,r2,ra>>3,0,f,(ra)&7,0,0,0,t)
216 #define FMPYFADD_S(r1,r2,ra,t) FMPYFADD_(0,r1,r2,ra,t)
217 #define FMPYFADD_D(r1,r2,ra,t) FMPYFADD_(1,r1,r2,ra,t)
218 #define FMPYNFADD_(f,r1,r2,ra,t) f54(0x2e,r1,r2,ra>>3,0,f,(ra)&7,0,0,1,t)
219 #define FMPYNFADD_S(r1,r2,ra,t) FMPYNFADD_(0,r1,r2,ra,t)
220 #define FMPYNFADD_D(r1,r2,ra,t) FMPYNFADD_(1,r1,r2,ra,t)
221 #define FMPYSUB_(f,r1,r2,ta,ra,tm) f53(0x26,r1,r2,ta,ra,f,tm)
222 #define FMPYSUB_S(r1,r2,ta,ra,tm) FMPYSUB_(0,r1,r2,ta,ra,tm)
223 #define FMPYSUB_D(r1,r2,ta,ra,tm) FMPYSUB_(1,r1,r2,ta,ra,tm)
224 #define FNEG_(f,r,t) f49(0xe,r,0,6,0,f,0,0,0,0,0,t)
225 #define FNEG_S(r,t) FNEG_(0,r,t)
226 #define FNEG_D(r,t) FNEG_(1,r,t)
227 /* FIXME not disassembled */
228 #define FNEG_Q(r,t) f45(0xc,r,0,6,3,0,0,0,t)
229 #define FNEGABS_(f,r,t) f49(0xe,r,0,7,0,f,0,0,0,0,0,t)
230 #define FNEGABS_S(r,t) FNEGABS_(0,r,t)
231 #define FNEGABS_D(r,t) FNEGABS_(1,r,t)
232 #define FNEGABS_Q(r,t) f45(0xc,r,0,7,3,0,0,0,t)
233 #define FRND_(f,r,t) f49(0xe,r,0,5,0,f,0,0,0,0,0,t)
234 #define FRND_S(r,t) FRND_(0,r,t)
235 #define FRND_D(r,t) FRND_(1,r,t)
236 #define FRND_Q(r,t) f45(0xc,r,0,5,3,0,0,0,t)
237 #define FSQRT_(f,r,t) f49(0xe,r,0,4,0,f,0,0,0,0,0,t)
238 #define FSQRT_S(r,t) FSQRT_(0,r,t)
239 #define FSQRT_D(r,t) FSQRT_(1,r,t)
240 #define FSQRT_Q(r,t) f45(0xc,r,0,4,3,0,0,0,t)
241 #define FSTDL(r,i,b) f3(0x1c,b,r,i,1)
242 #define FSTD(r,x,b) f40(0xb,b,x,r)
243 #define FSTDI(r,i,b) f42(0xb,b,i,r)
244 #define FSTWL(r,i,b) f43(0x1f,b,r,i)
245 #define FSTW(r,x,b) f40(0x9,b,x,r)
246 #define FSTWI(r,i,b) f42(0x9,b,i,r)
247 #define FSUB_(f,r1,r2,t) f52(0xe,r1,r2,1,0,f,3,0,0,0,0,t)
248 #define FSUB_S(r1,r2,t) FSUB_(0,r1,r2,t)
249 #define FSUB_D(r1,r2,t) FSUB_(1,r1,r2,t)
250 #define FSUB_Q(r1,r2,t) f48(0xc,r1,r2,1,3,3,0,0,t)
251 #define FTEST_(c) f47(0xc,0,0,0,0,2,0,1,c)
252 #define FTEST() f47(0xc,0,0,1,0,2,0,1,0)
253 #define FTEST_LT() FTEST_(FCMP_LT)
254 #define FTEST_LE() FTEST_(FCMP_LE)
255 #define FTEST_EQ() FTEST_(FCMP_EQ)
256 #define FTEST_GE() FTEST_(FCMP_GE)
257 #define FTEST_GT() FTEST_(FCMP_GT)
258 #define FTEST_NE() FTEST_(FCMP_NE)
259 #define FTEST_UNLT() FTEST_(FCMP_UNLT)
260 #define FTEST_UNLE() FTEST_(FCMP_UNLE)
261 #define FTEST_UNEQ() FTEST_(FCMP_UNEQ)
262 #define FTEST_UNGE() FTEST_(FCMP_UNGE)
263 #define FTEST_UNGT() FTEST_(FCMP_UNGT)
264 #define FTEST_LTGT() FTEST_(FCMP_LTGT)
265 #define FTEST_ORD() FTEST_(FCMP_ORD)
266 #define FTEST_UNORD() FTEST_(FCMP_UNORD)
267 #define XMPYU(r1,r2,t) f52(0xe,r1,r2,2,0,0,3,1,0,0,0,t)
268 #define XMPYU_L_R(r1,r2,t) f52(0xe,r1,r2,2,1,0,3,1,0,0,0,t)
269 #define XMPYU_R_L(r1,r2,t) f52(0xe,r1,r2,2,0,0,3,1,1,0,0,t)
270 #define XMPYU_R_R(r1,r2,t) f52(0xe,r1,r2,2,1,0,3,1,1,0,0,t)
271 #define negr_f(r0,r1) FNEG_S(r1,r0)
272 #define negr_d(r0,r1) FNEG_D(r1,r0)
273 #define sqrtr_f(r0,r1) FSQRT_S(r1,r0)
274 #define sqrtr_d(r0,r1) FSQRT_D(r1,r0)
275 #define extr_f(r0,r1) _extr_f(_jit,r0,r1)
276 static void _extr_f(jit_state_t*,jit_int32_t,jit_int32_t);
277 #define extr_d(r0,r1) _extr_d(_jit,r0,r1)
278 static void _extr_d(jit_state_t*,jit_int32_t,jit_int32_t);
279 #define extr_f_d(r0,r1) FCNVFF_S_D(r1,r0)
280 #define extr_d_f(r0,r1) FCNVFF_D_S(r1,r0)
281 #define truncr_f(r0,r1) truncr_f_i(r0,r1)
282 #define truncr_f_i(r0,r1) _truncr_f_i(_jit,r0,r1)
283 static void _truncr_f_i(jit_state_t*,jit_int32_t,jit_int32_t);
284 #define truncr_d(r0,r1) truncr_d_i(r0,r1)
285 #define truncr_d_i(r0,r1) _truncr_d_i(_jit,r0,r1)
286 static void _truncr_d_i(jit_state_t*,jit_int32_t,jit_int32_t);
287 #define movr_f(r0,r1) FCPY_S(r1,r0)
288 #define movi_f(r0,i0) _movi_f(_jit,r0,i0)
289 static void _movi_f(jit_state_t*,jit_int32_t,jit_float32_t*);
290 #define movr_d(r0,r1) FCPY_D(r1,r0)
291 #define movi_d(r0,i0) _movi_d(_jit,r0,i0)
292 static void _movi_d(jit_state_t*,jit_int32_t,jit_float64_t*);
293 #define absr_f(r0,r1) FABS_S(r1,r0)
294 #define absr_d(r0,r1) FABS_D(r1,r0)
295 #define addr_f(r0,r1,r2) FADD_S(r1,r2,r0)
296 #define addi_f(r0,r1,i0) _addi_f(_jit,r0,r1,i0)
297 static void _addi_f(jit_state_t*,jit_int32_t,jit_int32_t,jit_float32_t*);
298 #define addr_d(r0,r1,r2) FADD_D(r1,r2,r0)
299 #define addi_d(r0,r1,i0) _addi_d(_jit,r0,r1,i0)
300 static void _addi_d(jit_state_t*,jit_int32_t,jit_int32_t,jit_float64_t*);
301 #define subr_f(r0,r1,r2) FSUB_S(r1,r2,r0)
302 #define subi_f(r0,r1,i0) _subi_f(_jit,r0,r1,i0)
303 static void _subi_f(jit_state_t*,jit_int32_t,jit_int32_t,jit_float32_t*);
304 #define subr_d(r0,r1,r2) FSUB_D(r1,r2,r0)
305 #define subi_d(r0,r1,i0) _subi_d(_jit,r0,r1,i0)
306 static void _subi_d(jit_state_t*,jit_int32_t,jit_int32_t,jit_float64_t*);
307 #define rsbr_f(r0,r1,r2) subr_f(r0,r2,r1)
308 #define rsbi_f(r0,r1,i0) _rsbi_f(_jit,r0,r1,i0)
309 static void _rsbi_f(jit_state_t*,jit_int32_t,jit_int32_t,jit_float32_t*);
310 #define rsbr_d(r0,r1,r2) subr_d(r0,r2,r1)
311 #define rsbi_d(r0,r1,i0) _rsbi_d(_jit,r0,r1,i0)
312 static void _rsbi_d(jit_state_t*,jit_int32_t,jit_int32_t,jit_float64_t*);
313 #define mulr_f(r0,r1,r2) FMPY_S(r1,r2,r0)
314 #define muli_f(r0,r1,i0) _muli_f(_jit,r0,r1,i0)
315 static void _muli_f(jit_state_t*,jit_int32_t,jit_int32_t,jit_float32_t*);
316 #define mulr_d(r0,r1,r2) FMPY_D(r1,r2,r0)
317 #define muli_d(r0,r1,i0) _muli_d(_jit,r0,r1,i0)
318 static void _muli_d(jit_state_t*,jit_int32_t,jit_int32_t,jit_float64_t*);
319 #define divr_f(r0,r1,r2) FDIV_S(r1,r2,r0)
320 #define divi_f(r0,r1,i0) _divi_f(_jit,r0,r1,i0)
321 static void _divi_f(jit_state_t*,jit_int32_t,jit_int32_t,jit_float32_t*);
322 #define divr_d(r0,r1,r2) FDIV_D(r1,r2,r0)
323 #define divi_d(r0,r1,i0) _divi_d(_jit,r0,r1,i0)
324 static void _divi_d(jit_state_t*,jit_int32_t,jit_int32_t,jit_float64_t*);
325 #define cmpr_f(c,r0,r1,r2) _cmpr_f(_jit,c,r0,r1,r2)
326 static void _cmpr_f(jit_state_t*,jit_word_t,
327 jit_int32_t,jit_int32_t,jit_int32_t);
328 #define cmpi_f(c,r0,r1,i0) _cmpi_f(_jit,c,r0,r1,i0)
329 static void _cmpi_f(jit_state_t*,jit_word_t,
330 jit_int32_t,jit_int32_t,jit_float32_t*);
331 #define cmpr_d(c,r0,r1,r2) _cmpr_d(_jit,c,r0,r1,r2)
332 static void _cmpr_d(jit_state_t*,jit_word_t,
333 jit_int32_t,jit_int32_t,jit_int32_t);
334 #define cmpi_d(c,r0,r1,i0) _cmpi_d(_jit,c,r0,r1,i0)
335 static void _cmpi_d(jit_state_t*,jit_word_t,
336 jit_int32_t,jit_int32_t,jit_float64_t*);
337 #define ltr_f(r0,r1,r2) cmpr_f(FCMP_LT,r0,r1,r2)
338 #define lti_f(r0,r1,i0) cmpi_f(FCMP_LT,r0,r1,i0)
339 #define ltr_d(r0,r1,r2) cmpr_d(FCMP_LT,r0,r1,r2)
340 #define lti_d(r0,r1,i0) cmpi_d(FCMP_LT,r0,r1,i0)
341 #define ler_f(r0,r1,r2) cmpr_f(FCMP_LE,r0,r1,r2)
342 #define lei_f(r0,r1,i0) cmpi_f(FCMP_LE,r0,r1,i0)
343 #define ler_d(r0,r1,r2) cmpr_d(FCMP_LE,r0,r1,r2)
344 #define lei_d(r0,r1,i0) cmpi_d(FCMP_LE,r0,r1,i0)
345 #define eqr_f(r0,r1,r2) cmpr_f(FCMP_EQ,r0,r1,r2)
346 #define eqi_f(r0,r1,i0) cmpi_f(FCMP_EQ,r0,r1,i0)
347 #define eqr_d(r0,r1,r2) cmpr_d(FCMP_EQ,r0,r1,r2)
348 #define eqi_d(r0,r1,i0) cmpi_d(FCMP_EQ,r0,r1,i0)
349 #define ger_f(r0,r1,r2) cmpr_f(FCMP_GE,r0,r1,r2)
350 #define gei_f(r0,r1,i0) cmpi_f(FCMP_GE,r0,r1,i0)
351 #define ger_d(r0,r1,r2) cmpr_d(FCMP_GE,r0,r1,r2)
352 #define gei_d(r0,r1,i0) cmpi_d(FCMP_GE,r0,r1,i0)
353 #define gtr_f(r0,r1,r2) cmpr_f(FCMP_GT,r0,r1,r2)
354 #define gti_f(r0,r1,i0) cmpi_f(FCMP_GT,r0,r1,i0)
355 #define gtr_d(r0,r1,r2) cmpr_d(FCMP_GT,r0,r1,r2)
356 #define gti_d(r0,r1,i0) cmpi_d(FCMP_GT,r0,r1,i0)
357 #define ner_f(r0,r1,r2) cmpr_f(FCMP_NE,r0,r1,r2)
358 #define nei_f(r0,r1,i0) cmpi_f(FCMP_NE,r0,r1,i0)
359 #define ner_d(r0,r1,r2) cmpr_d(FCMP_NE,r0,r1,r2)
360 #define nei_d(r0,r1,i0) cmpi_d(FCMP_NE,r0,r1,i0)
361 #define unltr_f(r0,r1,r2) cmpr_f(FCMP_UNLT,r0,r1,r2)
362 #define unlti_f(r0,r1,i0) cmpi_f(FCMP_UNLT,r0,r1,i0)
363 #define unltr_d(r0,r1,r2) cmpr_d(FCMP_UNLT,r0,r1,r2)
364 #define unlti_d(r0,r1,i0) cmpi_d(FCMP_UNLT,r0,r1,i0)
365 #define unler_f(r0,r1,r2) cmpr_f(FCMP_UNLE,r0,r1,r2)
366 #define unlei_f(r0,r1,i0) cmpi_f(FCMP_UNLE,r0,r1,i0)
367 #define unler_d(r0,r1,r2) cmpr_d(FCMP_UNLE,r0,r1,r2)
368 #define unlei_d(r0,r1,i0) cmpi_d(FCMP_UNLE,r0,r1,i0)
369 #define uneqr_f(r0,r1,r2) cmpr_f(FCMP_UNEQ,r0,r1,r2)
370 #define uneqi_f(r0,r1,i0) cmpi_f(FCMP_UNEQ,r0,r1,i0)
371 #define uneqr_d(r0,r1,r2) cmpr_d(FCMP_UNEQ,r0,r1,r2)
372 #define uneqi_d(r0,r1,i0) cmpi_d(FCMP_UNEQ,r0,r1,i0)
373 #define unger_f(r0,r1,r2) cmpr_f(FCMP_UNGE,r0,r1,r2)
374 #define ungei_f(r0,r1,i0) cmpi_f(FCMP_UNGE,r0,r1,i0)
375 #define unger_d(r0,r1,r2) cmpr_d(FCMP_UNGE,r0,r1,r2)
376 #define ungei_d(r0,r1,i0) cmpi_d(FCMP_UNGE,r0,r1,i0)
377 #define ungtr_f(r0,r1,r2) cmpr_f(FCMP_UNGT,r0,r1,r2)
378 #define ungti_f(r0,r1,i0) cmpi_f(FCMP_UNGT,r0,r1,i0)
379 #define ungtr_d(r0,r1,r2) cmpr_d(FCMP_UNGT,r0,r1,r2)
380 #define ungti_d(r0,r1,i0) cmpi_d(FCMP_UNGT,r0,r1,i0)
381 #define ltgtr_f(r0,r1,r2) cmpr_f(FCMP_LTGT,r0,r1,r2)
382 #define ltgti_f(r0,r1,i0) cmpi_f(FCMP_LTGT,r0,r1,i0)
383 #define ltgtr_d(r0,r1,r2) cmpr_d(FCMP_LTGT,r0,r1,r2)
384 #define ltgti_d(r0,r1,i0) cmpi_d(FCMP_LTGT,r0,r1,i0)
385 #define ordr_f(r0,r1,r2) cmpr_f(FCMP_ORD,r0,r1,r2)
386 #define ordi_f(r0,r1,i0) cmpi_f(FCMP_ORD,r0,r1,i0)
387 #define ordr_d(r0,r1,r2) cmpr_d(FCMP_ORD,r0,r1,r2)
388 #define ordi_d(r0,r1,i0) cmpi_d(FCMP_ORD,r0,r1,i0)
389 #define unordr_f(r0,r1,r2) cmpr_f(FCMP_UNORD,r0,r1,r2)
390 #define unordi_f(r0,r1,i0) cmpi_f(FCMP_UNORD,r0,r1,i0)
391 #define unordr_d(r0,r1,r2) cmpr_d(FCMP_UNORD,r0,r1,r2)
392 #define unordi_d(r0,r1,i0) cmpi_d(FCMP_UNORD,r0,r1,i0)
393 #define ldr_f(r0,r1) FLDWI(0,r1,r0)
394 #define ldi_f(r0,i0) _ldi_f(_jit,r0,i0)
395 static void _ldi_f(jit_state_t*,jit_int32_t,jit_word_t);
396 #if FLDXR
397 # define ldxr_f(r0,r1,r2) FLDW(r2,r1,r0)
398 # define ldxr_d(r0,r1,r2) FLDD(r2,r1,r0)
399 #else
400 #define ldxr_f(r0,r1,r2) _ldxr_f(_jit,r0,r1,r2)
401 static void _ldxr_f(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t);
402 #define ldxr_d(r0,r1,r2) _ldxr_d(_jit,r0,r1,r2)
403 static void _ldxr_d(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t);
404 #endif
405 #define ldxi_f(r0,r1,i0) _ldxi_f(_jit,r0,r1,i0)
406 static void _ldxi_f(jit_state_t*,jit_int32_t,jit_int32_t,jit_word_t);
407 #define ldr_d(r0,r1) FLDDI(0,r1,r0)
408 #define ldi_d(r0,i0) _ldi_d(_jit,r0,i0)
409 static void _ldi_d(jit_state_t*,jit_int32_t,jit_word_t);
410 #define ldxi_d(r0,r1,i0) _ldxi_d(_jit,r0,r1,i0)
411 static void _ldxi_d(jit_state_t*,jit_int32_t,jit_int32_t,jit_word_t);
412 #define str_f(r0,r1) FSTWI(r1,0,r0)
413 #define sti_f(i0,r0) _sti_f(_jit,i0,r0)
414 static void _sti_f(jit_state_t*,jit_word_t,jit_int32_t);
415 #if FSTXR
416 # define stxr_f(r0,r1,r2) FSTW(r2,r1,r0)
417 # define stxr_d(r0,r1,r2) FSTD(r2,r1,r0)
418 #else
419 # define stxr_f(r0,r1,r2) _stxr_f(_jit,r0,r1,r2)
420 static void _stxr_f(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t);
421 # define stxr_d(r0,r1,r2) _stxr_d(_jit,r0,r1,r2)
422 static void _stxr_d(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t);
423 #endif
424 #define stxi_f(i0,r0,r1) _stxi_f(_jit,i0,r0,r1)
425 static void _stxi_f(jit_state_t*,jit_word_t,jit_int32_t,jit_int32_t);
426 #define str_d(r0,r1) FSTDI(r1,0,r0)
427 #define sti_d(i0,r0) _sti_d(_jit,i0,r0)
428 static void _sti_d(jit_state_t*,jit_word_t,jit_int32_t);
429 #define stxi_d(i0,r0,r1) _stxi_d(_jit,i0,r0,r1)
430 static void _stxi_d(jit_state_t*,jit_word_t,jit_int32_t,jit_int32_t);
431 #define bcmpr_f(c,i0,r0,r1) _bcmpr_f(_jit,c,i0,r0,r1)
432 static jit_word_t _bcmpr_f(jit_state_t*,jit_word_t,
433 jit_word_t,jit_int32_t,jit_int32_t);
434 #define bcmpi_f(c,i0,r0,i1) _bcmpi_f(_jit,c,i0,r0,i1)
435 static jit_word_t _bcmpi_f(jit_state_t*,jit_word_t,
436 jit_word_t,jit_int32_t,jit_float32_t*);
437 #define bcmpr_d(c,i0,r0,r1) _bcmpr_d(_jit,c,i0,r0,r1)
438 static jit_word_t _bcmpr_d(jit_state_t*,jit_word_t,
439 jit_word_t,jit_int32_t,jit_int32_t);
440 #define bcmpi_d(c,i0,r0,i1) _bcmpi_d(_jit,c,i0,r0,i1)
441 static jit_word_t _bcmpi_d(jit_state_t*,jit_word_t,
442 jit_word_t,jit_int32_t,jit_float64_t*);
443 #define bltr_f(i0,r0,r1) bcmpr_f(FCMP_LT,i0,r0,r1)
444 #define blti_f(i0,r0,i1) bcmpi_f(FCMP_LT,i0,r0,i1)
445 #define bltr_d(i0,r0,r1) bcmpr_d(FCMP_LT,i0,r0,r1)
446 #define blti_d(i0,r0,i1) bcmpi_d(FCMP_LT,i0,r0,i1)
447 #define bler_f(i0,r0,r1) bcmpr_f(FCMP_LE,i0,r0,r1)
448 #define blei_f(i0,r0,i1) bcmpi_f(FCMP_LE,i0,r0,i1)
449 #define bler_d(i0,r0,r1) bcmpr_d(FCMP_LE,i0,r0,r1)
450 #define blei_d(i0,r0,i1) bcmpi_d(FCMP_LE,i0,r0,i1)
451 #define beqr_f(i0,r0,r1) bcmpr_f(FCMP_EQ,i0,r0,r1)
452 #define beqi_f(i0,r0,i1) bcmpi_f(FCMP_EQ,i0,r0,i1)
453 #define beqr_d(i0,r0,r1) bcmpr_d(FCMP_EQ,i0,r0,r1)
454 #define beqi_d(i0,r0,i1) bcmpi_d(FCMP_EQ,i0,r0,i1)
455 #define bger_f(i0,r0,r1) bcmpr_f(FCMP_GE,i0,r0,r1)
456 #define bgei_f(i0,r0,i1) bcmpi_f(FCMP_GE,i0,r0,i1)
457 #define bger_d(i0,r0,r1) bcmpr_d(FCMP_GE,i0,r0,r1)
458 #define bgei_d(i0,r0,i1) bcmpi_d(FCMP_GE,i0,r0,i1)
459 #define bgtr_f(i0,r0,r1) bcmpr_f(FCMP_GT,i0,r0,r1)
460 #define bgti_f(i0,r0,i1) bcmpi_f(FCMP_GT,i0,r0,i1)
461 #define bgtr_d(i0,r0,r1) bcmpr_d(FCMP_GT,i0,r0,r1)
462 #define bgti_d(i0,r0,i1) bcmpi_d(FCMP_GT,i0,r0,i1)
463 #define bner_f(i0,r0,r1) bcmpr_f(FCMP_NE,i0,r0,r1)
464 #define bnei_f(i0,r0,i1) bcmpi_f(FCMP_NE,i0,r0,i1)
465 #define bner_d(i0,r0,r1) bcmpr_d(FCMP_NE,i0,r0,r1)
466 #define bnei_d(i0,r0,i1) bcmpi_d(FCMP_NE,i0,r0,i1)
467 #define bunltr_f(i0,r0,r1) bcmpr_f(FCMP_UNLT,i0,r0,r1)
468 #define bunlti_f(i0,r0,i1) bcmpi_f(FCMP_UNLT,i0,r0,i1)
469 #define bunltr_d(i0,r0,r1) bcmpr_d(FCMP_UNLT,i0,r0,r1)
470 #define bunlti_d(i0,r0,i1) bcmpi_d(FCMP_UNLT,i0,r0,i1)
471 #define bunler_f(i0,r0,r1) bcmpr_f(FCMP_UNLE,i0,r0,r1)
472 #define bunlei_f(i0,r0,i1) bcmpi_f(FCMP_UNLE,i0,r0,i1)
473 #define bunler_d(i0,r0,r1) bcmpr_d(FCMP_UNLE,i0,r0,r1)
474 #define bunlei_d(i0,r0,i1) bcmpi_d(FCMP_UNLE,i0,r0,i1)
475 #define buneqr_f(i0,r0,r1) bcmpr_f(FCMP_UNEQ,i0,r0,r1)
476 #define buneqi_f(i0,r0,i1) bcmpi_f(FCMP_UNEQ,i0,r0,i1)
477 #define buneqr_d(i0,r0,r1) bcmpr_d(FCMP_UNEQ,i0,r0,r1)
478 #define buneqi_d(i0,r0,i1) bcmpi_d(FCMP_UNEQ,i0,r0,i1)
479 #define bunger_f(i0,r0,r1) bcmpr_f(FCMP_UNGE,i0,r0,r1)
480 #define bungei_f(i0,r0,i1) bcmpi_f(FCMP_UNGE,i0,r0,i1)
481 #define bunger_d(i0,r0,r1) bcmpr_d(FCMP_UNGE,i0,r0,r1)
482 #define bungei_d(i0,r0,i1) bcmpi_d(FCMP_UNGE,i0,r0,i1)
483 #define bungtr_f(i0,r0,r1) bcmpr_f(FCMP_UNGT,i0,r0,r1)
484 #define bungti_f(i0,r0,i1) bcmpi_f(FCMP_UNGT,i0,r0,i1)
485 #define bungtr_d(i0,r0,r1) bcmpr_d(FCMP_UNGT,i0,r0,r1)
486 #define bungti_d(i0,r0,i1) bcmpi_d(FCMP_UNGT,i0,r0,i1)
487 #define bltgtr_f(i0,r0,r1) bcmpr_f(FCMP_LTGT,i0,r0,r1)
488 #define bltgti_f(i0,r0,i1) bcmpi_f(FCMP_LTGT,i0,r0,i1)
489 #define bltgtr_d(i0,r0,r1) bcmpr_d(FCMP_LTGT,i0,r0,r1)
490 #define bltgti_d(i0,r0,i1) bcmpi_d(FCMP_LTGT,i0,r0,i1)
491 #define bordr_f(i0,r0,r1) bcmpr_f(FCMP_ORD,i0,r0,r1)
492 #define bordi_f(i0,r0,i1) bcmpi_f(FCMP_ORD,i0,r0,i1)
493 #define bordr_d(i0,r0,r1) bcmpr_d(FCMP_ORD,i0,r0,r1)
494 #define bordi_d(i0,r0,i1) bcmpi_d(FCMP_ORD,i0,r0,i1)
495 #define bunordr_f(i0,r0,r1) bcmpr_f(FCMP_UNORD,i0,r0,r1)
496 #define bunordi_f(i0,r0,i1) bcmpi_f(FCMP_UNORD,i0,r0,i1)
497 #define bunordr_d(i0,r0,r1) bcmpr_d(FCMP_UNORD,i0,r0,r1)
498 #define bunordi_d(i0,r0,i1) bcmpi_d(FCMP_UNORD,i0,r0,i1)
499 #define vaarg_d(r0, r1) _vaarg_d(_jit, r0, r1)
500 static void _vaarg_d(jit_state_t*, jit_int32_t, jit_int32_t);
501 #endif
502
503 #if CODE
504 static void
_f39(jit_state_t * _jit,jit_int32_t o,jit_int32_t b,jit_int32_t x,jit_int32_t t)505 _f39(jit_state_t *_jit, jit_int32_t o,
506 jit_int32_t b, jit_int32_t x, jit_int32_t t)
507 {
508 assert(!(o & ~0x3f));
509 assert(!(b & ~0x1f));
510 assert(!(x & ~0x1f));
511 assert(!(t & ~0x1f));
512 ii((o<<26)|(b<<21)|(x<<16)|t);
513 }
514
515 static void
_f40(jit_state_t * _jit,jit_int32_t o,jit_int32_t b,jit_int32_t x,jit_int32_t r)516 _f40(jit_state_t *_jit, jit_int32_t o,
517 jit_int32_t b, jit_int32_t x, jit_int32_t r)
518 {
519 assert(!(o & ~0x3f));
520 assert(!(b & ~0x1f));
521 assert(!(x & ~0x1f));
522 assert(!(r & ~0x1f));
523 ii((o<<26)|(b<<21)|(x<<16)|(1<<9)|r);
524 }
525
526 static void
_f41(jit_state_t * _jit,jit_int32_t o,jit_int32_t b,jit_int32_t x,jit_int32_t t)527 _f41(jit_state_t *_jit, jit_int32_t o,
528 jit_int32_t b, jit_int32_t x, jit_int32_t t)
529 {
530 assert(!(o & ~0x3f));
531 assert(!(b & ~0x1f));
532 assert(x >= -16 && x < 15);
533 assert(!(t & ~0x1f));
534 ii((o<<26)|(b<<21)|(low_sign_unext(x,5)<<16)|(1<<12)|t);
535 }
536
537 static void
_f42(jit_state_t * _jit,jit_int32_t o,jit_int32_t b,jit_int32_t i,jit_int32_t r)538 _f42(jit_state_t *_jit, jit_int32_t o,
539 jit_int32_t b, jit_int32_t i, jit_int32_t r)
540 {
541 assert(!(o & ~0x3f));
542 assert(!(b & ~0x1f));
543 assert(i >= -16 && i < 15);
544 assert(!(r & ~0x1f));
545 ii((o<<26)|(b<<21)|(low_sign_unext(i,5)<<16)|(1<<12)|(1<<9)|r);
546 }
547
548 static void
_f45(jit_state_t * _jit,jit_int32_t o,jit_int32_t r,jit_int32_t a,jit_int32_t b,jit_int32_t fmt,jit_int32_t c,jit_int32_t d,jit_int32_t e,jit_int32_t t)549 _f45(jit_state_t *_jit, jit_int32_t o,
550 jit_int32_t r, jit_int32_t a, jit_int32_t b, jit_int32_t fmt,
551 jit_int32_t c, jit_int32_t d, jit_int32_t e, jit_int32_t t)
552 {
553 assert(!(o & ~0x3f));
554 assert(!(r & ~0x1f));
555 assert(!(a & ~0x1f));
556 assert(!(b & ~0x7));
557 assert(!(fmt & ~0x3));
558 assert(!(c & ~0x3));
559 assert(!(d & ~0x7));
560 assert(!(e & ~0x1));
561 assert(!(t & ~0x1f));
562 ii((o<<26)|(r<<21)|(a<<16)|(fmt<<13)|(b<<11)|(c<<9)|(d<<6)|(e<<5)|t);
563 }
564
565 static void
_f46(jit_state_t * _jit,jit_int32_t o,jit_int32_t r,jit_int32_t a,jit_int32_t s,jit_int32_t df,jit_int32_t sf,jit_int32_t b,jit_int32_t c,jit_int32_t d,jit_int32_t t)566 _f46(jit_state_t *_jit, jit_int32_t o, jit_int32_t r,
567 jit_int32_t a, jit_int32_t s, jit_int32_t df, jit_int32_t sf,
568 jit_int32_t b, jit_int32_t c, jit_int32_t d, jit_int32_t t)
569 {
570 assert(!(o & ~0x3f));
571 assert(!(r & ~0x1f));
572 assert(!(a & ~0x7));
573 assert(!(s & ~0x7));
574 assert(!(df & ~0x3));
575 assert(!(sf & ~0x3));
576 assert(!(b & ~0x3));
577 assert(!(c & ~0x7));
578 assert(!(d & ~0x1));
579 assert(!(t & ~0x1f));
580 ii((o<<26)|(r<<21)|(a<<18)|(s<<15)|
581 (df<<13)|(sf<<11)|(b<<9)|(c<<6)|(d<<5)|t);
582 }
583
584 static void
_f47_48(jit_state_t * _jit,jit_int32_t o,jit_int32_t r2,jit_int32_t r1,jit_int32_t y,jit_int32_t fmt,jit_int32_t a,jit_int32_t b,jit_int32_t c,jit_int32_t t)585 _f47_48(jit_state_t *_jit, jit_int32_t o,
586 jit_int32_t r2, jit_int32_t r1, jit_int32_t y, jit_int32_t fmt,
587 jit_int32_t a, jit_int32_t b, jit_int32_t c, jit_int32_t t)
588 {
589 assert(!(o & ~0x3f));
590 assert(!(r2 & ~0x1f));
591 assert(!(r1 & ~0x1f));
592 assert(!(y & ~0x7));
593 assert(!(fmt & ~0x3));
594 assert(!(a & ~0x3));
595 assert(!(b & ~0x7));
596 assert(!(c & ~0x1));
597 assert(!(t & ~0x1f));
598 ii((o<<26)|(r2<<21)|(r1<<16)|(y<<13)|(fmt<<11)|(a<<9)|(b<<6)|(c<<5)|t);
599 }
600
601 static void
_f49_52(jit_state_t * _jit,jit_int32_t o,jit_int32_t r1,jit_int32_t r2,jit_int32_t y,jit_int32_t v,jit_int32_t f,jit_int32_t a,jit_int32_t b,jit_int32_t u,jit_int32_t c,jit_int32_t d,jit_int32_t t)602 _f49_52(jit_state_t *_jit, jit_int32_t o,
603 jit_int32_t r1, jit_int32_t r2, jit_int32_t y,
604 jit_int32_t v, jit_int32_t f, jit_int32_t a, jit_int32_t b,
605 jit_int32_t u, jit_int32_t c, jit_int32_t d, jit_int32_t t)
606 {
607 assert(!(o & ~0x3f));
608 assert(!(r1 & ~0x1f));
609 assert(!(r2 & ~0x3f));
610 assert(!(y & ~0x7));
611 assert(!(v & ~0x1));
612 assert(!(f & ~0x1));
613 assert(!(a & ~0x3));
614 assert(!(b & ~0x1));
615 assert(!(u & ~0x1));
616 assert(!(c & ~0x1));
617 assert(!(d & ~0x1));
618 assert(!(t & ~0x1f));
619 ii((o<<26)|(r1<<21)|(r2<<16)|(y<<13)|(v<<12)|
620 (f<<11)|(a<<9)|(b<<8)|(u<<7)|(c<<6)|(d<<5)|t);
621 }
622
623 static void
_f53(jit_state_t * _jit,jit_int32_t o,jit_int32_t r1,jit_int32_t r2,jit_int32_t ta,jit_int32_t ra,jit_int32_t f,jit_int32_t tm)624 _f53(jit_state_t *_jit, jit_int32_t o, jit_int32_t r1, jit_int32_t r2,
625 jit_int32_t ta, jit_int32_t ra, jit_int32_t f, jit_int32_t tm)
626 {
627 assert(!(o & ~0x3f));
628 assert(!(r1 & ~0x1f));
629 assert(!(r2 & ~0x1f));
630 assert(!(ta & ~0x1f));
631 assert(!(ra & ~0x1f));
632 assert(!(f & ~0x1));
633 assert(!(tm & ~0x1f));
634 assert(ra != tm ||
635 (ta == r1 || ta == r2 || ta == tm) ||
636 (f && ra == 1) || (!f && !ra));
637 ii((o<<26)|(r1<<21)|(r2<<16)|(ta<<11)|(ra<<6)|(f<<5)|tm);
638 }
639
640 static void
_f54(jit_state_t * _jit,jit_int32_t o,jit_int32_t r1,jit_int32_t r2,jit_int32_t a,jit_int32_t b,jit_int32_t f,jit_int32_t c,jit_int32_t d,jit_int32_t e,jit_int32_t g,jit_int32_t t)641 _f54(jit_state_t *_jit, jit_int32_t o, jit_int32_t r1, jit_int32_t r2,
642 jit_int32_t a, jit_int32_t b, jit_int32_t f, jit_int32_t c,
643 jit_int32_t d, jit_int32_t e, jit_int32_t g, jit_int32_t t)
644 {
645 assert(!(o & ~0x3f));
646 assert(!(r1 & ~0x1f));
647 assert(!(r2 & ~0x1f));
648 assert(!(a & ~0x7));
649 assert(!(b & ~0x1));
650 assert(!(f & ~0x1));
651 assert(!(c & ~0x7));
652 assert(!(e & ~0x1));
653 assert(!(e & ~0x1));
654 assert(!(g & ~0x1));
655 assert(!(t & ~0x1f));
656 ii((o<<26)|(r1<<21)|(r2<<16)|(a<<13)|
657 (b<<12)|(f<11)|(c<<8)|(d<<7)|(e<<6)|(g<<5)|t);
658 }
659
660 static void
_extr_f(jit_state_t * _jit,jit_int32_t r0,jit_int32_t r1)661 _extr_f(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
662 {
663 stxi(alloca_offset - 8, _FP_REGNO, r1);
664 ldxi_f(r0, _FP_REGNO, alloca_offset - 8);
665 FCNVXF_S_S(r0, r0);
666 }
667
668 static void
_extr_d(jit_state_t * _jit,jit_int32_t r0,jit_int32_t r1)669 _extr_d(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
670 {
671 stxi(alloca_offset - 8, _FP_REGNO, r1);
672 ldxi_f(r0, _FP_REGNO, alloca_offset - 8);
673 FCNVXF_S_D(r0, r0);
674 }
675
676 static void
_truncr_f_i(jit_state_t * _jit,jit_int32_t r0,jit_int32_t r1)677 _truncr_f_i(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
678 {
679 jit_int32_t reg;
680 reg = jit_get_reg(jit_class_fpr);
681 FCNVXT_S_S(r1, rn(reg));
682 stxi_f(alloca_offset - 8, _FP_REGNO, rn(reg));
683 ldxi(r0, _FP_REGNO, alloca_offset - 8);
684 jit_unget_reg(reg);
685 }
686
687 static void
_truncr_d_i(jit_state_t * _jit,jit_int32_t r0,jit_int32_t r1)688 _truncr_d_i(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
689 {
690 jit_int32_t reg;
691 reg = jit_get_reg(jit_class_fpr);
692 FCNVXT_D_S(r1, rn(reg));
693 stxi_d(alloca_offset - 8, _FP_REGNO, rn(reg));
694 ldxi(r0, _FP_REGNO, alloca_offset - 8);
695 jit_unget_reg(reg);
696 }
697
698 static void
_movi_f(jit_state_t * _jit,jit_int32_t r0,jit_float32_t * i0)699 _movi_f(jit_state_t *_jit, jit_int32_t r0, jit_float32_t *i0)
700 {
701 union {
702 jit_int32_t i;
703 jit_float32_t f;
704 } data;
705 jit_int32_t reg;
706
707 if (_jitc->no_data) {
708 data.f = *i0;
709 reg = jit_get_reg(jit_class_gpr);
710 movi(rn(reg), data.i);
711 stxi_i(alloca_offset - 8, _FP_REGNO, rn(reg));
712 jit_unget_reg(reg);
713 ldxi_f(r0, _FP_REGNO, alloca_offset - 8);
714 }
715 else
716 ldi_f(r0, (jit_word_t)i0);
717 }
718
719 static void
_movi_d(jit_state_t * _jit,jit_int32_t r0,jit_float64_t * i0)720 _movi_d(jit_state_t *_jit, jit_int32_t r0, jit_float64_t *i0)
721 {
722 union {
723 jit_int32_t ii[2];
724 jit_word_t w;
725 jit_float64_t d;
726 } data;
727 jit_int32_t reg;
728
729 data.d = *i0;
730 if (_jitc->no_data) {
731 data.d = *i0;
732 reg = jit_get_reg(jit_class_gpr);
733 movi(rn(reg), data.ii[0]);
734 stxi_i(alloca_offset - 8, _FP_REGNO, rn(reg));
735 movi(rn(reg), data.ii[1]);
736 stxi_i(alloca_offset - 4, _FP_REGNO, rn(reg));
737 jit_unget_reg(reg);
738 ldxi_d(r0, _FP_REGNO, alloca_offset - 8);
739 }
740 else
741 ldi_d(r0, (jit_word_t)i0);
742 }
743
744 #define fpr_opi(name, type, size) \
745 static void \
746 _##name##i_##type(jit_state_t *_jit, \
747 jit_int32_t r0, jit_int32_t r1, \
748 jit_float##size##_t *i0) \
749 { \
750 jit_int32_t reg = jit_get_reg(jit_class_fpr); \
751 movi_##type(rn(reg), i0); \
752 name##r_##type(r0, r1, rn(reg)); \
753 jit_unget_reg(reg); \
754 }
755 #define fopi(name) fpr_opi(name, f, 32)
756 #define dopi(name) fpr_opi(name, d, 64)
757
758 fopi(add)
dopi(add)759 dopi(add)
760 fopi(sub)
761 dopi(sub)
762 fopi(rsb)
763 dopi(rsb)
764 fopi(mul)
765 dopi(mul)
766 fopi(div)
767 dopi(div)
768
769 static void
770 _cmpr_f(jit_state_t *_jit, jit_word_t c,
771 jit_int32_t r0, jit_int32_t r1, jit_int32_t r2)
772 {
773 LDI(0, r0);
774 FCMP_S_(r1, r2, c);
775 FTEST();
776 LDI(1, r0);
777 }
778
779 static void
_cmpi_f(jit_state_t * _jit,jit_word_t c,jit_int32_t r0,jit_int32_t r1,jit_float32_t * i0)780 _cmpi_f(jit_state_t *_jit, jit_word_t c,
781 jit_int32_t r0, jit_int32_t r1, jit_float32_t *i0)
782 {
783 jit_int32_t reg = jit_get_reg(jit_class_fpr);
784 movi_f(rn(reg), i0);
785 cmpr_f(c, r0, r1, rn(reg));
786 jit_unget_reg(reg);
787 }
788
789 static void
_cmpr_d(jit_state_t * _jit,jit_word_t c,jit_int32_t r0,jit_int32_t r1,jit_int32_t r2)790 _cmpr_d(jit_state_t *_jit, jit_word_t c,
791 jit_int32_t r0, jit_int32_t r1, jit_int32_t r2)
792 {
793 LDI(0, r0);
794 FCMP_D_(r1, r2, c);
795 FTEST();
796 LDI(1, r0);
797 }
798
799 static void
_cmpi_d(jit_state_t * _jit,jit_word_t c,jit_int32_t r0,jit_int32_t r1,jit_float64_t * i0)800 _cmpi_d(jit_state_t *_jit, jit_word_t c,
801 jit_int32_t r0, jit_int32_t r1, jit_float64_t *i0)
802 {
803 jit_int32_t reg = jit_get_reg(jit_class_fpr);
804 movi_d(rn(reg), i0);
805 cmpr_d(c, r0, r1, rn(reg));
806 jit_unget_reg(reg);
807 }
808
809 static void
_ldi_f(jit_state_t * _jit,jit_int32_t r0,jit_word_t i0)810 _ldi_f(jit_state_t *_jit, jit_int32_t r0, jit_word_t i0)
811 {
812 jit_int32_t reg;
813 assert(!(i0 & 3));
814 if (i0 >= -8192 && i0 <= 8191 && !(re_assemble_16(i0) & 6))
815 FLDWL(i0, _R0_REGNO, r0);
816 else {
817 reg = jit_get_reg(jit_class_gpr);
818 movi(rn(reg), i0);
819 ldr_f(r0, rn(reg));
820 jit_unget_reg(reg);
821 }
822 }
823
824 #if !FLDXR
825 static void
_ldxr_f(jit_state_t * _jit,jit_int32_t r0,jit_int32_t r1,jit_int32_t r2)826 _ldxr_f(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_int32_t r2)
827 {
828 jit_int32_t reg;
829 reg = jit_get_reg(jit_class_gpr);
830 addr(rn(reg), r1, r2);
831 ldr_f(r0, rn(reg));
832 jit_unget_reg(reg);
833 }
834
835 static void
_ldxr_d(jit_state_t * _jit,jit_int32_t r0,jit_int32_t r1,jit_int32_t r2)836 _ldxr_d(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_int32_t r2)
837 {
838 jit_int32_t reg;
839 reg = jit_get_reg(jit_class_gpr);
840 addr(rn(reg), r1, r2);
841 ldr_d(r0, rn(reg));
842 jit_unget_reg(reg);
843 }
844 #endif
845
846 static void
_ldxi_f(jit_state_t * _jit,jit_int32_t r0,jit_int32_t r1,jit_word_t i0)847 _ldxi_f(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0)
848 {
849 jit_int32_t reg;
850 if (i0 >= -16 && i0 <= 15)
851 FLDWI(i0, r1, r0);
852 /* |im11a|0|t|i| */
853 else if (FLDXR && i0 >= -8192 && i0 <= 8191 && !(re_assemble_16(i0) & 6))
854 FLDWL(i0, r1, r0);
855 else {
856 reg = jit_get_reg(jit_class_gpr);
857 movi(rn(reg), i0);
858 ldxr_f(r0, r1, rn(reg));
859 jit_unget_reg(reg);
860 }
861 }
862
863 static void
_ldi_d(jit_state_t * _jit,jit_int32_t r0,jit_word_t i0)864 _ldi_d(jit_state_t *_jit, jit_int32_t r0, jit_word_t i0)
865 {
866 jit_int32_t reg;
867 assert(!(i0 & 7));
868 if (i0 >= -8192 && i0 <= 8191 && !(re_assemble_16(i0) & 14))
869 FLDDL(i0, _R0_REGNO, r0);
870 else {
871 reg = jit_get_reg(jit_class_gpr);
872 movi(rn(reg), i0);
873 ldr_d(r0, rn(reg));
874 jit_unget_reg(reg);
875 }
876 }
877
878 static void
_ldxi_d(jit_state_t * _jit,jit_int32_t r0,jit_int32_t r1,jit_word_t i0)879 _ldxi_d(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0)
880 {
881 jit_int32_t reg;
882 if (i0 >= -16 && i0 <= 15)
883 FLDDI(i0, r1, r0);
884 /* |im10a|m|a|1|i| */
885 else if (FLDXR && i0 >= -8192 && i0 <= 8191 && !(re_assemble_16(i0) & 14))
886 FLDDL(i0, r1, r0);
887 else {
888 reg = jit_get_reg(jit_class_gpr);
889 movi(rn(reg), i0);
890 ldxr_d(r0, r1, rn(reg));
891 jit_unget_reg(reg);
892 }
893 }
894
895 static void
_sti_f(jit_state_t * _jit,jit_word_t i0,jit_int32_t r0)896 _sti_f(jit_state_t *_jit, jit_word_t i0, jit_int32_t r0)
897 {
898 jit_int32_t reg;
899 assert(!(i0 & 3));
900 if (i0 >= -8192 && i0 <= 8191 && !(re_assemble_16(i0) & 6))
901 FSTWL(r0, i0, _R0_REGNO);
902 else {
903 reg = jit_get_reg(jit_class_gpr);
904 movi(rn(reg), i0);
905 str_f(rn(reg), r0);
906 jit_unget_reg(reg);
907 }
908 }
909
910 #if !FSTXR
911 static void
_stxr_f(jit_state_t * _jit,jit_int32_t r0,jit_int32_t r1,jit_int32_t r2)912 _stxr_f(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_int32_t r2)
913 {
914 jit_int32_t reg;
915 reg = jit_get_reg(jit_class_gpr);
916 addr(rn(reg), r0, r1);
917 str_f(rn(reg), r2);
918 jit_unget_reg(reg);
919 }
920
921 static void
_stxr_d(jit_state_t * _jit,jit_int32_t r0,jit_int32_t r1,jit_int32_t r2)922 _stxr_d(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_int32_t r2)
923 {
924 jit_int32_t reg;
925 reg = jit_get_reg(jit_class_gpr);
926 addr(rn(reg), r0, r1);
927 str_d(rn(reg), r2);
928 jit_unget_reg(reg);
929 }
930 #endif
931
932 static void
_stxi_f(jit_state_t * _jit,jit_word_t i0,jit_int32_t r0,jit_int32_t r1)933 _stxi_f(jit_state_t *_jit, jit_word_t i0, jit_int32_t r0, jit_int32_t r1)
934 {
935 jit_int32_t reg;
936 if (i0 >= -16 && i0 <= 15)
937 FSTWI(r1, i0, r0);
938 /* |im11a|0|t|i| */
939 else if (FSTXR && i0 >= -8192 && i0 <= 8191 && !(re_assemble_16(i0) & 6))
940 FSTWL(r1, i0, r0);
941 else {
942 reg = jit_get_reg(jit_class_gpr);
943 #if FSTXR
944 movi(rn(reg), i0);
945 stxr_f(rn(reg), r0, r1);
946 #else
947 addi(rn(reg), r0, i0);
948 str_f(rn(reg), r1);
949 #endif
950 jit_unget_reg(reg);
951 }
952 }
953
954 static void
_sti_d(jit_state_t * _jit,jit_word_t i0,jit_int32_t r0)955 _sti_d(jit_state_t *_jit, jit_word_t i0, jit_int32_t r0)
956 {
957 jit_int32_t reg;
958 assert(!(i0 & 7));
959 if (i0 >= -8192 && i0 <= 8191 && !(re_assemble_16(i0) & 14))
960 FSTDL(r0, i0, _R0_REGNO);
961 else {
962 reg = jit_get_reg(jit_class_gpr);
963 movi(rn(reg), i0);
964 str_d(rn(reg), r0);
965 jit_unget_reg(reg);
966 }
967 }
968
969 static void
_stxi_d(jit_state_t * _jit,jit_word_t i0,jit_int32_t r0,jit_int32_t r1)970 _stxi_d(jit_state_t *_jit, jit_word_t i0, jit_int32_t r0, jit_int32_t r1)
971 {
972 jit_int32_t reg;
973 if (i0 >= -16 && i0 <= 15)
974 FSTDI(r1, i0, r0);
975 /* |im10a|m|a|1|i| */
976 else if (FSTXR && i0 >= -8192 && i0 <= 8191 && !(re_assemble_16(i0) & 14))
977 FSTDL(r1, i0, r0);
978 else {
979 reg = jit_get_reg(jit_class_gpr);
980 #if FSTXR
981 movi(rn(reg), i0);
982 stxr_d(rn(reg), r0, r1);
983 #else
984 addi(rn(reg), r0, i0);
985 str_d(rn(reg), r1);
986 #endif
987 jit_unget_reg(reg);
988 }
989 }
990
991 static jit_word_t
_bcmpr_f(jit_state_t * _jit,jit_word_t c,jit_word_t i0,jit_int32_t r0,jit_int32_t r1)992 _bcmpr_f(jit_state_t *_jit, jit_word_t c,
993 jit_word_t i0, jit_int32_t r0, jit_int32_t r1)
994 {
995 jit_word_t w;
996 FCMP_S_(r0, r1, c);
997 FTEST();
998 w = _jit->pc.w;
999 B_N(((i0 - w) >> 2) - 2, _R0_REGNO);
1000 NOP();
1001 return (w);
1002 }
1003
1004 static jit_word_t
_bcmpi_f(jit_state_t * _jit,jit_word_t c,jit_word_t i0,jit_int32_t r0,jit_float32_t * i1)1005 _bcmpi_f(jit_state_t *_jit, jit_word_t c,
1006 jit_word_t i0, jit_int32_t r0, jit_float32_t *i1)
1007 {
1008 jit_word_t w;
1009 jit_int32_t reg;
1010 reg = jit_get_reg(jit_class_fpr|jit_class_nospill);
1011 movi_f(rn(reg), i1);
1012 FCMP_S_(r0, rn(reg), c);
1013 FTEST();
1014 w = _jit->pc.w;
1015 B_N(((i0 - w) >> 2) - 2, _R0_REGNO);
1016 NOP();
1017 jit_unget_reg(reg);
1018 return (w);
1019 }
1020
1021 static jit_word_t
_bcmpr_d(jit_state_t * _jit,jit_word_t c,jit_word_t i0,jit_int32_t r0,jit_int32_t r1)1022 _bcmpr_d(jit_state_t *_jit, jit_word_t c,
1023 jit_word_t i0, jit_int32_t r0, jit_int32_t r1)
1024 {
1025 jit_word_t w;
1026 FCMP_D_(r0, r1, c);
1027 FTEST();
1028 w = _jit->pc.w;
1029 B_N(((i0 - w) >> 2) - 2, _R0_REGNO);
1030 NOP();
1031 return (w);
1032 }
1033
1034 static jit_word_t
_bcmpi_d(jit_state_t * _jit,jit_word_t c,jit_word_t i0,jit_int32_t r0,jit_float64_t * i1)1035 _bcmpi_d(jit_state_t *_jit, jit_word_t c,
1036 jit_word_t i0, jit_int32_t r0, jit_float64_t *i1)
1037 {
1038 jit_word_t w;
1039 jit_int32_t reg;
1040 reg = jit_get_reg(jit_class_fpr|jit_class_nospill);
1041 movi_d(rn(reg), i1);
1042 FCMP_D_(r0, rn(reg), c);
1043 FTEST();
1044 w = _jit->pc.w;
1045 B_N(((i0 - w) >> 2) - 2, _R0_REGNO);
1046 NOP();
1047 jit_unget_reg(reg);
1048 return (w);
1049 }
1050
1051 static void
_vaarg_d(jit_state_t * _jit,jit_int32_t r0,jit_int32_t r1)1052 _vaarg_d(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
1053 {
1054 jit_int32_t reg;
1055
1056 assert(_jitc->function->self.call & jit_call_varargs);
1057
1058 /* Align pointer if required. */
1059 reg = jit_get_reg(jit_class_gpr);
1060 andi(rn(reg), r1, 7);
1061 subr(r1, r1, rn(reg));
1062 jit_unget_reg(reg);
1063
1064 /* Adjust vararg stack pointer. */
1065 subi(r1, r1, 8);
1066
1067 /* Load argument. */
1068 ldr_d(r0, r1);
1069 }
1070 #endif
1071