This commit was generated by cvs2svn to track changes on a CVS vendor
[deliverable/binutils-gdb.git] / sim / common / cgen-ops.h
CommitLineData
43ff13b4 1
c906108c 2/* Semantics ops support for CGEN-based simulators.
7a292a7a 3 Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
c906108c
SS
4 Contributed by Cygnus Solutions.
5
6This file is part of the GNU Simulators.
7
8This program is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2, or (at your option)
11any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License along
19with this program; if not, write to the Free Software Foundation, Inc.,
2059 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
7a292a7a
SS
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
c906108c
SS
34/* Semantic operations.
35 At one point this file was machine generated. Maybe it will be again. */
36
43ff13b4
JM
37/* TODO: Lazy encoding/decoding of fp values. */
38
c906108c
SS
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))
43ff13b4 59\f
c906108c
SS
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))
43ff13b4
JM
70extern QI RORQI (QI, int);
71extern QI ROLQI (QI, int);
c906108c
SS
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))
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))
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))
43ff13b4 117\f
c906108c
SS
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))
43ff13b4
JM
128extern SI RORSI (SI, int);
129extern SI ROLSI (SI, int);
c906108c
SS
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))
43ff13b4 146\f
c906108c 147#ifdef DI_FN_SUPPORT
43ff13b4
JM
148extern DI ADDDI (DI, DI);
149extern DI SUBDI (DI, DI);
150extern DI MULDI (DI, DI);
151extern DI DIVDI (DI, DI);
152extern DI UDIVDI (DI, DI);
153extern DI MODDI (DI, DI);
154extern DI UMODDI (DI, DI);
155extern DI SRADI (DI, int);
156extern UDI SRLDI (UDI, int);
157extern UDI SLLDI (UDI, int);
158extern DI RORDI (DI, int);
159extern DI ROLDI (DI, int);
160extern DI ANDDI (DI, DI);
161extern DI ORDI (DI, DI);
162extern DI XORDI (DI, DI);
163extern DI NEGDI (DI);
164extern int NOTDI (DI);
165extern DI INVDI (DI);
166extern int EQDI (DI, DI);
167extern int NEDI (DI, DI);
168extern int LTDI (DI, DI);
169extern int LEDI (DI, DI);
170extern int GTDI (DI, DI);
171extern int GEDI (DI, DI);
172extern int LTUDI (UDI, UDI);
173extern int LEUDI (UDI, UDI);
174extern int GTUDI (UDI, UDI);
175extern int GEUDI (UDI, UDI);
c906108c
SS
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))
43ff13b4
JM
187extern DI RORDI (DI, int);
188extern DI ROLDI (DI, int);
c906108c
SS
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 */
43ff13b4 206\f
c906108c
SS
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)
43ff13b4 211extern DI EXTBIDI (BI);
c906108c
SS
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)
43ff13b4 218extern DI EXTQIDI (QI);
c906108c
SS
219#else
220#define EXTQIDI(x) ((DI) (QI) (x))
221#endif
222#define EXTHISI(x) ((SI) (HI) (x))
223#if defined (DI_FN_SUPPORT)
43ff13b4 224extern DI EXTHIDI (HI);
c906108c
SS
225#else
226#define EXTHIDI(x) ((DI) (HI) (x))
227#endif
228#if defined (DI_FN_SUPPORT)
43ff13b4 229extern DI EXTSIDI (SI);
c906108c
SS
230#else
231#define EXTSIDI(x) ((DI) (SI) (x))
232#endif
43ff13b4 233\f
c906108c
SS
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)
43ff13b4 238extern DI ZEXTBIDI (BI);
c906108c
SS
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)
43ff13b4 245extern DI ZEXTQIDI (QI);
c906108c
SS
246#else
247#define ZEXTQIDI(x) ((DI) (UQI) (x))
248#endif
249#define ZEXTHISI(x) ((SI) (UHI) (x))
250#if defined (DI_FN_SUPPORT)
43ff13b4 251extern DI ZEXTHIDI (HI);
c906108c
SS
252#else
253#define ZEXTHIDI(x) ((DI) (UHI) (x))
254#endif
255#if defined (DI_FN_SUPPORT)
43ff13b4 256extern DI ZEXTSIDI (SI);
c906108c
SS
257#else
258#define ZEXTSIDI(x) ((DI) (USI) (x))
259#endif
43ff13b4 260\f
c906108c
SS
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)
43ff13b4 268extern BI TRUNCDIBI (DI);
c906108c
SS
269#else
270#define TRUNCDIBI(x) ((BI) (DI) (x))
271#endif
272#if defined (DI_FN_SUPPORT)
43ff13b4 273extern QI TRUNCDIQI (DI);
c906108c
SS
274#else
275#define TRUNCDIQI(x) ((QI) (DI) (x))
276#endif
277#if defined (DI_FN_SUPPORT)
43ff13b4 278extern HI TRUNCDIHI (DI);
c906108c
SS
279#else
280#define TRUNCDIHI(x) ((HI) (DI) (x))
281#endif
282#if defined (DI_FN_SUPPORT)
43ff13b4 283extern SI TRUNCDISI (DI);
c906108c
SS
284#else
285#define TRUNCDISI(x) ((SI) (DI) (x))
286#endif
c906108c 287\f
7a292a7a 288/* Composing/decomposing the various types. */
c906108c 289
43ff13b4
JM
290/* ??? endianness issues undecided */
291/* ??? CURRENT_TARGET_BYTE_ORDER usage wip */
292
c906108c 293#ifdef SEMOPS_DEFINE_INLINE
7a292a7a
SS
294
295SEMOPS_INLINE SF
296SUBWORDSISF (SIM_CPU *cpu, SI in)
297{
298 union { SI in; SF out; } x;
299 x.in = in;
300 return x.out;
301}
302
303SEMOPS_INLINE SI
304SUBWORDSFSI (SIM_CPU *cpu, SF in)
305{
306 union { SF in; SI out; } x;
307 x.in = in;
308 return x.out;
309}
310
311SEMOPS_INLINE SI
312SUBWORDDISI (SIM_CPU *cpu, DI in, int word)
313{
7a292a7a
SS
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
330SEMOPS_INLINE SI
331SUBWORDDFSI (SIM_CPU *cpu, DF in, int word)
332{
7a292a7a
SS
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
43ff13b4
JM
341SEMOPS_INLINE SI
342SUBWORDXFSI (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
7a292a7a
SS
352SEMOPS_INLINE SI
353SUBWORDTFSI (SIM_CPU *cpu, TF in, int word)
354{
7a292a7a
SS
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
43ff13b4 360 return x.out[3 - word];
7a292a7a
SS
361}
362
363SEMOPS_INLINE DI
364JOINSIDI (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
372SEMOPS_INLINE DF
373JOINSIDF (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
43ff13b4
JM
383SEMOPS_INLINE XF
384JOINSIXF (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
7a292a7a
SS
394SEMOPS_INLINE TF
395JOINSITF (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
c906108c 405#else
7a292a7a
SS
406
407SF SUBWORDSISF (SIM_CPU *, SI);
408SI SUBWORDSFSI (SIM_CPU *, SF);
409SI SUBWORDDISI (SIM_CPU *, DI, int);
410SI SUBWORDDFSI (SIM_CPU *, DF, int);
43ff13b4 411SI SUBWORDXFSI (SIM_CPU *, XF, int);
7a292a7a
SS
412SI SUBWORDTFSI (SIM_CPU *, TF, int);
413
414DI JOINSIDI (SIM_CPU *, SI, SI);
415DF JOINSIDF (SIM_CPU *, SI, SI);
43ff13b4 416XF JOINSIXF (SIM_CPU *, SI, SI, SI);
7a292a7a
SS
417TF JOINSITF (SIM_CPU *, SI, SI, SI, SI);
418
419#endif /* SUBWORD,JOIN */
420\f
421/* Semantic support utilities. */
422
423#ifdef SEMOPS_DEFINE_INLINE
c906108c
SS
424
425SEMOPS_INLINE SI
426ADDCSI (SI a, SI b, BI c)
427{
428 SI res = ADDSI (a, ADDSI (b, c));
429 return res;
430}
431
432SEMOPS_INLINE BI
433ADDCFSI (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
440SEMOPS_INLINE BI
441ADDOFSI (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
449SEMOPS_INLINE SI
450SUBCSI (SI a, SI b, BI c)
451{
452 SI res = SUBSI (a, ADDSI (b, c));
453 return res;
454}
455
456SEMOPS_INLINE BI
457SUBCFSI (SI a, SI b, BI c)
458{
459 BI res = ((USI) a < (USI) b) || (c && a == b);
460 return res;
461}
462
463SEMOPS_INLINE BI
464SUBOFSI (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
474SI ADDCSI (SI, SI, BI);
475UBI ADDCFSI (SI, SI, BI);
476UBI ADDOFSI (SI, SI, BI);
477SI SUBCSI (SI, SI, BI);
478UBI SUBCFSI (SI, SI, BI);
479UBI SUBOFSI (SI, SI, BI);
480
481#endif
c906108c
SS
482
483#endif /* CGEN_SEM_OPS_H */
This page took 0.065624 seconds and 4 git commands to generate.