Remove use of a GCC extension when allocating local arrays.
[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))
77#define EQQI(x, y) ((QI) (x) == (QI) (y))
78#define NEQI(x, y) ((QI) (x) != (QI) (y))
79#define LTQI(x, y) ((QI) (x) < (QI) (y))
80#define LEQI(x, y) ((QI) (x) <= (QI) (y))
81#define GTQI(x, y) ((QI) (x) > (QI) (y))
82#define GEQI(x, y) ((QI) (x) >= (QI) (y))
83#define LTUQI(x, y) ((UQI) (x) < (UQI) (y))
84#define LEUQI(x, y) ((UQI) (x) <= (UQI) (y))
85#define GTUQI(x, y) ((UQI) (x) > (UQI) (y))
86#define GEUQI(x, y) ((UQI) (x) >= (UQI) (y))
43ff13b4 87\f
c906108c
SS
88#define ADDHI(x, y) ((x) + (y))
89#define SUBHI(x, y) ((x) - (y))
90#define MULHI(x, y) ((x) * (y))
91#define DIVHI(x, y) ((HI) (x) / (HI) (y))
92#define UDIVHI(x, y) ((UHI) (x) / (UHI) (y))
93#define MODHI(x, y) ((HI) (x) % (HI) (y))
94#define UMODHI(x, y) ((UHI) (x) % (UHI) (y))
95#define SRAHI(x, y) ((HI) (x) >> (y))
96#define SRLHI(x, y) ((UHI) (x) >> (y))
97#define SLLHI(x, y) ((UHI) (x) << (y))
43ff13b4
JM
98extern HI RORHI (HI, int);
99extern HI ROLHI (HI, int);
c906108c
SS
100#define ANDHI(x, y) ((x) & (y))
101#define ORHI(x, y) ((x) | (y))
102#define XORHI(x, y) ((x) ^ (y))
103#define NEGHI(x) (- (x))
104#define NOTHI(x) (! (HI) (x))
105#define INVHI(x) (~ (x))
106#define EQHI(x, y) ((HI) (x) == (HI) (y))
107#define NEHI(x, y) ((HI) (x) != (HI) (y))
108#define LTHI(x, y) ((HI) (x) < (HI) (y))
109#define LEHI(x, y) ((HI) (x) <= (HI) (y))
110#define GTHI(x, y) ((HI) (x) > (HI) (y))
111#define GEHI(x, y) ((HI) (x) >= (HI) (y))
112#define LTUHI(x, y) ((UHI) (x) < (UHI) (y))
113#define LEUHI(x, y) ((UHI) (x) <= (UHI) (y))
114#define GTUHI(x, y) ((UHI) (x) > (UHI) (y))
115#define GEUHI(x, y) ((UHI) (x) >= (UHI) (y))
43ff13b4 116\f
c906108c
SS
117#define ADDSI(x, y) ((x) + (y))
118#define SUBSI(x, y) ((x) - (y))
119#define MULSI(x, y) ((x) * (y))
120#define DIVSI(x, y) ((SI) (x) / (SI) (y))
121#define UDIVSI(x, y) ((USI) (x) / (USI) (y))
122#define MODSI(x, y) ((SI) (x) % (SI) (y))
123#define UMODSI(x, y) ((USI) (x) % (USI) (y))
124#define SRASI(x, y) ((SI) (x) >> (y))
125#define SRLSI(x, y) ((USI) (x) >> (y))
126#define SLLSI(x, y) ((USI) (x) << (y))
43ff13b4
JM
127extern SI RORSI (SI, int);
128extern SI ROLSI (SI, int);
c906108c
SS
129#define ANDSI(x, y) ((x) & (y))
130#define ORSI(x, y) ((x) | (y))
131#define XORSI(x, y) ((x) ^ (y))
132#define NEGSI(x) (- (x))
133#define NOTSI(x) (! (SI) (x))
134#define INVSI(x) (~ (x))
135#define EQSI(x, y) ((SI) (x) == (SI) (y))
136#define NESI(x, y) ((SI) (x) != (SI) (y))
137#define LTSI(x, y) ((SI) (x) < (SI) (y))
138#define LESI(x, y) ((SI) (x) <= (SI) (y))
139#define GTSI(x, y) ((SI) (x) > (SI) (y))
140#define GESI(x, y) ((SI) (x) >= (SI) (y))
141#define LTUSI(x, y) ((USI) (x) < (USI) (y))
142#define LEUSI(x, y) ((USI) (x) <= (USI) (y))
143#define GTUSI(x, y) ((USI) (x) > (USI) (y))
144#define GEUSI(x, y) ((USI) (x) >= (USI) (y))
43ff13b4 145\f
c906108c 146#ifdef DI_FN_SUPPORT
43ff13b4
JM
147extern DI ADDDI (DI, DI);
148extern DI SUBDI (DI, DI);
149extern DI MULDI (DI, DI);
150extern DI DIVDI (DI, DI);
151extern DI UDIVDI (DI, DI);
152extern DI MODDI (DI, DI);
153extern DI UMODDI (DI, DI);
154extern DI SRADI (DI, int);
155extern UDI SRLDI (UDI, int);
156extern UDI SLLDI (UDI, int);
157extern DI RORDI (DI, int);
158extern DI ROLDI (DI, int);
159extern DI ANDDI (DI, DI);
160extern DI ORDI (DI, DI);
161extern DI XORDI (DI, DI);
162extern DI NEGDI (DI);
163extern int NOTDI (DI);
164extern DI INVDI (DI);
165extern int EQDI (DI, DI);
166extern int NEDI (DI, DI);
167extern int LTDI (DI, DI);
168extern int LEDI (DI, DI);
169extern int GTDI (DI, DI);
170extern int GEDI (DI, DI);
171extern int LTUDI (UDI, UDI);
172extern int LEUDI (UDI, UDI);
173extern int GTUDI (UDI, UDI);
174extern int GEUDI (UDI, UDI);
c906108c
SS
175#else /* ! DI_FN_SUPPORT */
176#define ADDDI(x, y) ((x) + (y))
177#define SUBDI(x, y) ((x) - (y))
178#define MULDI(x, y) ((x) * (y))
179#define DIVDI(x, y) ((DI) (x) / (DI) (y))
180#define UDIVDI(x, y) ((UDI) (x) / (UDI) (y))
181#define MODDI(x, y) ((DI) (x) % (DI) (y))
182#define UMODDI(x, y) ((UDI) (x) % (UDI) (y))
183#define SRADI(x, y) ((DI) (x) >> (y))
184#define SRLDI(x, y) ((UDI) (x) >> (y))
185#define SLLDI(x, y) ((UDI) (x) << (y))
43ff13b4
JM
186extern DI RORDI (DI, int);
187extern DI ROLDI (DI, int);
c906108c
SS
188#define ANDDI(x, y) ((x) & (y))
189#define ORDI(x, y) ((x) | (y))
190#define XORDI(x, y) ((x) ^ (y))
191#define NEGDI(x) (- (x))
192#define NOTDI(x) (! (DI) (x))
193#define INVDI(x) (~ (x))
194#define EQDI(x, y) ((DI) (x) == (DI) (y))
195#define NEDI(x, y) ((DI) (x) != (DI) (y))
196#define LTDI(x, y) ((DI) (x) < (DI) (y))
197#define LEDI(x, y) ((DI) (x) <= (DI) (y))
198#define GTDI(x, y) ((DI) (x) > (DI) (y))
199#define GEDI(x, y) ((DI) (x) >= (DI) (y))
200#define LTUDI(x, y) ((UDI) (x) < (UDI) (y))
201#define LEUDI(x, y) ((UDI) (x) <= (UDI) (y))
202#define GTUDI(x, y) ((UDI) (x) > (UDI) (y))
203#define GEUDI(x, y) ((UDI) (x) >= (UDI) (y))
204#endif /* DI_FN_SUPPORT */
43ff13b4 205\f
c906108c
SS
206#define EXTBIQI(x) ((QI) (BI) (x))
207#define EXTBIHI(x) ((HI) (BI) (x))
208#define EXTBISI(x) ((SI) (BI) (x))
209#if defined (DI_FN_SUPPORT)
43ff13b4 210extern DI EXTBIDI (BI);
c906108c
SS
211#else
212#define EXTBIDI(x) ((DI) (BI) (x))
213#endif
214#define EXTQIHI(x) ((HI) (QI) (x))
215#define EXTQISI(x) ((SI) (QI) (x))
216#if defined (DI_FN_SUPPORT)
43ff13b4 217extern DI EXTQIDI (QI);
c906108c
SS
218#else
219#define EXTQIDI(x) ((DI) (QI) (x))
220#endif
221#define EXTHISI(x) ((SI) (HI) (x))
222#if defined (DI_FN_SUPPORT)
43ff13b4 223extern DI EXTHIDI (HI);
c906108c
SS
224#else
225#define EXTHIDI(x) ((DI) (HI) (x))
226#endif
227#if defined (DI_FN_SUPPORT)
43ff13b4 228extern DI EXTSIDI (SI);
c906108c
SS
229#else
230#define EXTSIDI(x) ((DI) (SI) (x))
231#endif
43ff13b4 232\f
c906108c
SS
233#define ZEXTBIQI(x) ((QI) (BI) (x))
234#define ZEXTBIHI(x) ((HI) (BI) (x))
235#define ZEXTBISI(x) ((SI) (BI) (x))
236#if defined (DI_FN_SUPPORT)
43ff13b4 237extern DI ZEXTBIDI (BI);
c906108c
SS
238#else
239#define ZEXTBIDI(x) ((DI) (BI) (x))
240#endif
241#define ZEXTQIHI(x) ((HI) (UQI) (x))
242#define ZEXTQISI(x) ((SI) (UQI) (x))
243#if defined (DI_FN_SUPPORT)
43ff13b4 244extern DI ZEXTQIDI (QI);
c906108c
SS
245#else
246#define ZEXTQIDI(x) ((DI) (UQI) (x))
247#endif
248#define ZEXTHISI(x) ((SI) (UHI) (x))
249#if defined (DI_FN_SUPPORT)
43ff13b4 250extern DI ZEXTHIDI (HI);
c906108c
SS
251#else
252#define ZEXTHIDI(x) ((DI) (UHI) (x))
253#endif
254#if defined (DI_FN_SUPPORT)
43ff13b4 255extern DI ZEXTSIDI (SI);
c906108c
SS
256#else
257#define ZEXTSIDI(x) ((DI) (USI) (x))
258#endif
43ff13b4 259\f
c906108c
SS
260#define TRUNCQIBI(x) ((BI) (QI) (x))
261#define TRUNCHIBI(x) ((BI) (HI) (x))
262#define TRUNCHIQI(x) ((QI) (HI) (x))
263#define TRUNCSIBI(x) ((BI) (SI) (x))
264#define TRUNCSIQI(x) ((QI) (SI) (x))
265#define TRUNCSIHI(x) ((HI) (SI) (x))
266#if defined (DI_FN_SUPPORT)
43ff13b4 267extern BI TRUNCDIBI (DI);
c906108c
SS
268#else
269#define TRUNCDIBI(x) ((BI) (DI) (x))
270#endif
271#if defined (DI_FN_SUPPORT)
43ff13b4 272extern QI TRUNCDIQI (DI);
c906108c
SS
273#else
274#define TRUNCDIQI(x) ((QI) (DI) (x))
275#endif
276#if defined (DI_FN_SUPPORT)
43ff13b4 277extern HI TRUNCDIHI (DI);
c906108c
SS
278#else
279#define TRUNCDIHI(x) ((HI) (DI) (x))
280#endif
281#if defined (DI_FN_SUPPORT)
43ff13b4 282extern SI TRUNCDISI (DI);
c906108c
SS
283#else
284#define TRUNCDISI(x) ((SI) (DI) (x))
285#endif
c906108c 286\f
6426a772
JM
287/* Composing/decomposing the various types.
288 Word ordering is endian-independent. Words are specified most to least
289 significant and word number 0 is the most significant word.
290 ??? May also wish an endian-dependent version. Later. */
43ff13b4 291
c906108c 292#ifdef SEMOPS_DEFINE_INLINE
7a292a7a
SS
293
294SEMOPS_INLINE SF
6426a772 295SUBWORDSISF (SI in)
7a292a7a
SS
296{
297 union { SI in; SF out; } x;
298 x.in = in;
299 return x.out;
300}
301
302SEMOPS_INLINE SI
6426a772 303SUBWORDSFSI (SF in)
7a292a7a
SS
304{
305 union { SF in; SI out; } x;
306 x.in = in;
307 return x.out;
308}
309
310SEMOPS_INLINE SI
6426a772 311SUBWORDDISI (DI in, int word)
7a292a7a 312{
6426a772
JM
313 if (word == 0)
314 return (UDI) in >> 32;
7a292a7a 315 else
6426a772 316 return in;
7a292a7a
SS
317}
318
319SEMOPS_INLINE SI
6426a772 320SUBWORDDFSI (DF in, int word)
7a292a7a 321{
6426a772
JM
322 /* Note: typedef UDI DF; */
323 if (word == 0)
324 return (UDI) in >> 32;
7a292a7a 325 else
6426a772 326 return in;
7a292a7a
SS
327}
328
43ff13b4 329SEMOPS_INLINE SI
6426a772 330SUBWORDXFSI (XF in, int word)
43ff13b4 331{
6426a772 332 /* Note: typedef struct { SI parts[3]; } XF; */
43ff13b4
JM
333 union { XF in; SI out[3]; } x;
334 x.in = in;
6426a772 335 return x.out[word];
43ff13b4
JM
336}
337
7a292a7a 338SEMOPS_INLINE SI
6426a772 339SUBWORDTFSI (TF in, int word)
7a292a7a 340{
6426a772 341 /* Note: typedef struct { SI parts[4]; } TF; */
7a292a7a
SS
342 union { TF in; SI out[4]; } x;
343 x.in = in;
6426a772 344 return x.out[word];
7a292a7a
SS
345}
346
347SEMOPS_INLINE DI
6426a772 348JOINSIDI (SI x0, SI x1)
7a292a7a
SS
349{
350 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
351 return MAKEDI (x0, x1);
352 else
353 return MAKEDI (x1, x0);
354}
355
356SEMOPS_INLINE DF
6426a772 357JOINSIDF (SI x0, SI x1)
7a292a7a
SS
358{
359 union { SI in[2]; DF out; } x;
360 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
361 x.in[0] = x0, x.in[1] = x1;
362 else
363 x.in[1] = x0, x.in[0] = x1;
364 return x.out;
365}
366
43ff13b4 367SEMOPS_INLINE XF
6426a772 368JOINSIXF (SI x0, SI x1, SI x2)
43ff13b4
JM
369{
370 union { SI in[3]; XF out; } x;
371 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
372 x.in[0] = x0, x.in[1] = x1, x.in[2] = x2;
373 else
374 x.in[2] = x0, x.in[1] = x1, x.in[0] = x2;
375 return x.out;
376}
377
7a292a7a 378SEMOPS_INLINE TF
6426a772 379JOINSITF (SI x0, SI x1, SI x2, SI x3)
7a292a7a
SS
380{
381 union { SI in[4]; TF out; } x;
382 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
383 x.in[0] = x0, x.in[1] = x1, x.in[2] = x2, x.in[3] = x3;
384 else
385 x.in[3] = x0, x.in[2] = x1, x.in[1] = x2, x.in[0] = x3;
386 return x.out;
387}
388
c906108c 389#else
7a292a7a 390
6426a772
JM
391SF SUBWORDSISF (SI);
392SI SUBWORDSFSI (SF);
393SI SUBWORDDISI (DI, int);
394SI SUBWORDDFSI (DF, int);
395SI SUBWORDXFSI (XF, int);
396SI SUBWORDTFSI (TF, int);
7a292a7a 397
6426a772
JM
398DI JOINSIDI (SI, SI);
399DF JOINSIDF (SI, SI);
400XF JOINSIXF (SI, SI, SI);
401TF JOINSITF (SI, SI, SI, SI);
7a292a7a
SS
402
403#endif /* SUBWORD,JOIN */
404\f
405/* Semantic support utilities. */
406
407#ifdef SEMOPS_DEFINE_INLINE
c906108c
SS
408
409SEMOPS_INLINE SI
410ADDCSI (SI a, SI b, BI c)
411{
412 SI res = ADDSI (a, ADDSI (b, c));
413 return res;
414}
415
416SEMOPS_INLINE BI
417ADDCFSI (SI a, SI b, BI c)
418{
419 SI tmp = ADDSI (a, ADDSI (b, c));
420 BI res = ((USI) tmp < (USI) a) || (c && tmp == a);
421 return res;
422}
423
424SEMOPS_INLINE BI
425ADDOFSI (SI a, SI b, BI c)
426{
427 SI tmp = ADDSI (a, ADDSI (b, c));
428 BI res = (((a < 0) == (b < 0))
429 && ((a < 0) != (tmp < 0)));
430 return res;
431}
432
433SEMOPS_INLINE SI
434SUBCSI (SI a, SI b, BI c)
435{
436 SI res = SUBSI (a, ADDSI (b, c));
437 return res;
438}
439
440SEMOPS_INLINE BI
441SUBCFSI (SI a, SI b, BI c)
442{
443 BI res = ((USI) a < (USI) b) || (c && a == b);
444 return res;
445}
446
447SEMOPS_INLINE BI
448SUBOFSI (SI a, SI b, BI c)
449{
450 SI tmp = SUBSI (a, ADDSI (b, c));
451 BI res = (((a < 0) != (b < 0))
452 && ((a < 0) != (tmp < 0)));
453 return res;
454}
455
456#else
457
458SI ADDCSI (SI, SI, BI);
459UBI ADDCFSI (SI, SI, BI);
460UBI ADDOFSI (SI, SI, BI);
461SI SUBCSI (SI, SI, BI);
462UBI SUBCFSI (SI, SI, BI);
463UBI SUBOFSI (SI, SI, BI);
464
465#endif
c906108c
SS
466
467#endif /* CGEN_SEM_OPS_H */
This page took 0.063881 seconds and 4 git commands to generate.