* stack.c (print_frame_args): Fix typos in comments.
[deliverable/binutils-gdb.git] / opcodes / cgen-ops.h
CommitLineData
49f58d10 1/* Semantics ops support for CGEN-based opcode libraries.
9b201bb5 2 Copyright (C) 2005, 2007 Free Software Foundation, Inc.
49f58d10
JB
3 Contributed by Red Hat.
4
9b201bb5 5 This file is part of the GNU opcodes library.
49f58d10 6
9b201bb5
NC
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)
10 any later version.
49f58d10 11
9b201bb5
NC
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.
49f58d10 16
9b201bb5
NC
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. */
49f58d10
JB
20
21#ifndef CGEN_SEM_OPS_H
22#define CGEN_SEM_OPS_H
23
24#include <assert.h>
25
26#if defined (__GNUC__) && ! defined (SEMOPS_DEFINE_INLINE)
27#define SEMOPS_DEFINE_INLINE
28#define SEMOPS_INLINE extern inline
29#else
30#define SEMOPS_INLINE
31#endif
32
33/* TODO: Lazy encoding/decoding of fp values. */
34
35/* These don't really have a mode. */
36#define ANDIF(x, y) ((x) && (y))
37#define ORIF(x, y) ((x) || (y))
38
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))
56\f
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))
67extern QI RORQI (QI, int);
68extern 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))
86\f
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))
97extern HI RORHI (HI, int);
98extern 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))
116\f
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))
127extern SI RORSI (SI, int);
128extern 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))
146\f
147#ifdef DI_FN_SUPPORT
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);
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))
187extern DI RORDI (DI, int);
188extern 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 */
207\f
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)
212extern DI EXTBIDI (BI);
213#else
214#define EXTBIDI(x) ((DI) (BI) (x))
215#endif
216#define EXTQIHI(x) ((HI) (QI) (x))
217#define EXTQISI(x) ((SI) (QI) (x))
218#if defined (DI_FN_SUPPORT)
219extern DI EXTQIDI (QI);
220#else
221#define EXTQIDI(x) ((DI) (QI) (x))
222#endif
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)
227extern DI EXTHIDI (HI);
228#else
229#define EXTHIDI(x) ((DI) (HI) (x))
230#endif
231#if defined (DI_FN_SUPPORT)
232extern DI EXTSIDI (SI);
233#else
234#define EXTSIDI(x) ((DI) (SI) (x))
235#endif
236\f
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)
241extern DI ZEXTBIDI (BI);
242#else
243#define ZEXTBIDI(x) ((DI) (BI) (x))
244#endif
245#define ZEXTQIHI(x) ((HI) (UQI) (x))
246#define ZEXTQISI(x) ((SI) (UQI) (x))
247#if defined (DI_FN_SUPPORT)
248extern DI ZEXTQIDI (QI);
249#else
250#define ZEXTQIDI(x) ((DI) (UQI) (x))
251#endif
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)
256extern DI ZEXTHIDI (HI);
257#else
258#define ZEXTHIDI(x) ((DI) (UHI) (x))
259#endif
260#if defined (DI_FN_SUPPORT)
261extern DI ZEXTSIDI (SI);
262#else
263#define ZEXTSIDI(x) ((DI) (USI) (x))
264#endif
265\f
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)
274extern BI TRUNCDIBI (DI);
275#else
276#define TRUNCDIBI(x) ((BI) (DI) (x))
277#endif
278#if defined (DI_FN_SUPPORT)
279extern QI TRUNCDIQI (DI);
280#else
281#define TRUNCDIQI(x) ((QI) (DI) (x))
282#endif
283#if defined (DI_FN_SUPPORT)
284extern HI TRUNCDIHI (DI);
285#else
286#define TRUNCDIHI(x) ((HI) (DI) (x))
287#endif
288#if defined (DI_FN_SUPPORT)
289extern SI TRUNCDISI (DI);
290#else
291#define TRUNCDISI(x) ((SI) (DI) (x))
292#endif
293\f
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. */
298
299QI SUBWORDSIQI (SI, int);
300HI SUBWORDSIHI (SI, int);
301SI SUBWORDSFSI (SF);
302SF SUBWORDSISF (SI);
303DI SUBWORDDFDI (DF);
304DF SUBWORDDIDF (DI);
305QI SUBWORDDIQI (DI, int);
306HI SUBWORDDIHI (DI, int);
307SI SUBWORDDISI (DI, int);
308SI SUBWORDDFSI (DF, int);
309SI SUBWORDXFSI (XF, int);
310SI SUBWORDTFSI (TF, int);
311
312UQI SUBWORDSIUQI (SI, int);
313UQI SUBWORDDIUQI (DI, int);
314
315#ifdef SEMOPS_DEFINE_INLINE
316
317SEMOPS_INLINE SF
318SUBWORDSISF (SI in)
319{
320 union { SI in; SF out; } x;
321 x.in = in;
322 return x.out;
323}
324
325SEMOPS_INLINE DF
326SUBWORDDIDF (DI in)
327{
328 union { DI in; DF out; } x;
329 x.in = in;
330 return x.out;
331}
332
333SEMOPS_INLINE QI
334SUBWORDSIQI (SI in, int byte)
335{
336 assert (byte >= 0 && byte <= 3);
337 return (UQI) (in >> (8 * (3 - byte))) & 0xFF;
338}
339
340SEMOPS_INLINE UQI
341SUBWORDSIUQI (SI in, int byte)
342{
343 assert (byte >= 0 && byte <= 3);
344 return (UQI) (in >> (8 * (3 - byte))) & 0xFF;
345}
346
347SEMOPS_INLINE QI
348SUBWORDDIQI (DI in, int byte)
349{
350 assert (byte >= 0 && byte <= 7);
351 return (UQI) (in >> (8 * (7 - byte))) & 0xFF;
352}
353
354SEMOPS_INLINE HI
355SUBWORDDIHI (DI in, int word)
356{
357 assert (word >= 0 && word <= 3);
358 return (UHI) (in >> (16 * (3 - word))) & 0xFFFF;
359}
360
361SEMOPS_INLINE HI
362SUBWORDSIHI (SI in, int word)
363{
364 if (word == 0)
365 return (USI) in >> 16;
366 else
367 return in;
368}
369
370SEMOPS_INLINE SI
371SUBWORDSFSI (SF in)
372{
373 union { SF in; SI out; } x;
374 x.in = in;
375 return x.out;
376}
377
378SEMOPS_INLINE DI
379SUBWORDDFDI (DF in)
380{
381 union { DF in; DI out; } x;
382 x.in = in;
383 return x.out;
384}
385
386SEMOPS_INLINE UQI
387SUBWORDDIUQI (DI in, int byte)
388{
389 assert (byte >= 0 && byte <= 7);
390 return (UQI) (in >> (8 * (7 - byte)));
391}
392
393SEMOPS_INLINE SI
394SUBWORDDISI (DI in, int word)
395{
396 if (word == 0)
397 return (UDI) in >> 32;
398 else
399 return in;
400}
401
402SEMOPS_INLINE SI
403SUBWORDDFSI (DF in, int word)
404{
405 /* Note: typedef UDI DF; */
406 if (word == 0)
407 return (UDI) in >> 32;
408 else
409 return in;
410}
411
412SEMOPS_INLINE SI
413SUBWORDXFSI (XF in, int word)
414{
415 /* Note: typedef struct { SI parts[3]; } XF; */
416 union { XF in; SI out[3]; } x;
417 x.in = in;
418 return x.out[word];
419}
420
421SEMOPS_INLINE SI
422SUBWORDTFSI (TF in, int word)
423{
424 /* Note: typedef struct { SI parts[4]; } TF; */
425 union { TF in; SI out[4]; } x;
426 x.in = in;
427 return x.out[word];
428}
429
430#endif /* SUBWORD,JOIN */
431
432#endif /* CGEN_SEM_OPS_H */
This page took 0.160524 seconds and 4 git commands to generate.