Upload Tizen:Base source
[external/binutils.git] / include / cgen / basic-ops.h
1 /* Basic semantics ops support for CGEN.
2    Copyright 2005, 2007, 2009 Free Software Foundation, Inc.
3    Contributed by Red Hat.
4
5    This file is part of the GNU opcodes library.
6
7    This library 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)
10    any later version.
11
12    It 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.
16
17    You should have received a copy of the GNU General Public License
18    along with this library; see the file COPYING3.  If not, write to the
19    Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
20    02110-1301, USA.  */
21
22 #ifndef CGEN_BASIC_OPS_H
23 #define CGEN_BASIC_OPS_H
24
25 #include <assert.h>
26
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
34 /* These don't really have a mode.  */
35 #define ANDIF(x, y) ((x) && (y))
36 #define ORIF(x, y) ((x) || (y))
37
38 #define SUBBI(x, y) ((x) - (y))
39 #define ANDBI(x, y) ((x) & (y))
40 #define ORBI(x, y) ((x) | (y))
41 #define XORBI(x, y) ((x) ^ (y))
42 #define NEGBI(x) (- (x))
43 #define NOTBI(x) (! (BI) (x))
44 #define INVBI(x) (~ (x))
45 #define EQBI(x, y) ((BI) (x) == (BI) (y))
46 #define NEBI(x, y) ((BI) (x) != (BI) (y))
47 #define LTBI(x, y) ((BI) (x) < (BI) (y))
48 #define LEBI(x, y) ((BI) (x) <= (BI) (y))
49 #define GTBI(x, y) ((BI) (x) > (BI) (y))
50 #define GEBI(x, y) ((BI) (x) >= (BI) (y))
51 #define LTUBI(x, y) ((BI) (x) < (BI) (y))
52 #define LEUBI(x, y) ((BI) (x) <= (BI) (y))
53 #define GTUBI(x, y) ((BI) (x) > (BI) (y))
54 #define GEUBI(x, y) ((BI) (x) >= (BI) (y))
55 \f
56 #define ADDQI(x, y) ((x) + (y))
57 #define SUBQI(x, y) ((x) - (y))
58 #define MULQI(x, y) ((x) * (y))
59 #define DIVQI(x, y) ((QI) (x) / (QI) (y))
60 #define UDIVQI(x, y) ((UQI) (x) / (UQI) (y))
61 #define MODQI(x, y) ((QI) (x) % (QI) (y))
62 #define UMODQI(x, y) ((UQI) (x) % (UQI) (y))
63 #define SRAQI(x, y) ((QI) (x) >> (y))
64 #define SRLQI(x, y) ((UQI) (x) >> (y))
65 #define SLLQI(x, y) ((UQI) (x) << (y))
66 extern QI RORQI (QI, int);
67 extern QI ROLQI (QI, int);
68 #define ANDQI(x, y) ((x) & (y))
69 #define ORQI(x, y) ((x) | (y))
70 #define XORQI(x, y) ((x) ^ (y))
71 #define NEGQI(x) (- (x))
72 #define NOTQI(x) (! (QI) (x))
73 #define INVQI(x) (~ (x))
74 #define ABSQI(x) ((x) < 0 ? -(x) : (x))
75 #define EQQI(x, y) ((QI) (x) == (QI) (y))
76 #define NEQI(x, y) ((QI) (x) != (QI) (y))
77 #define LTQI(x, y) ((QI) (x) < (QI) (y))
78 #define LEQI(x, y) ((QI) (x) <= (QI) (y))
79 #define GTQI(x, y) ((QI) (x) > (QI) (y))
80 #define GEQI(x, y) ((QI) (x) >= (QI) (y))
81 #define LTUQI(x, y) ((UQI) (x) < (UQI) (y))
82 #define LEUQI(x, y) ((UQI) (x) <= (UQI) (y))
83 #define GTUQI(x, y) ((UQI) (x) > (UQI) (y))
84 #define GEUQI(x, y) ((UQI) (x) >= (UQI) (y))
85 \f
86 #define ADDHI(x, y) ((x) + (y))
87 #define SUBHI(x, y) ((x) - (y))
88 #define MULHI(x, y) ((x) * (y))
89 #define DIVHI(x, y) ((HI) (x) / (HI) (y))
90 #define UDIVHI(x, y) ((UHI) (x) / (UHI) (y))
91 #define MODHI(x, y) ((HI) (x) % (HI) (y))
92 #define UMODHI(x, y) ((UHI) (x) % (UHI) (y))
93 #define SRAHI(x, y) ((HI) (x) >> (y))
94 #define SRLHI(x, y) ((UHI) (x) >> (y))
95 #define SLLHI(x, y) ((UHI) (x) << (y))
96 extern HI RORHI (HI, int);
97 extern HI ROLHI (HI, int);
98 #define ANDHI(x, y) ((x) & (y))
99 #define ORHI(x, y) ((x) | (y))
100 #define XORHI(x, y) ((x) ^ (y))
101 #define NEGHI(x) (- (x))
102 #define NOTHI(x) (! (HI) (x))
103 #define INVHI(x) (~ (x))
104 #define ABSHI(x) ((x) < 0 ? -(x) : (x))
105 #define EQHI(x, y) ((HI) (x) == (HI) (y))
106 #define NEHI(x, y) ((HI) (x) != (HI) (y))
107 #define LTHI(x, y) ((HI) (x) < (HI) (y))
108 #define LEHI(x, y) ((HI) (x) <= (HI) (y))
109 #define GTHI(x, y) ((HI) (x) > (HI) (y))
110 #define GEHI(x, y) ((HI) (x) >= (HI) (y))
111 #define LTUHI(x, y) ((UHI) (x) < (UHI) (y))
112 #define LEUHI(x, y) ((UHI) (x) <= (UHI) (y))
113 #define GTUHI(x, y) ((UHI) (x) > (UHI) (y))
114 #define GEUHI(x, y) ((UHI) (x) >= (UHI) (y))
115 \f
116 #define ADDSI(x, y) ((x) + (y))
117 #define SUBSI(x, y) ((x) - (y))
118 #define MULSI(x, y) ((x) * (y))
119 #define DIVSI(x, y) ((SI) (x) / (SI) (y))
120 #define UDIVSI(x, y) ((USI) (x) / (USI) (y))
121 #define MODSI(x, y) ((SI) (x) % (SI) (y))
122 #define UMODSI(x, y) ((USI) (x) % (USI) (y))
123 #define SRASI(x, y) ((SI) (x) >> (y))
124 #define SRLSI(x, y) ((USI) (x) >> (y))
125 #define SLLSI(x, y) ((USI) (x) << (y))
126 extern SI RORSI (SI, int);
127 extern SI ROLSI (SI, int);
128 #define ANDSI(x, y) ((x) & (y))
129 #define ORSI(x, y) ((x) | (y))
130 #define XORSI(x, y) ((x) ^ (y))
131 #define NEGSI(x) (- (x))
132 #define NOTSI(x) (! (SI) (x))
133 #define INVSI(x) (~ (x))
134 #define ABSSI(x) ((x) < 0 ? -(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))
145 \f
146 #ifdef DI_FN_SUPPORT
147 extern DI ADDDI (DI, DI);
148 extern DI SUBDI (DI, DI);
149 extern DI MULDI (DI, DI);
150 extern DI DIVDI (DI, DI);
151 extern DI UDIVDI (DI, DI);
152 extern DI MODDI (DI, DI);
153 extern DI UMODDI (DI, DI);
154 extern DI SRADI (DI, int);
155 extern UDI SRLDI (UDI, int);
156 extern UDI SLLDI (UDI, int);
157 extern DI RORDI (DI, int);
158 extern DI ROLDI (DI, int);
159 extern DI ANDDI (DI, DI);
160 extern DI ORDI (DI, DI);
161 extern DI XORDI (DI, DI);
162 extern DI NEGDI (DI);
163 extern int NOTDI (DI);
164 extern DI INVDI (DI);
165 extern int EQDI (DI, DI);
166 extern int NEDI (DI, DI);
167 extern int LTDI (DI, DI);
168 extern int LEDI (DI, DI);
169 extern int GTDI (DI, DI);
170 extern int GEDI (DI, DI);
171 extern int LTUDI (UDI, UDI);
172 extern int LEUDI (UDI, UDI);
173 extern int GTUDI (UDI, UDI);
174 extern int GEUDI (UDI, UDI);
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))
186 extern DI RORDI (DI, int);
187 extern DI ROLDI (DI, int);
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 ABSDI(x) ((x) < 0 ? -(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 */
206 \f
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);
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)
218 extern DI EXTQIDI (QI);
219 #else
220 #define EXTQIDI(x) ((DI) (QI) (x))
221 #endif
222 #define EXTHIHI(x) ((HI) (HI) (x))
223 #define EXTHISI(x) ((SI) (HI) (x))
224 #define EXTSISI(x) ((SI) (SI) (x))
225 #if defined (DI_FN_SUPPORT)
226 extern DI EXTHIDI (HI);
227 #else
228 #define EXTHIDI(x) ((DI) (HI) (x))
229 #endif
230 #if defined (DI_FN_SUPPORT)
231 extern DI EXTSIDI (SI);
232 #else
233 #define EXTSIDI(x) ((DI) (SI) (x))
234 #endif
235 \f
236 #define ZEXTBIQI(x) ((QI) (BI) (x))
237 #define ZEXTBIHI(x) ((HI) (BI) (x))
238 #define ZEXTBISI(x) ((SI) (BI) (x))
239 #if defined (DI_FN_SUPPORT)
240 extern DI ZEXTBIDI (BI);
241 #else
242 #define ZEXTBIDI(x) ((DI) (BI) (x))
243 #endif
244 #define ZEXTQIHI(x) ((HI) (UQI) (x))
245 #define ZEXTQISI(x) ((SI) (UQI) (x))
246 #if defined (DI_FN_SUPPORT)
247 extern DI ZEXTQIDI (QI);
248 #else
249 #define ZEXTQIDI(x) ((DI) (UQI) (x))
250 #endif
251 #define ZEXTHISI(x) ((SI) (UHI) (x))
252 #define ZEXTHIHI(x) ((HI) (UHI) (x))
253 #define ZEXTSISI(x) ((SI) (USI) (x))
254 #if defined (DI_FN_SUPPORT)
255 extern DI ZEXTHIDI (HI);
256 #else
257 #define ZEXTHIDI(x) ((DI) (UHI) (x))
258 #endif
259 #if defined (DI_FN_SUPPORT)
260 extern DI ZEXTSIDI (SI);
261 #else
262 #define ZEXTSIDI(x) ((DI) (USI) (x))
263 #endif
264 \f
265 #define TRUNCQIBI(x) ((BI) (QI) (x))
266 #define TRUNCHIBI(x) ((BI) (HI) (x))
267 #define TRUNCHIQI(x) ((QI) (HI) (x))
268 #define TRUNCSIBI(x) ((BI) (SI) (x))
269 #define TRUNCSIQI(x) ((QI) (SI) (x))
270 #define TRUNCSIHI(x) ((HI) (SI) (x))
271 #define TRUNCSISI(x) ((SI) (SI) (x))
272 #if defined (DI_FN_SUPPORT)
273 extern BI TRUNCDIBI (DI);
274 #else
275 #define TRUNCDIBI(x) ((BI) (DI) (x))
276 #endif
277 #if defined (DI_FN_SUPPORT)
278 extern QI TRUNCDIQI (DI);
279 #else
280 #define TRUNCDIQI(x) ((QI) (DI) (x))
281 #endif
282 #if defined (DI_FN_SUPPORT)
283 extern HI TRUNCDIHI (DI);
284 #else
285 #define TRUNCDIHI(x) ((HI) (DI) (x))
286 #endif
287 #if defined (DI_FN_SUPPORT)
288 extern SI TRUNCDISI (DI);
289 #else
290 #define TRUNCDISI(x) ((SI) (DI) (x))
291 #endif
292 \f
293 /* Composing/decomposing the various types.
294    Word ordering is endian-independent.  Words are specified most to least
295    significant and word number 0 is the most significant word.
296    ??? May also wish an endian-dependent version.  Later.  */
297
298 QI SUBWORDSIQI (SI, int);
299 HI SUBWORDSIHI (SI, int);
300 QI SUBWORDDIQI (DI, int);
301 HI SUBWORDDIHI (DI, int);
302 SI SUBWORDDISI (DI, int);
303
304 #ifdef SEMOPS_DEFINE_INLINE
305
306 SEMOPS_INLINE QI
307 SUBWORDSIQI (SI in, int byte)
308 {
309   assert (byte >= 0 && byte <= 3);
310   return (UQI) (in >> (8 * (3 - byte))) & 0xFF;
311 }
312
313 SEMOPS_INLINE HI
314 SUBWORDSIHI (SI in, int word)
315 {
316   if (word == 0)
317     return (USI) in >> 16;
318   else
319     return in;
320 }
321
322 SEMOPS_INLINE QI
323 SUBWORDDIQI (DI in, int byte)
324 {
325   assert (byte >= 0 && byte <= 7);
326   return (UQI) (in >> (8 * (7 - byte))) & 0xFF;
327 }
328
329 SEMOPS_INLINE HI
330 SUBWORDDIHI (DI in, int word)
331 {
332   assert (word >= 0 && word <= 3);
333   return (UHI) (in >> (16 * (3 - word))) & 0xFFFF;
334 }
335
336 SEMOPS_INLINE SI
337 SUBWORDDISI (DI in, int word)
338 {
339   if (word == 0)
340     return (UDI) in >> 32;
341   else
342     return in;
343 }
344
345 #endif /* SUBWORD,JOIN */
346
347 #endif /* CGEN_BASIC_OPS_H */