1 /* Semantics ops support for CGEN-based opcode libraries.
2 Copyright (C) 2005, 2007 Free Software Foundation, Inc.
3 Contributed by Red Hat.
5 This file is part of the GNU opcodes library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 It is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 #ifndef CGEN_SEM_OPS_H
22 #define CGEN_SEM_OPS_H
26 #if defined (__GNUC__) && ! defined (SEMOPS_DEFINE_INLINE)
27 #define SEMOPS_DEFINE_INLINE
28 #define SEMOPS_INLINE extern inline
33 /* TODO: Lazy encoding/decoding of fp values. */
35 /* These don't really have a mode. */
36 #define ANDIF(x, y) ((x) && (y))
37 #define ORIF(x, y) ((x) || (y))
39 #define SUBBI(x, y) ((x) - (y))
40 #define ANDBI(x, y) ((x) & (y))
41 #define ORBI(x, y) ((x) | (y))
42 #define XORBI(x, y) ((x) ^ (y))
43 #define NEGBI(x) (- (x))
44 #define NOTBI(x) (! (BI) (x))
45 #define INVBI(x) (~ (x))
46 #define EQBI(x, y) ((BI) (x) == (BI) (y))
47 #define NEBI(x, y) ((BI) (x) != (BI) (y))
48 #define LTBI(x, y) ((BI) (x) < (BI) (y))
49 #define LEBI(x, y) ((BI) (x) <= (BI) (y))
50 #define GTBI(x, y) ((BI) (x) > (BI) (y))
51 #define GEBI(x, y) ((BI) (x) >= (BI) (y))
52 #define LTUBI(x, y) ((BI) (x) < (BI) (y))
53 #define LEUBI(x, y) ((BI) (x) <= (BI) (y))
54 #define GTUBI(x, y) ((BI) (x) > (BI) (y))
55 #define GEUBI(x, y) ((BI) (x) >= (BI) (y))
57 #define ADDQI(x, y) ((x) + (y))
58 #define SUBQI(x, y) ((x) - (y))
59 #define MULQI(x, y) ((x) * (y))
60 #define DIVQI(x, y) ((QI) (x) / (QI) (y))
61 #define UDIVQI(x, y) ((UQI) (x) / (UQI) (y))
62 #define MODQI(x, y) ((QI) (x) % (QI) (y))
63 #define UMODQI(x, y) ((UQI) (x) % (UQI) (y))
64 #define SRAQI(x, y) ((QI) (x) >> (y))
65 #define SRLQI(x, y) ((UQI) (x) >> (y))
66 #define SLLQI(x, y) ((UQI) (x) << (y))
67 extern QI
RORQI (QI
, int);
68 extern QI
ROLQI (QI
, int);
69 #define ANDQI(x, y) ((x) & (y))
70 #define ORQI(x, y) ((x) | (y))
71 #define XORQI(x, y) ((x) ^ (y))
72 #define NEGQI(x) (- (x))
73 #define NOTQI(x) (! (QI) (x))
74 #define INVQI(x) (~ (x))
75 #define ABSQI(x) ((x) < 0 ? -(x) : (x))
76 #define EQQI(x, y) ((QI) (x) == (QI) (y))
77 #define NEQI(x, y) ((QI) (x) != (QI) (y))
78 #define LTQI(x, y) ((QI) (x) < (QI) (y))
79 #define LEQI(x, y) ((QI) (x) <= (QI) (y))
80 #define GTQI(x, y) ((QI) (x) > (QI) (y))
81 #define GEQI(x, y) ((QI) (x) >= (QI) (y))
82 #define LTUQI(x, y) ((UQI) (x) < (UQI) (y))
83 #define LEUQI(x, y) ((UQI) (x) <= (UQI) (y))
84 #define GTUQI(x, y) ((UQI) (x) > (UQI) (y))
85 #define GEUQI(x, y) ((UQI) (x) >= (UQI) (y))
87 #define ADDHI(x, y) ((x) + (y))
88 #define SUBHI(x, y) ((x) - (y))
89 #define MULHI(x, y) ((x) * (y))
90 #define DIVHI(x, y) ((HI) (x) / (HI) (y))
91 #define UDIVHI(x, y) ((UHI) (x) / (UHI) (y))
92 #define MODHI(x, y) ((HI) (x) % (HI) (y))
93 #define UMODHI(x, y) ((UHI) (x) % (UHI) (y))
94 #define SRAHI(x, y) ((HI) (x) >> (y))
95 #define SRLHI(x, y) ((UHI) (x) >> (y))
96 #define SLLHI(x, y) ((UHI) (x) << (y))
97 extern HI
RORHI (HI
, int);
98 extern HI
ROLHI (HI
, int);
99 #define ANDHI(x, y) ((x) & (y))
100 #define ORHI(x, y) ((x) | (y))
101 #define XORHI(x, y) ((x) ^ (y))
102 #define NEGHI(x) (- (x))
103 #define NOTHI(x) (! (HI) (x))
104 #define INVHI(x) (~ (x))
105 #define ABSHI(x) ((x) < 0 ? -(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))
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))
127 extern SI
RORSI (SI
, int);
128 extern SI
ROLSI (SI
, int);
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 ABSSI(x) ((x) < 0 ? -(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 ABSDI(x) ((x) < 0 ? -(x) : (x))
196 #define EQDI(x, y) ((DI) (x) == (DI) (y))
197 #define NEDI(x, y) ((DI) (x) != (DI) (y))
198 #define LTDI(x, y) ((DI) (x) < (DI) (y))
199 #define LEDI(x, y) ((DI) (x) <= (DI) (y))
200 #define GTDI(x, y) ((DI) (x) > (DI) (y))
201 #define GEDI(x, y) ((DI) (x) >= (DI) (y))
202 #define LTUDI(x, y) ((UDI) (x) < (UDI) (y))
203 #define LEUDI(x, y) ((UDI) (x) <= (UDI) (y))
204 #define GTUDI(x, y) ((UDI) (x) > (UDI) (y))
205 #define GEUDI(x, y) ((UDI) (x) >= (UDI) (y))
206 #endif /* DI_FN_SUPPORT */
208 #define EXTBIQI(x) ((QI) (BI) (x))
209 #define EXTBIHI(x) ((HI) (BI) (x))
210 #define EXTBISI(x) ((SI) (BI) (x))
211 #if defined (DI_FN_SUPPORT)
212 extern DI
EXTBIDI (BI
);
214 #define EXTBIDI(x) ((DI) (BI) (x))
216 #define EXTQIHI(x) ((HI) (QI) (x))
217 #define EXTQISI(x) ((SI) (QI) (x))
218 #if defined (DI_FN_SUPPORT)
219 extern DI
EXTQIDI (QI
);
221 #define EXTQIDI(x) ((DI) (QI) (x))
223 #define EXTHIHI(x) ((HI) (HI) (x))
224 #define EXTHISI(x) ((SI) (HI) (x))
225 #define EXTSISI(x) ((SI) (SI) (x))
226 #if defined (DI_FN_SUPPORT)
227 extern DI
EXTHIDI (HI
);
229 #define EXTHIDI(x) ((DI) (HI) (x))
231 #if defined (DI_FN_SUPPORT)
232 extern DI
EXTSIDI (SI
);
234 #define EXTSIDI(x) ((DI) (SI) (x))
237 #define ZEXTBIQI(x) ((QI) (BI) (x))
238 #define ZEXTBIHI(x) ((HI) (BI) (x))
239 #define ZEXTBISI(x) ((SI) (BI) (x))
240 #if defined (DI_FN_SUPPORT)
241 extern DI
ZEXTBIDI (BI
);
243 #define ZEXTBIDI(x) ((DI) (BI) (x))
245 #define ZEXTQIHI(x) ((HI) (UQI) (x))
246 #define ZEXTQISI(x) ((SI) (UQI) (x))
247 #if defined (DI_FN_SUPPORT)
248 extern DI
ZEXTQIDI (QI
);
250 #define ZEXTQIDI(x) ((DI) (UQI) (x))
252 #define ZEXTHISI(x) ((SI) (UHI) (x))
253 #define ZEXTHIHI(x) ((HI) (UHI) (x))
254 #define ZEXTSISI(x) ((SI) (USI) (x))
255 #if defined (DI_FN_SUPPORT)
256 extern DI
ZEXTHIDI (HI
);
258 #define ZEXTHIDI(x) ((DI) (UHI) (x))
260 #if defined (DI_FN_SUPPORT)
261 extern DI
ZEXTSIDI (SI
);
263 #define ZEXTSIDI(x) ((DI) (USI) (x))
266 #define TRUNCQIBI(x) ((BI) (QI) (x))
267 #define TRUNCHIBI(x) ((BI) (HI) (x))
268 #define TRUNCHIQI(x) ((QI) (HI) (x))
269 #define TRUNCSIBI(x) ((BI) (SI) (x))
270 #define TRUNCSIQI(x) ((QI) (SI) (x))
271 #define TRUNCSIHI(x) ((HI) (SI) (x))
272 #define TRUNCSISI(x) ((SI) (SI) (x))
273 #if defined (DI_FN_SUPPORT)
274 extern BI
TRUNCDIBI (DI
);
276 #define TRUNCDIBI(x) ((BI) (DI) (x))
278 #if defined (DI_FN_SUPPORT)
279 extern QI
TRUNCDIQI (DI
);
281 #define TRUNCDIQI(x) ((QI) (DI) (x))
283 #if defined (DI_FN_SUPPORT)
284 extern HI
TRUNCDIHI (DI
);
286 #define TRUNCDIHI(x) ((HI) (DI) (x))
288 #if defined (DI_FN_SUPPORT)
289 extern SI
TRUNCDISI (DI
);
291 #define TRUNCDISI(x) ((SI) (DI) (x))
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. */
299 QI
SUBWORDSIQI (SI
, int);
300 HI
SUBWORDSIHI (SI
, int);
305 QI
SUBWORDDIQI (DI
, int);
306 HI
SUBWORDDIHI (DI
, int);
307 SI
SUBWORDDISI (DI
, int);
308 SI
SUBWORDDFSI (DF
, int);
309 SI
SUBWORDXFSI (XF
, int);
310 SI
SUBWORDTFSI (TF
, int);
312 UQI
SUBWORDSIUQI (SI
, int);
313 UQI
SUBWORDDIUQI (DI
, int);
315 #ifdef SEMOPS_DEFINE_INLINE
320 union { SI in
; SF out
; } x
;
328 union { DI in
; DF out
; } x
;
334 SUBWORDSIQI (SI in
, int byte
)
336 assert (byte
>= 0 && byte
<= 3);
337 return (UQI
) (in
>> (8 * (3 - byte
))) & 0xFF;
341 SUBWORDSIUQI (SI in
, int byte
)
343 assert (byte
>= 0 && byte
<= 3);
344 return (UQI
) (in
>> (8 * (3 - byte
))) & 0xFF;
348 SUBWORDDIQI (DI in
, int byte
)
350 assert (byte
>= 0 && byte
<= 7);
351 return (UQI
) (in
>> (8 * (7 - byte
))) & 0xFF;
355 SUBWORDDIHI (DI in
, int word
)
357 assert (word
>= 0 && word
<= 3);
358 return (UHI
) (in
>> (16 * (3 - word
))) & 0xFFFF;
362 SUBWORDSIHI (SI in
, int word
)
365 return (USI
) in
>> 16;
373 union { SF in
; SI out
; } x
;
381 union { DF in
; DI out
; } x
;
387 SUBWORDDIUQI (DI in
, int byte
)
389 assert (byte
>= 0 && byte
<= 7);
390 return (UQI
) (in
>> (8 * (7 - byte
)));
394 SUBWORDDISI (DI in
, int word
)
397 return (UDI
) in
>> 32;
403 SUBWORDDFSI (DF in
, int word
)
405 /* Note: typedef UDI DF; */
407 return (UDI
) in
>> 32;
413 SUBWORDXFSI (XF in
, int word
)
415 /* Note: typedef struct { SI parts[3]; } XF; */
416 union { XF in
; SI out
[3]; } x
;
422 SUBWORDTFSI (TF in
, int word
)
424 /* Note: typedef struct { SI parts[4]; } TF; */
425 union { TF in
; SI out
[4]; } x
;
430 #endif /* SUBWORD,JOIN */
432 #endif /* CGEN_SEM_OPS_H */