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