1 /* Semantics ops support for CGEN-based opcode libraries.
2 Copyright (C) 2005 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 2, or (at your option)
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public 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.
23 #ifndef CGEN_SEM_OPS_H
24 #define CGEN_SEM_OPS_H
28 #if defined (__GNUC__) && ! defined (SEMOPS_DEFINE_INLINE)
29 #define SEMOPS_DEFINE_INLINE
30 #define SEMOPS_INLINE extern inline
35 /* TODO: Lazy encoding/decoding of fp values. */
37 /* These don't really have a mode. */
38 #define ANDIF(x, y) ((x) && (y))
39 #define ORIF(x, y) ((x) || (y))
41 #define SUBBI(x, y) ((x) - (y))
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))
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))
69 extern QI
RORQI (QI
, int);
70 extern QI
ROLQI (QI
, int);
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 ABSQI(x) ((x) < 0 ? -(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 ABSHI(x) ((x) < 0 ? -(x) : (x))
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))
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))
129 extern SI
RORSI (SI
, int);
130 extern SI
ROLSI (SI
, int);
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))
137 #define ABSSI(x) ((x) < 0 ? -(x) : (x))
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))
150 extern DI
ADDDI (DI
, DI
);
151 extern DI
SUBDI (DI
, DI
);
152 extern DI
MULDI (DI
, DI
);
153 extern DI
DIVDI (DI
, DI
);
154 extern DI
UDIVDI (DI
, DI
);
155 extern DI
MODDI (DI
, DI
);
156 extern DI
UMODDI (DI
, DI
);
157 extern DI
SRADI (DI
, int);
158 extern UDI
SRLDI (UDI
, int);
159 extern UDI
SLLDI (UDI
, int);
160 extern DI
RORDI (DI
, int);
161 extern DI
ROLDI (DI
, int);
162 extern DI
ANDDI (DI
, DI
);
163 extern DI
ORDI (DI
, DI
);
164 extern DI
XORDI (DI
, DI
);
165 extern DI
NEGDI (DI
);
166 extern int NOTDI (DI
);
167 extern DI
INVDI (DI
);
168 extern int EQDI (DI
, DI
);
169 extern int NEDI (DI
, DI
);
170 extern int LTDI (DI
, DI
);
171 extern int LEDI (DI
, DI
);
172 extern int GTDI (DI
, DI
);
173 extern int GEDI (DI
, DI
);
174 extern int LTUDI (UDI
, UDI
);
175 extern int LEUDI (UDI
, UDI
);
176 extern int GTUDI (UDI
, UDI
);
177 extern int GEUDI (UDI
, UDI
);
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))
189 extern DI
RORDI (DI
, int);
190 extern DI
ROLDI (DI
, int);
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))
197 #define ABSDI(x) ((x) < 0 ? -(x) : (x))
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 */
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)
214 extern DI
EXTBIDI (BI
);
216 #define EXTBIDI(x) ((DI) (BI) (x))
218 #define EXTQIHI(x) ((HI) (QI) (x))
219 #define EXTQISI(x) ((SI) (QI) (x))
220 #if defined (DI_FN_SUPPORT)
221 extern DI
EXTQIDI (QI
);
223 #define EXTQIDI(x) ((DI) (QI) (x))
225 #define EXTHIHI(x) ((HI) (HI) (x))
226 #define EXTHISI(x) ((SI) (HI) (x))
227 #define EXTSISI(x) ((SI) (SI) (x))
228 #if defined (DI_FN_SUPPORT)
229 extern DI
EXTHIDI (HI
);
231 #define EXTHIDI(x) ((DI) (HI) (x))
233 #if defined (DI_FN_SUPPORT)
234 extern DI
EXTSIDI (SI
);
236 #define EXTSIDI(x) ((DI) (SI) (x))
239 #define ZEXTBIQI(x) ((QI) (BI) (x))
240 #define ZEXTBIHI(x) ((HI) (BI) (x))
241 #define ZEXTBISI(x) ((SI) (BI) (x))
242 #if defined (DI_FN_SUPPORT)
243 extern DI
ZEXTBIDI (BI
);
245 #define ZEXTBIDI(x) ((DI) (BI) (x))
247 #define ZEXTQIHI(x) ((HI) (UQI) (x))
248 #define ZEXTQISI(x) ((SI) (UQI) (x))
249 #if defined (DI_FN_SUPPORT)
250 extern DI
ZEXTQIDI (QI
);
252 #define ZEXTQIDI(x) ((DI) (UQI) (x))
254 #define ZEXTHISI(x) ((SI) (UHI) (x))
255 #define ZEXTHIHI(x) ((HI) (UHI) (x))
256 #define ZEXTSISI(x) ((SI) (USI) (x))
257 #if defined (DI_FN_SUPPORT)
258 extern DI
ZEXTHIDI (HI
);
260 #define ZEXTHIDI(x) ((DI) (UHI) (x))
262 #if defined (DI_FN_SUPPORT)
263 extern DI
ZEXTSIDI (SI
);
265 #define ZEXTSIDI(x) ((DI) (USI) (x))
268 #define TRUNCQIBI(x) ((BI) (QI) (x))
269 #define TRUNCHIBI(x) ((BI) (HI) (x))
270 #define TRUNCHIQI(x) ((QI) (HI) (x))
271 #define TRUNCSIBI(x) ((BI) (SI) (x))
272 #define TRUNCSIQI(x) ((QI) (SI) (x))
273 #define TRUNCSIHI(x) ((HI) (SI) (x))
274 #define TRUNCSISI(x) ((SI) (SI) (x))
275 #if defined (DI_FN_SUPPORT)
276 extern BI
TRUNCDIBI (DI
);
278 #define TRUNCDIBI(x) ((BI) (DI) (x))
280 #if defined (DI_FN_SUPPORT)
281 extern QI
TRUNCDIQI (DI
);
283 #define TRUNCDIQI(x) ((QI) (DI) (x))
285 #if defined (DI_FN_SUPPORT)
286 extern HI
TRUNCDIHI (DI
);
288 #define TRUNCDIHI(x) ((HI) (DI) (x))
290 #if defined (DI_FN_SUPPORT)
291 extern SI
TRUNCDISI (DI
);
293 #define TRUNCDISI(x) ((SI) (DI) (x))
296 /* Composing/decomposing the various types.
297 Word ordering is endian-independent. Words are specified most to least
298 significant and word number 0 is the most significant word.
299 ??? May also wish an endian-dependent version. Later. */
301 QI
SUBWORDSIQI (SI
, int);
302 HI
SUBWORDSIHI (SI
, int);
307 QI
SUBWORDDIQI (DI
, int);
308 HI
SUBWORDDIHI (DI
, int);
309 SI
SUBWORDDISI (DI
, int);
310 SI
SUBWORDDFSI (DF
, int);
311 SI
SUBWORDXFSI (XF
, int);
312 SI
SUBWORDTFSI (TF
, int);
314 UQI
SUBWORDSIUQI (SI
, int);
315 UQI
SUBWORDDIUQI (DI
, int);
317 #ifdef SEMOPS_DEFINE_INLINE
322 union { SI in
; SF out
; } x
;
330 union { DI in
; DF out
; } x
;
336 SUBWORDSIQI (SI in
, int byte
)
338 assert (byte
>= 0 && byte
<= 3);
339 return (UQI
) (in
>> (8 * (3 - byte
))) & 0xFF;
343 SUBWORDSIUQI (SI in
, int byte
)
345 assert (byte
>= 0 && byte
<= 3);
346 return (UQI
) (in
>> (8 * (3 - byte
))) & 0xFF;
350 SUBWORDDIQI (DI in
, int byte
)
352 assert (byte
>= 0 && byte
<= 7);
353 return (UQI
) (in
>> (8 * (7 - byte
))) & 0xFF;
357 SUBWORDDIHI (DI in
, int word
)
359 assert (word
>= 0 && word
<= 3);
360 return (UHI
) (in
>> (16 * (3 - word
))) & 0xFFFF;
364 SUBWORDSIHI (SI in
, int word
)
367 return (USI
) in
>> 16;
375 union { SF in
; SI out
; } x
;
383 union { DF in
; DI out
; } x
;
389 SUBWORDDIUQI (DI in
, int byte
)
391 assert (byte
>= 0 && byte
<= 7);
392 return (UQI
) (in
>> (8 * (7 - byte
)));
396 SUBWORDDISI (DI in
, int word
)
399 return (UDI
) in
>> 32;
405 SUBWORDDFSI (DF in
, int word
)
407 /* Note: typedef UDI DF; */
409 return (UDI
) in
>> 32;
415 SUBWORDXFSI (XF in
, int word
)
417 /* Note: typedef struct { SI parts[3]; } XF; */
418 union { XF in
; SI out
[3]; } x
;
424 SUBWORDTFSI (TF in
, int word
)
426 /* Note: typedef struct { SI parts[4]; } TF; */
427 union { TF in
; SI out
[4]; } x
;
432 #endif /* SUBWORD,JOIN */
434 #endif /* CGEN_SEM_OPS_H */