2 /* Semantics ops support for CGEN-based simulators.
3 Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
4 Contributed by Cygnus Solutions.
6 This file is part of the GNU Simulators.
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)
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.
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.
24 #ifndef CGEN_SEM_OPS_H
25 #define CGEN_SEM_OPS_H
27 #if defined (__GNUC__) && ! defined (SEMOPS_DEFINE_INLINE)
28 #define SEMOPS_DEFINE_INLINE
29 #define SEMOPS_INLINE extern inline
34 /* Semantic operations.
35 At one point this file was machine generated. Maybe it will be again. */
37 /* TODO: Lazy encoding/decoding of fp values. */
39 /* These don't really have a mode. */
40 #define ANDIF(x, y) ((x) && (y))
41 #define ORIF(x, y) ((x) || (y))
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))
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))
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))
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))
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 */
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
);
213 #define EXTBIDI(x) ((DI) (BI) (x))
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
);
220 #define EXTQIDI(x) ((DI) (QI) (x))
222 #define EXTHISI(x) ((SI) (HI) (x))
223 #if defined (DI_FN_SUPPORT)
224 extern DI
EXTHIDI (HI
);
226 #define EXTHIDI(x) ((DI) (HI) (x))
228 #if defined (DI_FN_SUPPORT)
229 extern DI
EXTSIDI (SI
);
231 #define EXTSIDI(x) ((DI) (SI) (x))
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
);
240 #define ZEXTBIDI(x) ((DI) (BI) (x))
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
);
247 #define ZEXTQIDI(x) ((DI) (UQI) (x))
249 #define ZEXTHISI(x) ((SI) (UHI) (x))
250 #if defined (DI_FN_SUPPORT)
251 extern DI
ZEXTHIDI (HI
);
253 #define ZEXTHIDI(x) ((DI) (UHI) (x))
255 #if defined (DI_FN_SUPPORT)
256 extern DI
ZEXTSIDI (SI
);
258 #define ZEXTSIDI(x) ((DI) (USI) (x))
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
);
270 #define TRUNCDIBI(x) ((BI) (DI) (x))
272 #if defined (DI_FN_SUPPORT)
273 extern QI
TRUNCDIQI (DI
);
275 #define TRUNCDIQI(x) ((QI) (DI) (x))
277 #if defined (DI_FN_SUPPORT)
278 extern HI
TRUNCDIHI (DI
);
280 #define TRUNCDIHI(x) ((HI) (DI) (x))
282 #if defined (DI_FN_SUPPORT)
283 extern SI
TRUNCDISI (DI
);
285 #define TRUNCDISI(x) ((SI) (DI) (x))
288 /* Composing/decomposing the various types. */
290 /* ??? endianness issues undecided */
291 /* ??? CURRENT_TARGET_BYTE_ORDER usage wip */
293 #ifdef SEMOPS_DEFINE_INLINE
296 SUBWORDSISF (SIM_CPU
*cpu
, SI in
)
298 union { SI in
; SF out
; } x
;
304 SUBWORDSFSI (SIM_CPU
*cpu
, SF in
)
306 union { SF in
; SI out
; } x
;
312 SUBWORDDISI (SIM_CPU
*cpu
, DI in
, int word
)
314 if (CURRENT_TARGET_BYTE_ORDER
== BIG_ENDIAN
)
317 return (UDI
) in
>> 32;
324 return (UDI
) in
>> 32;
331 SUBWORDDFSI (SIM_CPU
*cpu
, DF in
, int word
)
333 union { DF in
; SI out
[2]; } x
;
335 if (CURRENT_TARGET_BYTE_ORDER
== BIG_ENDIAN
)
342 SUBWORDXFSI (SIM_CPU
*cpu
, XF in
, int word
)
344 union { XF in
; SI out
[3]; } x
;
346 if (CURRENT_TARGET_BYTE_ORDER
== BIG_ENDIAN
)
349 return x
.out
[2 - word
];
353 SUBWORDTFSI (SIM_CPU
*cpu
, TF in
, int word
)
355 union { TF in
; SI out
[4]; } x
;
357 if (CURRENT_TARGET_BYTE_ORDER
== BIG_ENDIAN
)
360 return x
.out
[3 - word
];
364 JOINSIDI (SIM_CPU
*cpu
, SI x0
, SI x1
)
366 if (CURRENT_TARGET_BYTE_ORDER
== BIG_ENDIAN
)
367 return MAKEDI (x0
, x1
);
369 return MAKEDI (x1
, x0
);
373 JOINSIDF (SIM_CPU
*cpu
, SI x0
, SI x1
)
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
;
379 x
.in
[1] = x0
, x
.in
[0] = x1
;
384 JOINSIXF (SIM_CPU
*cpu
, SI x0
, SI x1
, SI x2
)
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
;
390 x
.in
[2] = x0
, x
.in
[1] = x1
, x
.in
[0] = x2
;
395 JOINSITF (SIM_CPU
*cpu
, SI x0
, SI x1
, SI x2
, SI x3
)
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
;
401 x
.in
[3] = x0
, x
.in
[2] = x1
, x
.in
[1] = x2
, x
.in
[0] = x3
;
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);
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
);
419 #endif /* SUBWORD,JOIN */
421 /* Semantic support utilities. */
423 #ifdef SEMOPS_DEFINE_INLINE
426 ADDCSI (SI a
, SI b
, BI c
)
428 SI res
= ADDSI (a
, ADDSI (b
, c
));
433 ADDCFSI (SI a
, SI b
, BI c
)
435 SI tmp
= ADDSI (a
, ADDSI (b
, c
));
436 BI res
= ((USI
) tmp
< (USI
) a
) || (c
&& tmp
== a
);
441 ADDOFSI (SI a
, SI b
, BI c
)
443 SI tmp
= ADDSI (a
, ADDSI (b
, c
));
444 BI res
= (((a
< 0) == (b
< 0))
445 && ((a
< 0) != (tmp
< 0)));
450 SUBCSI (SI a
, SI b
, BI c
)
452 SI res
= SUBSI (a
, ADDSI (b
, c
));
457 SUBCFSI (SI a
, SI b
, BI c
)
459 BI res
= ((USI
) a
< (USI
) b
) || (c
&& a
== b
);
464 SUBOFSI (SI a
, SI b
, BI c
)
466 SI tmp
= SUBSI (a
, ADDSI (b
, c
));
467 BI res
= (((a
< 0) != (b
< 0))
468 && ((a
< 0) != (tmp
< 0)));
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
);
483 #endif /* CGEN_SEM_OPS_H */