cgen-ops.h revision 1.1 1 1.1 christos /* Semantics ops support for CGEN-based simulators.
2 1.1 christos Copyright (C) 1996-2014 Free Software Foundation, Inc.
3 1.1 christos Contributed by Cygnus Solutions.
4 1.1 christos
5 1.1 christos This file is part of the GNU Simulators.
6 1.1 christos
7 1.1 christos This program is free software; you can redistribute it and/or modify
8 1.1 christos it under the terms of the GNU General Public License as published by
9 1.1 christos the Free Software Foundation; either version 3 of the License, or
10 1.1 christos (at your option) any later version.
11 1.1 christos
12 1.1 christos This program is distributed in the hope that it will be useful,
13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 1.1 christos GNU General Public License for more details.
16 1.1 christos
17 1.1 christos You should have received a copy of the GNU General Public License
18 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>.
19 1.1 christos
20 1.1 christos */
21 1.1 christos
22 1.1 christos #ifndef CGEN_SEM_OPS_H
23 1.1 christos #define CGEN_SEM_OPS_H
24 1.1 christos
25 1.1 christos #include <assert.h>
26 1.1 christos
27 1.1 christos #if defined (__GNUC__) && ! defined (SEMOPS_DEFINE_INLINE)
28 1.1 christos #define SEMOPS_DEFINE_INLINE
29 1.1 christos #define SEMOPS_INLINE extern inline
30 1.1 christos #else
31 1.1 christos #define SEMOPS_INLINE
32 1.1 christos #endif
33 1.1 christos
34 1.1 christos /* Semantic operations.
35 1.1 christos At one point this file was machine generated. Maybe it will be again. */
36 1.1 christos
37 1.1 christos /* TODO: Lazy encoding/decoding of fp values. */
38 1.1 christos
39 1.1 christos /* These don't really have a mode. */
40 1.1 christos #define ANDIF(x, y) ((x) && (y))
41 1.1 christos #define ORIF(x, y) ((x) || (y))
42 1.1 christos
43 1.1 christos #define SUBBI(x, y) ((x) - (y))
44 1.1 christos #define ANDBI(x, y) ((x) & (y))
45 1.1 christos #define ORBI(x, y) ((x) | (y))
46 1.1 christos #define XORBI(x, y) ((x) ^ (y))
47 1.1 christos #define NEGBI(x) (- (x))
48 1.1 christos #define NOTBI(x) (! (BI) (x))
49 1.1 christos #define INVBI(x) (~ (x))
50 1.1 christos #define EQBI(x, y) ((BI) (x) == (BI) (y))
51 1.1 christos #define NEBI(x, y) ((BI) (x) != (BI) (y))
52 1.1 christos #define LTBI(x, y) ((BI) (x) < (BI) (y))
53 1.1 christos #define LEBI(x, y) ((BI) (x) <= (BI) (y))
54 1.1 christos #define GTBI(x, y) ((BI) (x) > (BI) (y))
55 1.1 christos #define GEBI(x, y) ((BI) (x) >= (BI) (y))
56 1.1 christos #define LTUBI(x, y) ((BI) (x) < (BI) (y))
57 1.1 christos #define LEUBI(x, y) ((BI) (x) <= (BI) (y))
58 1.1 christos #define GTUBI(x, y) ((BI) (x) > (BI) (y))
59 1.1 christos #define GEUBI(x, y) ((BI) (x) >= (BI) (y))
60 1.1 christos
61 1.1 christos #define ADDQI(x, y) ((QI) ((UQI) (x) + (UQI) (y)))
63 1.1 christos #define SUBQI(x, y) ((QI) ((UQI) (x) - (UQI) (y)))
64 1.1 christos #define MULQI(x, y) ((QI) ((UQI) (x) * (UQI) (y)))
65 1.1 christos #define DIVQI(x, y) ((QI) (x) / (QI) (y))
66 1.1 christos #define UDIVQI(x, y) ((UQI) (x) / (UQI) (y))
67 1.1 christos #define MODQI(x, y) ((QI) (x) % (QI) (y))
68 1.1 christos #define UMODQI(x, y) ((UQI) (x) % (UQI) (y))
69 1.1 christos #define SRAQI(x, y) ((QI) (x) >> (y))
70 1.1 christos #define SRLQI(x, y) ((UQI) (x) >> (y))
71 1.1 christos #define SLLQI(x, y) ((UQI) (x) << (y))
72 1.1 christos extern QI RORQI (QI, int);
73 1.1 christos extern QI ROLQI (QI, int);
74 1.1 christos #define ANDQI(x, y) ((x) & (y))
75 1.1 christos #define ORQI(x, y) ((x) | (y))
76 1.1 christos #define XORQI(x, y) ((x) ^ (y))
77 1.1 christos #define NEGQI(x) ((QI) (- (UQI) (x)))
78 1.1 christos #define NOTQI(x) (! (QI) (x))
79 1.1 christos #define INVQI(x) (~ (x))
80 1.1 christos #define ABSQI(x) ((QI) ((QI) (x) < 0 ? -(UQI) (x) : (UQI) (x)))
81 1.1 christos #define EQQI(x, y) ((QI) (x) == (QI) (y))
82 1.1 christos #define NEQI(x, y) ((QI) (x) != (QI) (y))
83 1.1 christos #define LTQI(x, y) ((QI) (x) < (QI) (y))
84 1.1 christos #define LEQI(x, y) ((QI) (x) <= (QI) (y))
85 1.1 christos #define GTQI(x, y) ((QI) (x) > (QI) (y))
86 1.1 christos #define GEQI(x, y) ((QI) (x) >= (QI) (y))
87 1.1 christos #define LTUQI(x, y) ((UQI) (x) < (UQI) (y))
88 1.1 christos #define LEUQI(x, y) ((UQI) (x) <= (UQI) (y))
89 1.1 christos #define GTUQI(x, y) ((UQI) (x) > (UQI) (y))
90 1.1 christos #define GEUQI(x, y) ((UQI) (x) >= (UQI) (y))
91 1.1 christos
92 1.1 christos #define ADDHI(x, y) ((HI) ((UHI) (x) + (UHI) (y)))
94 1.1 christos #define SUBHI(x, y) ((HI) ((UHI) (x) - (UHI) (y)))
95 1.1 christos #define MULHI(x, y) ((HI) ((UHI) (x) * (UHI) (y)))
96 1.1 christos #define DIVHI(x, y) ((HI) (x) / (HI) (y))
97 1.1 christos #define UDIVHI(x, y) ((UHI) (x) / (UHI) (y))
98 1.1 christos #define MODHI(x, y) ((HI) (x) % (HI) (y))
99 1.1 christos #define UMODHI(x, y) ((UHI) (x) % (UHI) (y))
100 1.1 christos #define SRAHI(x, y) ((HI) (x) >> (y))
101 1.1 christos #define SRLHI(x, y) ((UHI) (x) >> (y))
102 1.1 christos #define SLLHI(x, y) ((UHI) (x) << (y))
103 1.1 christos extern HI RORHI (HI, int);
104 1.1 christos extern HI ROLHI (HI, int);
105 1.1 christos #define ANDHI(x, y) ((x) & (y))
106 1.1 christos #define ORHI(x, y) ((x) | (y))
107 1.1 christos #define XORHI(x, y) ((x) ^ (y))
108 1.1 christos #define NEGHI(x) ((HI) (- (UHI) (x)))
109 1.1 christos #define NOTHI(x) (! (HI) (x))
110 1.1 christos #define INVHI(x) (~ (x))
111 1.1 christos #define ABSHI(x) ((HI) ((HI) (x) < 0 ? -(UHI) (x) : (UHI) (x)))
112 1.1 christos #define EQHI(x, y) ((HI) (x) == (HI) (y))
113 1.1 christos #define NEHI(x, y) ((HI) (x) != (HI) (y))
114 1.1 christos #define LTHI(x, y) ((HI) (x) < (HI) (y))
115 1.1 christos #define LEHI(x, y) ((HI) (x) <= (HI) (y))
116 1.1 christos #define GTHI(x, y) ((HI) (x) > (HI) (y))
117 1.1 christos #define GEHI(x, y) ((HI) (x) >= (HI) (y))
118 1.1 christos #define LTUHI(x, y) ((UHI) (x) < (UHI) (y))
119 1.1 christos #define LEUHI(x, y) ((UHI) (x) <= (UHI) (y))
120 1.1 christos #define GTUHI(x, y) ((UHI) (x) > (UHI) (y))
121 1.1 christos #define GEUHI(x, y) ((UHI) (x) >= (UHI) (y))
122 1.1 christos
123 1.1 christos #define ADDSI(x, y) ((SI) ((USI) (x) + (USI) (y)))
125 1.1 christos #define SUBSI(x, y) ((SI) ((USI) (x) - (USI) (y)))
126 1.1 christos #define MULSI(x, y) ((SI) ((USI) (x) * (USI) (y)))
127 1.1 christos #define DIVSI(x, y) ((SI) (x) / (SI) (y))
128 1.1 christos #define UDIVSI(x, y) ((USI) (x) / (USI) (y))
129 1.1 christos #define MODSI(x, y) ((SI) (x) % (SI) (y))
130 1.1 christos #define UMODSI(x, y) ((USI) (x) % (USI) (y))
131 1.1 christos #define SRASI(x, y) ((SI) (x) >> (y))
132 1.1 christos #define SRLSI(x, y) ((USI) (x) >> (y))
133 1.1 christos #define SLLSI(x, y) ((USI) (x) << (y))
134 1.1 christos extern SI RORSI (SI, int);
135 1.1 christos extern SI ROLSI (SI, int);
136 1.1 christos #define ANDSI(x, y) ((x) & (y))
137 1.1 christos #define ORSI(x, y) ((x) | (y))
138 1.1 christos #define XORSI(x, y) ((x) ^ (y))
139 1.1 christos #define NEGSI(x) ((SI) (- (USI) (x)))
140 1.1 christos #define NOTSI(x) (! (SI) (x))
141 1.1 christos #define INVSI(x) (~ (x))
142 1.1 christos #define ABSSI(x) ((SI) ((SI) (x) < 0 ? -(USI) (x) : (USI) (x)))
143 1.1 christos #define EQSI(x, y) ((SI) (x) == (SI) (y))
144 1.1 christos #define NESI(x, y) ((SI) (x) != (SI) (y))
145 1.1 christos #define LTSI(x, y) ((SI) (x) < (SI) (y))
146 1.1 christos #define LESI(x, y) ((SI) (x) <= (SI) (y))
147 1.1 christos #define GTSI(x, y) ((SI) (x) > (SI) (y))
148 1.1 christos #define GESI(x, y) ((SI) (x) >= (SI) (y))
149 1.1 christos #define LTUSI(x, y) ((USI) (x) < (USI) (y))
150 1.1 christos #define LEUSI(x, y) ((USI) (x) <= (USI) (y))
151 1.1 christos #define GTUSI(x, y) ((USI) (x) > (USI) (y))
152 1.1 christos #define GEUSI(x, y) ((USI) (x) >= (USI) (y))
153 1.1 christos
154 1.1 christos #ifdef DI_FN_SUPPORT
156 1.1 christos extern DI ADDDI (DI, DI);
157 1.1 christos extern DI SUBDI (DI, DI);
158 1.1 christos extern DI MULDI (DI, DI);
159 1.1 christos extern DI DIVDI (DI, DI);
160 1.1 christos extern DI UDIVDI (DI, DI);
161 1.1 christos extern DI MODDI (DI, DI);
162 1.1 christos extern DI UMODDI (DI, DI);
163 1.1 christos extern DI SRADI (DI, int);
164 1.1 christos extern UDI SRLDI (UDI, int);
165 1.1 christos extern UDI SLLDI (UDI, int);
166 1.1 christos extern DI RORDI (DI, int);
167 1.1 christos extern DI ROLDI (DI, int);
168 1.1 christos extern DI ANDDI (DI, DI);
169 1.1 christos extern DI ORDI (DI, DI);
170 1.1 christos extern DI XORDI (DI, DI);
171 1.1 christos extern DI NEGDI (DI);
172 1.1 christos extern int NOTDI (DI);
173 1.1 christos extern DI INVDI (DI);
174 1.1 christos extern int EQDI (DI, DI);
175 1.1 christos extern int NEDI (DI, DI);
176 1.1 christos extern int LTDI (DI, DI);
177 1.1 christos extern int LEDI (DI, DI);
178 1.1 christos extern int GTDI (DI, DI);
179 1.1 christos extern int GEDI (DI, DI);
180 1.1 christos extern int LTUDI (UDI, UDI);
181 1.1 christos extern int LEUDI (UDI, UDI);
182 1.1 christos extern int GTUDI (UDI, UDI);
183 1.1 christos extern int GEUDI (UDI, UDI);
184 1.1 christos #else /* ! DI_FN_SUPPORT */
185 1.1 christos #define ADDDI(x, y) ((DI) ((UDI) (x) + (UDI) (y)))
186 1.1 christos #define SUBDI(x, y) ((DI) ((UDI) (x) - (UDI) (y)))
187 1.1 christos #define MULDI(x, y) ((DI) ((UDI) (x) * (UDI) (y)))
188 1.1 christos #define DIVDI(x, y) ((DI) (x) / (DI) (y))
189 1.1 christos #define UDIVDI(x, y) ((UDI) (x) / (UDI) (y))
190 1.1 christos #define MODDI(x, y) ((DI) (x) % (DI) (y))
191 1.1 christos #define UMODDI(x, y) ((UDI) (x) % (UDI) (y))
192 1.1 christos #define SRADI(x, y) ((DI) (x) >> (y))
193 1.1 christos #define SRLDI(x, y) ((UDI) (x) >> (y))
194 1.1 christos #define SLLDI(x, y) ((UDI) (x) << (y))
195 1.1 christos extern DI RORDI (DI, int);
196 1.1 christos extern DI ROLDI (DI, int);
197 1.1 christos #define ANDDI(x, y) ((x) & (y))
198 1.1 christos #define ORDI(x, y) ((x) | (y))
199 1.1 christos #define XORDI(x, y) ((x) ^ (y))
200 1.1 christos #define NEGDI(x) ((DI) (- (UDI) (x)))
201 1.1 christos #define NOTDI(x) (! (DI) (x))
202 1.1 christos #define INVDI(x) (~ (x))
203 1.1 christos #define ABSDI(x) ((DI) ((DI) (x) < 0 ? -(UDI) (x) : (UDI) (x)))
204 1.1 christos #define EQDI(x, y) ((DI) (x) == (DI) (y))
205 1.1 christos #define NEDI(x, y) ((DI) (x) != (DI) (y))
206 1.1 christos #define LTDI(x, y) ((DI) (x) < (DI) (y))
207 1.1 christos #define LEDI(x, y) ((DI) (x) <= (DI) (y))
208 1.1 christos #define GTDI(x, y) ((DI) (x) > (DI) (y))
209 1.1 christos #define GEDI(x, y) ((DI) (x) >= (DI) (y))
210 1.1 christos #define LTUDI(x, y) ((UDI) (x) < (UDI) (y))
211 1.1 christos #define LEUDI(x, y) ((UDI) (x) <= (UDI) (y))
212 1.1 christos #define GTUDI(x, y) ((UDI) (x) > (UDI) (y))
213 1.1 christos #define GEUDI(x, y) ((UDI) (x) >= (UDI) (y))
214 1.1 christos #endif /* DI_FN_SUPPORT */
215 1.1 christos
216 1.1 christos #define EXTBIQI(x) ((QI) (BI) (x))
218 1.1 christos #define EXTBIHI(x) ((HI) (BI) (x))
219 1.1 christos #define EXTBISI(x) ((SI) (BI) (x))
220 1.1 christos #if defined (DI_FN_SUPPORT)
221 1.1 christos extern DI EXTBIDI (BI);
222 1.1 christos #else
223 1.1 christos #define EXTBIDI(x) ((DI) (BI) (x))
224 1.1 christos #endif
225 1.1 christos #define EXTQIHI(x) ((HI) (QI) (x))
226 1.1 christos #define EXTQISI(x) ((SI) (QI) (x))
227 1.1 christos #if defined (DI_FN_SUPPORT)
228 1.1 christos extern DI EXTQIDI (QI);
229 1.1 christos #else
230 1.1 christos #define EXTQIDI(x) ((DI) (QI) (x))
231 1.1 christos #endif
232 1.1 christos #define EXTHIHI(x) ((HI) (HI) (x))
233 1.1 christos #define EXTHISI(x) ((SI) (HI) (x))
234 1.1 christos #define EXTSISI(x) ((SI) (SI) (x))
235 1.1 christos #if defined (DI_FN_SUPPORT)
236 1.1 christos extern DI EXTHIDI (HI);
237 1.1 christos #else
238 1.1 christos #define EXTHIDI(x) ((DI) (HI) (x))
239 1.1 christos #endif
240 1.1 christos #if defined (DI_FN_SUPPORT)
241 1.1 christos extern DI EXTSIDI (SI);
242 1.1 christos #else
243 1.1 christos #define EXTSIDI(x) ((DI) (SI) (x))
244 1.1 christos #endif
245 1.1 christos
246 1.1 christos #define ZEXTBIQI(x) ((QI) (BI) (x))
248 1.1 christos #define ZEXTBIHI(x) ((HI) (BI) (x))
249 1.1 christos #define ZEXTBISI(x) ((SI) (BI) (x))
250 1.1 christos #if defined (DI_FN_SUPPORT)
251 1.1 christos extern DI ZEXTBIDI (BI);
252 1.1 christos #else
253 1.1 christos #define ZEXTBIDI(x) ((DI) (BI) (x))
254 1.1 christos #endif
255 1.1 christos #define ZEXTQIHI(x) ((HI) (UQI) (x))
256 1.1 christos #define ZEXTQISI(x) ((SI) (UQI) (x))
257 1.1 christos #if defined (DI_FN_SUPPORT)
258 1.1 christos extern DI ZEXTQIDI (QI);
259 1.1 christos #else
260 1.1 christos #define ZEXTQIDI(x) ((DI) (UQI) (x))
261 1.1 christos #endif
262 1.1 christos #define ZEXTHISI(x) ((SI) (UHI) (x))
263 1.1 christos #define ZEXTHIHI(x) ((HI) (UHI) (x))
264 1.1 christos #define ZEXTSISI(x) ((SI) (USI) (x))
265 1.1 christos #if defined (DI_FN_SUPPORT)
266 1.1 christos extern DI ZEXTHIDI (HI);
267 1.1 christos #else
268 1.1 christos #define ZEXTHIDI(x) ((DI) (UHI) (x))
269 1.1 christos #endif
270 1.1 christos #if defined (DI_FN_SUPPORT)
271 1.1 christos extern DI ZEXTSIDI (SI);
272 1.1 christos #else
273 1.1 christos #define ZEXTSIDI(x) ((DI) (USI) (x))
274 1.1 christos #endif
275 1.1 christos
276 1.1 christos #define TRUNCQIBI(x) ((BI) (QI) (x))
278 1.1 christos #define TRUNCHIBI(x) ((BI) (HI) (x))
279 1.1 christos #define TRUNCHIQI(x) ((QI) (HI) (x))
280 1.1 christos #define TRUNCSIBI(x) ((BI) (SI) (x))
281 1.1 christos #define TRUNCSIQI(x) ((QI) (SI) (x))
282 1.1 christos #define TRUNCSIHI(x) ((HI) (SI) (x))
283 1.1 christos #define TRUNCSISI(x) ((SI) (SI) (x))
284 1.1 christos #if defined (DI_FN_SUPPORT)
285 1.1 christos extern BI TRUNCDIBI (DI);
286 1.1 christos #else
287 1.1 christos #define TRUNCDIBI(x) ((BI) (DI) (x))
288 1.1 christos #endif
289 1.1 christos #if defined (DI_FN_SUPPORT)
290 1.1 christos extern QI TRUNCDIQI (DI);
291 1.1 christos #else
292 1.1 christos #define TRUNCDIQI(x) ((QI) (DI) (x))
293 1.1 christos #endif
294 1.1 christos #if defined (DI_FN_SUPPORT)
295 1.1 christos extern HI TRUNCDIHI (DI);
296 1.1 christos #else
297 1.1 christos #define TRUNCDIHI(x) ((HI) (DI) (x))
298 1.1 christos #endif
299 1.1 christos #if defined (DI_FN_SUPPORT)
300 1.1 christos extern SI TRUNCDISI (DI);
301 1.1 christos #else
302 1.1 christos #define TRUNCDISI(x) ((SI) (DI) (x))
303 1.1 christos #endif
304 1.1 christos
305 1.1 christos /* Composing/decomposing the various types.
307 1.1 christos Word ordering is endian-independent. Words are specified most to least
308 1.1 christos significant and word number 0 is the most significant word.
309 1.1 christos ??? May also wish an endian-dependent version. Later. */
310 1.1 christos
311 1.1 christos #ifdef SEMOPS_DEFINE_INLINE
312 1.1 christos
313 1.1 christos SEMOPS_INLINE SF
314 1.1 christos SUBWORDSISF (SI in)
315 1.1 christos {
316 1.1 christos union { SI in; SF out; } x;
317 1.1 christos x.in = in;
318 1.1 christos return x.out;
319 1.1 christos }
320 1.1 christos
321 1.1 christos SEMOPS_INLINE DF
322 1.1 christos SUBWORDDIDF (DI in)
323 1.1 christos {
324 1.1 christos union { DI in; DF out; } x;
325 1.1 christos x.in = in;
326 1.1 christos return x.out;
327 1.1 christos }
328 1.1 christos
329 1.1 christos SEMOPS_INLINE QI
330 1.1 christos SUBWORDSIQI (SI in, int byte)
331 1.1 christos {
332 1.1 christos assert (byte >= 0 && byte <= 3);
333 1.1 christos return (UQI) (in >> (8 * (3 - byte))) & 0xFF;
334 1.1 christos }
335 1.1 christos
336 1.1 christos SEMOPS_INLINE UQI
337 1.1 christos SUBWORDSIUQI (SI in, int byte)
338 1.1 christos {
339 1.1 christos assert (byte >= 0 && byte <= 3);
340 1.1 christos return (UQI) (in >> (8 * (3 - byte))) & 0xFF;
341 1.1 christos }
342 1.1 christos
343 1.1 christos SEMOPS_INLINE QI
344 1.1 christos SUBWORDDIQI (DI in, int byte)
345 1.1 christos {
346 1.1 christos assert (byte >= 0 && byte <= 7);
347 1.1 christos return (UQI) (in >> (8 * (7 - byte))) & 0xFF;
348 1.1 christos }
349 1.1 christos
350 1.1 christos SEMOPS_INLINE HI
351 1.1 christos SUBWORDDIHI (DI in, int word)
352 1.1 christos {
353 1.1 christos assert (word >= 0 && word <= 3);
354 1.1 christos return (UHI) (in >> (16 * (3 - word))) & 0xFFFF;
355 1.1 christos }
356 1.1 christos
357 1.1 christos SEMOPS_INLINE HI
358 1.1 christos SUBWORDSIHI (SI in, int word)
359 1.1 christos {
360 1.1 christos if (word == 0)
361 1.1 christos return (USI) in >> 16;
362 1.1 christos else
363 1.1 christos return in;
364 1.1 christos }
365 1.1 christos
366 1.1 christos SEMOPS_INLINE SI
367 1.1 christos SUBWORDSFSI (SF in)
368 1.1 christos {
369 1.1 christos union { SF in; SI out; } x;
370 1.1 christos x.in = in;
371 1.1 christos return x.out;
372 1.1 christos }
373 1.1 christos
374 1.1 christos SEMOPS_INLINE DI
375 1.1 christos SUBWORDDFDI (DF in)
376 1.1 christos {
377 1.1 christos union { DF in; DI out; } x;
378 1.1 christos x.in = in;
379 1.1 christos return x.out;
380 1.1 christos }
381 1.1 christos
382 1.1 christos SEMOPS_INLINE UQI
383 1.1 christos SUBWORDDIUQI (DI in, int byte)
384 1.1 christos {
385 1.1 christos assert (byte >= 0 && byte <= 7);
386 1.1 christos return (UQI) (in >> (8 * (7 - byte)));
387 1.1 christos }
388 1.1 christos
389 1.1 christos SEMOPS_INLINE SI
390 1.1 christos SUBWORDDISI (DI in, int word)
391 1.1 christos {
392 1.1 christos if (word == 0)
393 1.1 christos return (UDI) in >> 32;
394 1.1 christos else
395 1.1 christos return in;
396 1.1 christos }
397 1.1 christos
398 1.1 christos SEMOPS_INLINE SI
399 1.1 christos SUBWORDDFSI (DF in, int word)
400 1.1 christos {
401 1.1 christos /* Note: typedef UDI DF; */
402 1.1 christos if (word == 0)
403 1.1 christos return (UDI) in >> 32;
404 1.1 christos else
405 1.1 christos return in;
406 1.1 christos }
407 1.1 christos
408 1.1 christos SEMOPS_INLINE SI
409 1.1 christos SUBWORDXFSI (XF in, int word)
410 1.1 christos {
411 1.1 christos /* Note: typedef struct { SI parts[3]; } XF; */
412 1.1 christos union { XF in; SI out[3]; } x;
413 1.1 christos x.in = in;
414 1.1 christos if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
415 1.1 christos return x.out[word];
416 1.1 christos else
417 1.1 christos return x.out[2 - word];
418 1.1 christos }
419 1.1 christos
420 1.1 christos SEMOPS_INLINE SI
421 1.1 christos SUBWORDTFSI (TF in, int word)
422 1.1 christos {
423 1.1 christos /* Note: typedef struct { SI parts[4]; } TF; */
424 1.1 christos union { TF in; SI out[4]; } x;
425 1.1 christos x.in = in;
426 1.1 christos if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
427 1.1 christos return x.out[word];
428 1.1 christos else
429 1.1 christos return x.out[3 - word];
430 1.1 christos }
431 1.1 christos
432 1.1 christos SEMOPS_INLINE DI
433 1.1 christos JOINSIDI (SI x0, SI x1)
434 1.1 christos {
435 1.1 christos return MAKEDI (x0, x1);
436 1.1 christos }
437 1.1 christos
438 1.1 christos SEMOPS_INLINE DF
439 1.1 christos JOINSIDF (SI x0, SI x1)
440 1.1 christos {
441 1.1 christos union { SI in[2]; DF out; } x;
442 1.1 christos if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
443 1.1 christos x.in[0] = x0, x.in[1] = x1;
444 1.1 christos else
445 1.1 christos x.in[1] = x0, x.in[0] = x1;
446 1.1 christos return x.out;
447 1.1 christos }
448 1.1 christos
449 1.1 christos SEMOPS_INLINE XF
450 1.1 christos JOINSIXF (SI x0, SI x1, SI x2)
451 1.1 christos {
452 1.1 christos union { SI in[3]; XF out; } x;
453 1.1 christos if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
454 1.1 christos x.in[0] = x0, x.in[1] = x1, x.in[2] = x2;
455 1.1 christos else
456 1.1 christos x.in[2] = x0, x.in[1] = x1, x.in[0] = x2;
457 1.1 christos return x.out;
458 1.1 christos }
459 1.1 christos
460 1.1 christos SEMOPS_INLINE TF
461 1.1 christos JOINSITF (SI x0, SI x1, SI x2, SI x3)
462 1.1 christos {
463 1.1 christos union { SI in[4]; TF out; } x;
464 1.1 christos if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
465 1.1 christos x.in[0] = x0, x.in[1] = x1, x.in[2] = x2, x.in[3] = x3;
466 1.1 christos else
467 1.1 christos x.in[3] = x0, x.in[2] = x1, x.in[1] = x2, x.in[0] = x3;
468 1.1 christos return x.out;
469 1.1 christos }
470 1.1 christos
471 1.1 christos #else
472 1.1 christos
473 1.1 christos QI SUBWORDSIQI (SI);
474 1.1 christos HI SUBWORDSIHI (HI);
475 1.1 christos SI SUBWORDSFSI (SF);
476 1.1 christos SF SUBWORDSISF (SI);
477 1.1 christos DI SUBWORDDFDI (DF);
478 1.1 christos DF SUBWORDDIDF (DI);
479 1.1 christos QI SUBWORDDIQI (DI, int);
480 1.1 christos HI SUBWORDDIHI (DI, int);
481 1.1 christos SI SUBWORDDISI (DI, int);
482 1.1 christos SI SUBWORDDFSI (DF, int);
483 1.1 christos SI SUBWORDXFSI (XF, int);
484 1.1 christos SI SUBWORDTFSI (TF, int);
485 1.1 christos
486 1.1 christos UQI SUBWORDSIUQI (SI);
487 1.1 christos UQI SUBWORDDIUQI (DI);
488 1.1 christos
489 1.1 christos DI JOINSIDI (SI, SI);
490 1.1 christos DF JOINSIDF (SI, SI);
491 1.1 christos XF JOINSIXF (SI, SI, SI);
492 1.1 christos TF JOINSITF (SI, SI, SI, SI);
493 1.1 christos
494 1.1 christos #endif /* SUBWORD,JOIN */
495 1.1 christos
496 1.1 christos /* Semantic support utilities. */
498 1.1 christos
499 1.1 christos #ifdef SEMOPS_DEFINE_INLINE
500 1.1 christos
501 1.1 christos SEMOPS_INLINE SI
502 1.1 christos ADDCSI (SI a, SI b, BI c)
503 1.1 christos {
504 1.1 christos SI res = ADDSI (a, ADDSI (b, c));
505 1.1 christos return res;
506 1.1 christos }
507 1.1 christos
508 1.1 christos SEMOPS_INLINE BI
509 1.1 christos ADDCFSI (SI a, SI b, BI c)
510 1.1 christos {
511 1.1 christos SI tmp = ADDSI (a, ADDSI (b, c));
512 1.1 christos BI res = ((USI) tmp < (USI) a) || (c && tmp == a);
513 1.1 christos return res;
514 1.1 christos }
515 1.1 christos
516 1.1 christos SEMOPS_INLINE BI
517 1.1 christos ADDOFSI (SI a, SI b, BI c)
518 1.1 christos {
519 1.1 christos SI tmp = ADDSI (a, ADDSI (b, c));
520 1.1 christos BI res = (((a < 0) == (b < 0))
521 1.1 christos && ((a < 0) != (tmp < 0)));
522 1.1 christos return res;
523 1.1 christos }
524 1.1 christos
525 1.1 christos SEMOPS_INLINE SI
526 1.1 christos SUBCSI (SI a, SI b, BI c)
527 1.1 christos {
528 1.1 christos SI res = SUBSI (a, ADDSI (b, c));
529 1.1 christos return res;
530 1.1 christos }
531 1.1 christos
532 1.1 christos SEMOPS_INLINE BI
533 1.1 christos SUBCFSI (SI a, SI b, BI c)
534 1.1 christos {
535 1.1 christos BI res = ((USI) a < (USI) b) || (c && a == b);
536 1.1 christos return res;
537 1.1 christos }
538 1.1 christos
539 1.1 christos SEMOPS_INLINE BI
540 1.1 christos SUBOFSI (SI a, SI b, BI c)
541 1.1 christos {
542 1.1 christos SI tmp = SUBSI (a, ADDSI (b, c));
543 1.1 christos BI res = (((a < 0) != (b < 0))
544 1.1 christos && ((a < 0) != (tmp < 0)));
545 1.1 christos return res;
546 1.1 christos }
547 1.1 christos
548 1.1 christos SEMOPS_INLINE HI
549 1.1 christos ADDCHI (HI a, HI b, BI c)
550 1.1 christos {
551 1.1 christos HI res = ADDHI (a, ADDHI (b, c));
552 1.1 christos return res;
553 1.1 christos }
554 1.1 christos
555 1.1 christos SEMOPS_INLINE BI
556 1.1 christos ADDCFHI (HI a, HI b, BI c)
557 1.1 christos {
558 1.1 christos HI tmp = ADDHI (a, ADDHI (b, c));
559 1.1 christos BI res = ((UHI) tmp < (UHI) a) || (c && tmp == a);
560 1.1 christos return res;
561 1.1 christos }
562 1.1 christos
563 1.1 christos SEMOPS_INLINE BI
564 1.1 christos ADDOFHI (HI a, HI b, BI c)
565 1.1 christos {
566 1.1 christos HI tmp = ADDHI (a, ADDHI (b, c));
567 1.1 christos BI res = (((a < 0) == (b < 0))
568 1.1 christos && ((a < 0) != (tmp < 0)));
569 1.1 christos return res;
570 1.1 christos }
571 1.1 christos
572 1.1 christos SEMOPS_INLINE HI
573 1.1 christos SUBCHI (HI a, HI b, BI c)
574 1.1 christos {
575 1.1 christos HI res = SUBHI (a, ADDHI (b, c));
576 1.1 christos return res;
577 1.1 christos }
578 1.1 christos
579 1.1 christos SEMOPS_INLINE BI
580 1.1 christos SUBCFHI (HI a, HI b, BI c)
581 1.1 christos {
582 1.1 christos BI res = ((UHI) a < (UHI) b) || (c && a == b);
583 1.1 christos return res;
584 1.1 christos }
585 1.1 christos
586 1.1 christos SEMOPS_INLINE BI
587 1.1 christos SUBOFHI (HI a, HI b, BI c)
588 1.1 christos {
589 1.1 christos HI tmp = SUBHI (a, ADDHI (b, c));
590 1.1 christos BI res = (((a < 0) != (b < 0))
591 1.1 christos && ((a < 0) != (tmp < 0)));
592 1.1 christos return res;
593 1.1 christos }
594 1.1 christos
595 1.1 christos SEMOPS_INLINE QI
596 1.1 christos ADDCQI (QI a, QI b, BI c)
597 1.1 christos {
598 1.1 christos QI res = ADDQI (a, ADDQI (b, c));
599 1.1 christos return res;
600 1.1 christos }
601 1.1 christos
602 1.1 christos SEMOPS_INLINE BI
603 1.1 christos ADDCFQI (QI a, QI b, BI c)
604 1.1 christos {
605 1.1 christos QI tmp = ADDQI (a, ADDQI (b, c));
606 1.1 christos BI res = ((UQI) tmp < (UQI) a) || (c && tmp == a);
607 1.1 christos return res;
608 1.1 christos }
609 1.1 christos
610 1.1 christos SEMOPS_INLINE BI
611 1.1 christos ADDOFQI (QI a, QI b, BI c)
612 1.1 christos {
613 1.1 christos QI tmp = ADDQI (a, ADDQI (b, c));
614 1.1 christos BI res = (((a < 0) == (b < 0))
615 1.1 christos && ((a < 0) != (tmp < 0)));
616 1.1 christos return res;
617 1.1 christos }
618 1.1 christos
619 1.1 christos SEMOPS_INLINE QI
620 1.1 christos SUBCQI (QI a, QI b, BI c)
621 1.1 christos {
622 1.1 christos QI res = SUBQI (a, ADDQI (b, c));
623 1.1 christos return res;
624 1.1 christos }
625 1.1 christos
626 1.1 christos SEMOPS_INLINE BI
627 1.1 christos SUBCFQI (QI a, QI b, BI c)
628 1.1 christos {
629 1.1 christos BI res = ((UQI) a < (UQI) b) || (c && a == b);
630 1.1 christos return res;
631 1.1 christos }
632 1.1 christos
633 1.1 christos SEMOPS_INLINE BI
634 1.1 christos SUBOFQI (QI a, QI b, BI c)
635 1.1 christos {
636 1.1 christos QI tmp = SUBQI (a, ADDQI (b, c));
637 1.1 christos BI res = (((a < 0) != (b < 0))
638 1.1 christos && ((a < 0) != (tmp < 0)));
639 1.1 christos return res;
640 1.1 christos }
641 1.1 christos
642 1.1 christos #else
643 1.1 christos
644 1.1 christos SI ADDCSI (SI, SI, BI);
645 1.1 christos UBI ADDCFSI (SI, SI, BI);
646 1.1 christos UBI ADDOFSI (SI, SI, BI);
647 1.1 christos SI SUBCSI (SI, SI, BI);
648 1.1 christos UBI SUBCFSI (SI, SI, BI);
649 1.1 christos UBI SUBOFSI (SI, SI, BI);
650 1.1 christos HI ADDCHI (HI, HI, BI);
651 1.1 christos UBI ADDCFHI (HI, HI, BI);
652 1.1 christos UBI ADDOFHI (HI, HI, BI);
653 1.1 christos HI SUBCHI (HI, HI, BI);
654 1.1 christos UBI SUBCFHI (HI, HI, BI);
655 1.1 christos UBI SUBOFHI (HI, HI, BI);
656 1.1 christos QI ADDCQI (QI, QI, BI);
657 UBI ADDCFQI (QI, QI, BI);
658 UBI ADDOFQI (QI, QI, BI);
659 QI SUBCQI (QI, QI, BI);
660 UBI SUBCFQI (QI, QI, BI);
661 UBI SUBOFQI (QI, QI, BI);
662
663 #endif
664
665 #endif /* CGEN_SEM_OPS_H */
666