This commit was generated by cvs2svn to track changes on a CVS vendor
[deliverable/binutils-gdb.git] / sim / common / cgen-ops.h
1
2 /* Semantics ops support for CGEN-based simulators.
3 Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
4 Contributed by Cygnus Solutions.
5
6 This file is part of the GNU Simulators.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
22 */
23
24 #ifndef CGEN_SEM_OPS_H
25 #define CGEN_SEM_OPS_H
26
27 #if defined (__GNUC__) && ! defined (SEMOPS_DEFINE_INLINE)
28 #define SEMOPS_DEFINE_INLINE
29 #define SEMOPS_INLINE extern inline
30 #else
31 #define SEMOPS_INLINE
32 #endif
33
34 /* Semantic operations.
35 At one point this file was machine generated. Maybe it will be again. */
36
37 /* TODO: Lazy encoding/decoding of fp values. */
38
39 /* These don't really have a mode. */
40 #define ANDIF(x, y) ((x) && (y))
41 #define ORIF(x, y) ((x) || (y))
42
43 #define ANDBI(x, y) ((x) & (y))
44 #define ORBI(x, y) ((x) | (y))
45 #define XORBI(x, y) ((x) ^ (y))
46 #define NEGBI(x) (- (x))
47 #define NOTBI(x) (! (BI) (x))
48 #define INVBI(x) (~ (x))
49 #define EQBI(x, y) ((BI) (x) == (BI) (y))
50 #define NEBI(x, y) ((BI) (x) != (BI) (y))
51 #define LTBI(x, y) ((BI) (x) < (BI) (y))
52 #define LEBI(x, y) ((BI) (x) <= (BI) (y))
53 #define GTBI(x, y) ((BI) (x) > (BI) (y))
54 #define GEBI(x, y) ((BI) (x) >= (BI) (y))
55 #define LTUBI(x, y) ((BI) (x) < (BI) (y))
56 #define LEUBI(x, y) ((BI) (x) <= (BI) (y))
57 #define GTUBI(x, y) ((BI) (x) > (BI) (y))
58 #define GEUBI(x, y) ((BI) (x) >= (BI) (y))
59 \f
60 #define ADDQI(x, y) ((x) + (y))
61 #define SUBQI(x, y) ((x) - (y))
62 #define MULQI(x, y) ((x) * (y))
63 #define DIVQI(x, y) ((QI) (x) / (QI) (y))
64 #define UDIVQI(x, y) ((UQI) (x) / (UQI) (y))
65 #define MODQI(x, y) ((QI) (x) % (QI) (y))
66 #define UMODQI(x, y) ((UQI) (x) % (UQI) (y))
67 #define SRAQI(x, y) ((QI) (x) >> (y))
68 #define SRLQI(x, y) ((UQI) (x) >> (y))
69 #define SLLQI(x, y) ((UQI) (x) << (y))
70 extern QI RORQI (QI, int);
71 extern QI ROLQI (QI, int);
72 #define ANDQI(x, y) ((x) & (y))
73 #define ORQI(x, y) ((x) | (y))
74 #define XORQI(x, y) ((x) ^ (y))
75 #define NEGQI(x) (- (x))
76 #define NOTQI(x) (! (QI) (x))
77 #define INVQI(x) (~ (x))
78 #define EQQI(x, y) ((QI) (x) == (QI) (y))
79 #define NEQI(x, y) ((QI) (x) != (QI) (y))
80 #define LTQI(x, y) ((QI) (x) < (QI) (y))
81 #define LEQI(x, y) ((QI) (x) <= (QI) (y))
82 #define GTQI(x, y) ((QI) (x) > (QI) (y))
83 #define GEQI(x, y) ((QI) (x) >= (QI) (y))
84 #define LTUQI(x, y) ((UQI) (x) < (UQI) (y))
85 #define LEUQI(x, y) ((UQI) (x) <= (UQI) (y))
86 #define GTUQI(x, y) ((UQI) (x) > (UQI) (y))
87 #define GEUQI(x, y) ((UQI) (x) >= (UQI) (y))
88 \f
89 #define ADDHI(x, y) ((x) + (y))
90 #define SUBHI(x, y) ((x) - (y))
91 #define MULHI(x, y) ((x) * (y))
92 #define DIVHI(x, y) ((HI) (x) / (HI) (y))
93 #define UDIVHI(x, y) ((UHI) (x) / (UHI) (y))
94 #define MODHI(x, y) ((HI) (x) % (HI) (y))
95 #define UMODHI(x, y) ((UHI) (x) % (UHI) (y))
96 #define SRAHI(x, y) ((HI) (x) >> (y))
97 #define SRLHI(x, y) ((UHI) (x) >> (y))
98 #define SLLHI(x, y) ((UHI) (x) << (y))
99 extern HI RORHI (HI, int);
100 extern HI ROLHI (HI, int);
101 #define ANDHI(x, y) ((x) & (y))
102 #define ORHI(x, y) ((x) | (y))
103 #define XORHI(x, y) ((x) ^ (y))
104 #define NEGHI(x) (- (x))
105 #define NOTHI(x) (! (HI) (x))
106 #define INVHI(x) (~ (x))
107 #define EQHI(x, y) ((HI) (x) == (HI) (y))
108 #define NEHI(x, y) ((HI) (x) != (HI) (y))
109 #define LTHI(x, y) ((HI) (x) < (HI) (y))
110 #define LEHI(x, y) ((HI) (x) <= (HI) (y))
111 #define GTHI(x, y) ((HI) (x) > (HI) (y))
112 #define GEHI(x, y) ((HI) (x) >= (HI) (y))
113 #define LTUHI(x, y) ((UHI) (x) < (UHI) (y))
114 #define LEUHI(x, y) ((UHI) (x) <= (UHI) (y))
115 #define GTUHI(x, y) ((UHI) (x) > (UHI) (y))
116 #define GEUHI(x, y) ((UHI) (x) >= (UHI) (y))
117 \f
118 #define ADDSI(x, y) ((x) + (y))
119 #define SUBSI(x, y) ((x) - (y))
120 #define MULSI(x, y) ((x) * (y))
121 #define DIVSI(x, y) ((SI) (x) / (SI) (y))
122 #define UDIVSI(x, y) ((USI) (x) / (USI) (y))
123 #define MODSI(x, y) ((SI) (x) % (SI) (y))
124 #define UMODSI(x, y) ((USI) (x) % (USI) (y))
125 #define SRASI(x, y) ((SI) (x) >> (y))
126 #define SRLSI(x, y) ((USI) (x) >> (y))
127 #define SLLSI(x, y) ((USI) (x) << (y))
128 extern SI RORSI (SI, int);
129 extern SI ROLSI (SI, int);
130 #define ANDSI(x, y) ((x) & (y))
131 #define ORSI(x, y) ((x) | (y))
132 #define XORSI(x, y) ((x) ^ (y))
133 #define NEGSI(x) (- (x))
134 #define NOTSI(x) (! (SI) (x))
135 #define INVSI(x) (~ (x))
136 #define EQSI(x, y) ((SI) (x) == (SI) (y))
137 #define NESI(x, y) ((SI) (x) != (SI) (y))
138 #define LTSI(x, y) ((SI) (x) < (SI) (y))
139 #define LESI(x, y) ((SI) (x) <= (SI) (y))
140 #define GTSI(x, y) ((SI) (x) > (SI) (y))
141 #define GESI(x, y) ((SI) (x) >= (SI) (y))
142 #define LTUSI(x, y) ((USI) (x) < (USI) (y))
143 #define LEUSI(x, y) ((USI) (x) <= (USI) (y))
144 #define GTUSI(x, y) ((USI) (x) > (USI) (y))
145 #define GEUSI(x, y) ((USI) (x) >= (USI) (y))
146 \f
147 #ifdef DI_FN_SUPPORT
148 extern DI ADDDI (DI, DI);
149 extern DI SUBDI (DI, DI);
150 extern DI MULDI (DI, DI);
151 extern DI DIVDI (DI, DI);
152 extern DI UDIVDI (DI, DI);
153 extern DI MODDI (DI, DI);
154 extern DI UMODDI (DI, DI);
155 extern DI SRADI (DI, int);
156 extern UDI SRLDI (UDI, int);
157 extern UDI SLLDI (UDI, int);
158 extern DI RORDI (DI, int);
159 extern DI ROLDI (DI, int);
160 extern DI ANDDI (DI, DI);
161 extern DI ORDI (DI, DI);
162 extern DI XORDI (DI, DI);
163 extern DI NEGDI (DI);
164 extern int NOTDI (DI);
165 extern DI INVDI (DI);
166 extern int EQDI (DI, DI);
167 extern int NEDI (DI, DI);
168 extern int LTDI (DI, DI);
169 extern int LEDI (DI, DI);
170 extern int GTDI (DI, DI);
171 extern int GEDI (DI, DI);
172 extern int LTUDI (UDI, UDI);
173 extern int LEUDI (UDI, UDI);
174 extern int GTUDI (UDI, UDI);
175 extern int GEUDI (UDI, UDI);
176 #else /* ! DI_FN_SUPPORT */
177 #define ADDDI(x, y) ((x) + (y))
178 #define SUBDI(x, y) ((x) - (y))
179 #define MULDI(x, y) ((x) * (y))
180 #define DIVDI(x, y) ((DI) (x) / (DI) (y))
181 #define UDIVDI(x, y) ((UDI) (x) / (UDI) (y))
182 #define MODDI(x, y) ((DI) (x) % (DI) (y))
183 #define UMODDI(x, y) ((UDI) (x) % (UDI) (y))
184 #define SRADI(x, y) ((DI) (x) >> (y))
185 #define SRLDI(x, y) ((UDI) (x) >> (y))
186 #define SLLDI(x, y) ((UDI) (x) << (y))
187 extern DI RORDI (DI, int);
188 extern DI ROLDI (DI, int);
189 #define ANDDI(x, y) ((x) & (y))
190 #define ORDI(x, y) ((x) | (y))
191 #define XORDI(x, y) ((x) ^ (y))
192 #define NEGDI(x) (- (x))
193 #define NOTDI(x) (! (DI) (x))
194 #define INVDI(x) (~ (x))
195 #define EQDI(x, y) ((DI) (x) == (DI) (y))
196 #define NEDI(x, y) ((DI) (x) != (DI) (y))
197 #define LTDI(x, y) ((DI) (x) < (DI) (y))
198 #define LEDI(x, y) ((DI) (x) <= (DI) (y))
199 #define GTDI(x, y) ((DI) (x) > (DI) (y))
200 #define GEDI(x, y) ((DI) (x) >= (DI) (y))
201 #define LTUDI(x, y) ((UDI) (x) < (UDI) (y))
202 #define LEUDI(x, y) ((UDI) (x) <= (UDI) (y))
203 #define GTUDI(x, y) ((UDI) (x) > (UDI) (y))
204 #define GEUDI(x, y) ((UDI) (x) >= (UDI) (y))
205 #endif /* DI_FN_SUPPORT */
206 \f
207 #define EXTBIQI(x) ((QI) (BI) (x))
208 #define EXTBIHI(x) ((HI) (BI) (x))
209 #define EXTBISI(x) ((SI) (BI) (x))
210 #if defined (DI_FN_SUPPORT)
211 extern DI EXTBIDI (BI);
212 #else
213 #define EXTBIDI(x) ((DI) (BI) (x))
214 #endif
215 #define EXTQIHI(x) ((HI) (QI) (x))
216 #define EXTQISI(x) ((SI) (QI) (x))
217 #if defined (DI_FN_SUPPORT)
218 extern DI EXTQIDI (QI);
219 #else
220 #define EXTQIDI(x) ((DI) (QI) (x))
221 #endif
222 #define EXTHISI(x) ((SI) (HI) (x))
223 #if defined (DI_FN_SUPPORT)
224 extern DI EXTHIDI (HI);
225 #else
226 #define EXTHIDI(x) ((DI) (HI) (x))
227 #endif
228 #if defined (DI_FN_SUPPORT)
229 extern DI EXTSIDI (SI);
230 #else
231 #define EXTSIDI(x) ((DI) (SI) (x))
232 #endif
233 \f
234 #define ZEXTBIQI(x) ((QI) (BI) (x))
235 #define ZEXTBIHI(x) ((HI) (BI) (x))
236 #define ZEXTBISI(x) ((SI) (BI) (x))
237 #if defined (DI_FN_SUPPORT)
238 extern DI ZEXTBIDI (BI);
239 #else
240 #define ZEXTBIDI(x) ((DI) (BI) (x))
241 #endif
242 #define ZEXTQIHI(x) ((HI) (UQI) (x))
243 #define ZEXTQISI(x) ((SI) (UQI) (x))
244 #if defined (DI_FN_SUPPORT)
245 extern DI ZEXTQIDI (QI);
246 #else
247 #define ZEXTQIDI(x) ((DI) (UQI) (x))
248 #endif
249 #define ZEXTHISI(x) ((SI) (UHI) (x))
250 #if defined (DI_FN_SUPPORT)
251 extern DI ZEXTHIDI (HI);
252 #else
253 #define ZEXTHIDI(x) ((DI) (UHI) (x))
254 #endif
255 #if defined (DI_FN_SUPPORT)
256 extern DI ZEXTSIDI (SI);
257 #else
258 #define ZEXTSIDI(x) ((DI) (USI) (x))
259 #endif
260 \f
261 #define TRUNCQIBI(x) ((BI) (QI) (x))
262 #define TRUNCHIBI(x) ((BI) (HI) (x))
263 #define TRUNCHIQI(x) ((QI) (HI) (x))
264 #define TRUNCSIBI(x) ((BI) (SI) (x))
265 #define TRUNCSIQI(x) ((QI) (SI) (x))
266 #define TRUNCSIHI(x) ((HI) (SI) (x))
267 #if defined (DI_FN_SUPPORT)
268 extern BI TRUNCDIBI (DI);
269 #else
270 #define TRUNCDIBI(x) ((BI) (DI) (x))
271 #endif
272 #if defined (DI_FN_SUPPORT)
273 extern QI TRUNCDIQI (DI);
274 #else
275 #define TRUNCDIQI(x) ((QI) (DI) (x))
276 #endif
277 #if defined (DI_FN_SUPPORT)
278 extern HI TRUNCDIHI (DI);
279 #else
280 #define TRUNCDIHI(x) ((HI) (DI) (x))
281 #endif
282 #if defined (DI_FN_SUPPORT)
283 extern SI TRUNCDISI (DI);
284 #else
285 #define TRUNCDISI(x) ((SI) (DI) (x))
286 #endif
287 \f
288 /* Composing/decomposing the various types. */
289
290 /* ??? endianness issues undecided */
291 /* ??? CURRENT_TARGET_BYTE_ORDER usage wip */
292
293 #ifdef SEMOPS_DEFINE_INLINE
294
295 SEMOPS_INLINE SF
296 SUBWORDSISF (SIM_CPU *cpu, SI in)
297 {
298 union { SI in; SF out; } x;
299 x.in = in;
300 return x.out;
301 }
302
303 SEMOPS_INLINE SI
304 SUBWORDSFSI (SIM_CPU *cpu, SF in)
305 {
306 union { SF in; SI out; } x;
307 x.in = in;
308 return x.out;
309 }
310
311 SEMOPS_INLINE SI
312 SUBWORDDISI (SIM_CPU *cpu, DI in, int word)
313 {
314 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
315 {
316 if (word == 0)
317 return (UDI) in >> 32;
318 else
319 return in;
320 }
321 else
322 {
323 if (word == 1)
324 return (UDI) in >> 32;
325 else
326 return in;
327 }
328 }
329
330 SEMOPS_INLINE SI
331 SUBWORDDFSI (SIM_CPU *cpu, DF in, int word)
332 {
333 union { DF in; SI out[2]; } x;
334 x.in = in;
335 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
336 return x.out[word];
337 else
338 return x.out[!word];
339 }
340
341 SEMOPS_INLINE SI
342 SUBWORDXFSI (SIM_CPU *cpu, XF in, int word)
343 {
344 union { XF in; SI out[3]; } x;
345 x.in = in;
346 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
347 return x.out[word];
348 else
349 return x.out[2 - word];
350 }
351
352 SEMOPS_INLINE SI
353 SUBWORDTFSI (SIM_CPU *cpu, TF in, int word)
354 {
355 union { TF in; SI out[4]; } x;
356 x.in = in;
357 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
358 return x.out[word];
359 else
360 return x.out[3 - word];
361 }
362
363 SEMOPS_INLINE DI
364 JOINSIDI (SIM_CPU *cpu, SI x0, SI x1)
365 {
366 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
367 return MAKEDI (x0, x1);
368 else
369 return MAKEDI (x1, x0);
370 }
371
372 SEMOPS_INLINE DF
373 JOINSIDF (SIM_CPU *cpu, SI x0, SI x1)
374 {
375 union { SI in[2]; DF out; } x;
376 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
377 x.in[0] = x0, x.in[1] = x1;
378 else
379 x.in[1] = x0, x.in[0] = x1;
380 return x.out;
381 }
382
383 SEMOPS_INLINE XF
384 JOINSIXF (SIM_CPU *cpu, SI x0, SI x1, SI x2)
385 {
386 union { SI in[3]; XF out; } x;
387 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
388 x.in[0] = x0, x.in[1] = x1, x.in[2] = x2;
389 else
390 x.in[2] = x0, x.in[1] = x1, x.in[0] = x2;
391 return x.out;
392 }
393
394 SEMOPS_INLINE TF
395 JOINSITF (SIM_CPU *cpu, SI x0, SI x1, SI x2, SI x3)
396 {
397 union { SI in[4]; TF out; } x;
398 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
399 x.in[0] = x0, x.in[1] = x1, x.in[2] = x2, x.in[3] = x3;
400 else
401 x.in[3] = x0, x.in[2] = x1, x.in[1] = x2, x.in[0] = x3;
402 return x.out;
403 }
404
405 #else
406
407 SF SUBWORDSISF (SIM_CPU *, SI);
408 SI SUBWORDSFSI (SIM_CPU *, SF);
409 SI SUBWORDDISI (SIM_CPU *, DI, int);
410 SI SUBWORDDFSI (SIM_CPU *, DF, int);
411 SI SUBWORDXFSI (SIM_CPU *, XF, int);
412 SI SUBWORDTFSI (SIM_CPU *, TF, int);
413
414 DI JOINSIDI (SIM_CPU *, SI, SI);
415 DF JOINSIDF (SIM_CPU *, SI, SI);
416 XF JOINSIXF (SIM_CPU *, SI, SI, SI);
417 TF JOINSITF (SIM_CPU *, SI, SI, SI, SI);
418
419 #endif /* SUBWORD,JOIN */
420 \f
421 /* Semantic support utilities. */
422
423 #ifdef SEMOPS_DEFINE_INLINE
424
425 SEMOPS_INLINE SI
426 ADDCSI (SI a, SI b, BI c)
427 {
428 SI res = ADDSI (a, ADDSI (b, c));
429 return res;
430 }
431
432 SEMOPS_INLINE BI
433 ADDCFSI (SI a, SI b, BI c)
434 {
435 SI tmp = ADDSI (a, ADDSI (b, c));
436 BI res = ((USI) tmp < (USI) a) || (c && tmp == a);
437 return res;
438 }
439
440 SEMOPS_INLINE BI
441 ADDOFSI (SI a, SI b, BI c)
442 {
443 SI tmp = ADDSI (a, ADDSI (b, c));
444 BI res = (((a < 0) == (b < 0))
445 && ((a < 0) != (tmp < 0)));
446 return res;
447 }
448
449 SEMOPS_INLINE SI
450 SUBCSI (SI a, SI b, BI c)
451 {
452 SI res = SUBSI (a, ADDSI (b, c));
453 return res;
454 }
455
456 SEMOPS_INLINE BI
457 SUBCFSI (SI a, SI b, BI c)
458 {
459 BI res = ((USI) a < (USI) b) || (c && a == b);
460 return res;
461 }
462
463 SEMOPS_INLINE BI
464 SUBOFSI (SI a, SI b, BI c)
465 {
466 SI tmp = SUBSI (a, ADDSI (b, c));
467 BI res = (((a < 0) != (b < 0))
468 && ((a < 0) != (tmp < 0)));
469 return res;
470 }
471
472 #else
473
474 SI ADDCSI (SI, SI, BI);
475 UBI ADDCFSI (SI, SI, BI);
476 UBI ADDOFSI (SI, SI, BI);
477 SI SUBCSI (SI, SI, BI);
478 UBI SUBCFSI (SI, SI, BI);
479 UBI SUBOFSI (SI, SI, BI);
480
481 #endif
482
483 #endif /* CGEN_SEM_OPS_H */
This page took 0.063422 seconds and 5 git commands to generate.