Cleanup INLINE support for simulators using common framework.
[deliverable/binutils-gdb.git] / sim / common / sim-bits.h
CommitLineData
d6fea803
AC
1/* This file is part of the program psim.
2
3 Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>
4 Copyright (C) 1997, Free Software Foundation, Inc.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 */
21
22
23#ifndef _SIM_BITS_H_
24#define _SIM_BITS_H_
25
26
278bda40 27/* Bit manipulation routines:
d6fea803
AC
28
29 Bit numbering: The bits are numbered according to the target ISA's
30 convention. That being controlled by WITH_TARGET_WORD_MSB. For
31 the PowerPC (WITH_TARGET_WORD_MSB == 0) the numbering is 0..31
32 while for the MIPS (WITH_TARGET_WORD_MSB == 31) it is 31..0.
33
34 Size convention: Each macro is in three forms - <MACRO>32 which
35 operates in 32bit quantity (bits are numbered 0..31); <MACRO>64
36 which operates using 64bit quantites (and bits are numbered 0..63);
37 and <MACRO> which operates using the bit size of the target
38 architecture (bits are still numbered 0..63), with 32bit
39 architectures ignoring the first 32bits leaving bit 32 as the most
40 significant.
41
30efae3a
AC
42 NB: Use EXTRACTED, MSEXTRACTED and LSEXTRACTED as a guideline for
43 naming. LSMASK and LSMASKED are wrong.
44
278bda40 45 BIT*(POS): `*' bit constant with just 1 bit set.
d6fea803 46
278bda40
AC
47 LSBIT*(OFFSET): `*' bit constant with just 1 bit set - LS bit is
48 zero.
d6fea803 49
278bda40
AC
50 MSBIT*(OFFSET): `*' bit constant with just 1 bit set - MS bit is
51 zero.
d6fea803 52
278bda40
AC
53 MASK*(FIRST, LAST): `*' bit constant with bits [FIRST .. LAST]
54 set. The <MACRO> (no size) version permits FIRST >= LAST and
55 generates a wrapped bit mask vis ([0..LAST] | [FIRST..LSB]).
d6fea803 56
75b3697d 57 LSMASK*(FIRST, LAST): Like MASK - LS bit is zero.
d6fea803 58
75b3697d 59 MSMASK*(FIRST, LAST): Like MASK - LS bit is zero.
d6fea803
AC
60
61 MASKED*(VALUE, FIRST, LAST): Masks out all but bits [FIRST
62 .. LAST].
63
75b3697d 64 LSMASKED*(VALUE, FIRST, LAST): Like MASKED - LS bit is zero.
d6fea803 65
75b3697d 66 MSMASKED*(VALUE, FIRST, LAST): Like MASKED - MS bit is zero.
d6fea803
AC
67
68 EXTRACTED*(VALUE, FIRST, LAST): Masks out bits [FIRST .. LAST] but
69 also right shifts the masked value so that bit LAST becomes the
70 least significant (right most).
71
30efae3a
AC
72 LSEXTRACTED*(VALUE, FIRST, LAST): Same as extracted - LS bit is
73 zero.
74
75 MSEXTRACTED*(VALUE, FIRST, LAST): Same as extracted - MS bit is
76 zero.
77
d6fea803
AC
78 SHUFFLED**(VALUE, OLD, NEW): Mask then move a single bit from OLD
79 new NEW.
80
81 MOVED**(VALUE, OLD_FIRST, OLD_LAST, NEW_FIRST, NEW_LAST): Moves
82 things around so that bits OLD_FIRST..OLD_LAST are masked then
83 moved to NEW_FIRST..NEW_LAST.
84
85 INSERTED*(VALUE, FIRST, LAST): Takes VALUE and `inserts' the (LAST
86 - FIRST + 1) least significant bits into bit positions [ FIRST
87 .. LAST ]. This is almost the complement to EXTRACTED.
88
89 IEA_MASKED(SHOULD_MASK, ADDR): Convert the address to the targets
90 natural size. If in 32bit mode, discard the high 32bits.
91
278bda40
AC
92 EXTEND*(VALUE): Convert the `*' bit value to the targets natural
93 word size. Sign extend the value if needed.
94
95 ALIGN_*(VALUE): Round the value upwards so that it is aligned to a
96 `_*' byte boundary.
d6fea803 97
278bda40
AC
98 FLOOR_*(VALUE): Truncate the value so that it is aligned to a `_*'
99 byte boundary.
d6fea803 100
278bda40
AC
101 ROT*(VALUE, NR_BITS): Return the `*' bit VALUE rotated by NR_BITS
102 right (positive) or left (negative).
d6fea803 103
278bda40
AC
104 ROTL*(VALUE, NR_BITS): Return the `*' bit value rotated by NR_BITS
105 left. 0 <= NR_BITS <= `*'.
d6fea803 106
278bda40
AC
107 ROTR*(VALUE, NR_BITS): Return the `*' bit value rotated by NR_BITS
108 right. 0 <= NR_BITS <= N.
d6fea803 109
278bda40
AC
110 SEXT*(VALUE, SIGN_BIT): Treat SIGN_BIT as VALUEs sign, extend it ti
111 `*' bits.
d6fea803
AC
112
113 Note: Only the BIT* and MASK* macros return a constant that can be
114 used in variable declarations.
115
116 */
117
118
119/* compute the number of bits between START and STOP */
120
121#if (WITH_TARGET_WORD_MSB == 0)
122#define _MAKE_WIDTH(START, STOP) (STOP - START + 1)
123#else
124#define _MAKE_WIDTH(START, STOP) (START - STOP + 1)
125#endif
126
127
128
129/* compute the number shifts required to move a bit between LSB (MSB)
130 and POS */
131
132#if (WITH_TARGET_WORD_MSB == 0)
133#define _LSB_SHIFT(WIDTH, POS) (WIDTH - 1 - POS)
134#else
135#define _LSB_SHIFT(WIDTH, POS) (POS)
136#endif
137
138#if (WITH_TARGET_WORD_MSB == 0)
139#define _MSB_SHIFT(WIDTH, POS) (POS)
140#else
141#define _MSB_SHIFT(WIDTH, POS) (WIDTH - 1 - POS)
142#endif
143
144
145/* compute the absolute bit position given the OFFSET from the MSB(LSB)
146 NB: _MAKE_xxx_POS (WIDTH, _MAKE_xxx_SHIFT (WIDTH, POS)) == POS */
147
148#if (WITH_TARGET_WORD_MSB == 0)
149#define _MSB_POS(WIDTH, SHIFT) (SHIFT)
150#else
151#define _MSB_POS(WIDTH, SHIFT) (WIDTH - 1 - SHIFT)
152#endif
153
154#if (WITH_TARGET_WORD_MSB == 0)
155#define _LSB_POS(WIDTH, SHIFT) (WIDTH - 1 - SHIFT)
156#else
157#define _LSB_POS(WIDTH, SHIFT) (SHIFT)
158#endif
159
160
161/* convert a 64 bit position into a corresponding 32bit position. MSB
162 pos handles the posibility that the bit lies beyond the 32bit
163 boundary */
164
165#if (WITH_TARGET_WORD_MSB == 0)
166#define _MSB_32(START, STOP) (START <= STOP \
167 ? (START < 32 ? 0 : START - 32) \
168 : (STOP < 32 ? 0 : STOP - 32))
169#else
170#define _MSB_32(START, STOP) (START >= STOP \
171 ? (START >= 32 ? 31 : START) \
172 : (STOP >= 32 ? 31 : STOP))
173#endif
174
175#if (WITH_TARGET_WORD_MSB == 0)
176#define _LSB_32(START, STOP) (START <= STOP \
177 ? (STOP < 32 ? 0 : STOP - 32) \
178 : (START < 32 ? 0 : START - 32))
179#else
180#define _LSB_32(START, STOP) (START >= STOP \
181 ? (STOP >= 32 ? 31 : STOP) \
182 : (START >= 32 ? 31 : START))
183#endif
184
185#if (WITH_TARGET_WORD_MSB == 0)
186#define _MSB(START, STOP) (START <= STOP ? START : STOP)
187#else
188#define _MSB(START, STOP) (START >= STOP ? START : STOP)
189#endif
190
191#if (WITH_TARGET_WORD_MSB == 0)
192#define _LSB(START, STOP) (START <= STOP ? STOP : START)
193#else
194#define _LSB(START, STOP) (START >= STOP ? STOP : START)
195#endif
196
197
75b3697d
AC
198/* LS/MS Bit operations */
199
293a0876
AC
200#define LSBIT8(POS) ((unsigned8) 1 << (POS))
201#define LSBIT16(POS) ((unsigned16)1 << (POS))
202#define LSBIT32(POS) ((unsigned32)1 << (POS))
203#define LSBIT64(POS) ((unsigned64)1 << (POS))
75b3697d 204
b52e58c2
AC
205#if (WITH_TARGET_WORD_BITSIZE == 64)
206#define LSBIT(POS) LSBIT64 (POS)
207#else
293a0876
AC
208#define LSBIT(POS) ((unsigned32)((POS) >= 32 \
209 ? 0 \
210 : (1 << ((POS) >= 32 ? 0 : (POS)))))
b52e58c2 211#endif
75b3697d
AC
212
213
293a0876
AC
214#define MSBIT8(POS) ((unsigned8) 1 << ( 8 - 1 - (POS)))
215#define MSBIT16(POS) ((unsigned16)1 << (16 - 1 - (POS)))
216#define MSBIT32(POS) ((unsigned32)1 << (32 - 1 - (POS)))
217#define MSBIT64(POS) ((unsigned64)1 << (64 - 1 - (POS)))
b52e58c2
AC
218
219#if (WITH_TARGET_WORD_BITSIZE == 64)
220#define MSBIT(POS) MSBIT64 (POS)
221#else
293a0876
AC
222#define MSBIT(POS) ((unsigned32)((POS) < 32 \
223 ? 0 \
224 : (1 << ((POS) < 32 ? 0 : (64 - 1) - (POS)))))
b52e58c2 225#endif
d6fea803 226
b52e58c2
AC
227
228/* Bit operations */
d6fea803
AC
229
230#define BIT4(POS) (1 << _LSB_SHIFT (4, (POS)))
231#define BIT5(POS) (1 << _LSB_SHIFT (5, (POS)))
d6fea803 232#define BIT10(POS) (1 << _LSB_SHIFT (10, (POS)))
d6fea803 233
d6fea803 234#if (WITH_TARGET_WORD_MSB == 0)
b52e58c2
AC
235#define BIT8 MSBIT8
236#define BIT16 MSBIT16
237#define BIT32 MSBIT32
238#define BIT64 MSBIT64
239#define BIT MSBIT
d6fea803 240#else
b52e58c2
AC
241#define BIT8 LSBIT8
242#define BIT16 LSBIT16
243#define BIT32 LSBIT32
244#define BIT64 LSBIT64
245#define BIT LSBIT
d6fea803
AC
246#endif
247
248
b52e58c2 249
d6fea803
AC
250/* multi bit mask */
251
252/* 111111 -> mmll11 -> mm11ll */
253#define _MASKn(WIDTH, START, STOP) (((unsigned##WIDTH)(-1) \
254 >> (_MSB_SHIFT (WIDTH, START) \
255 + _LSB_SHIFT (WIDTH, STOP))) \
256 << _LSB_SHIFT (WIDTH, STOP))
257
d6fea803
AC
258#if (WITH_TARGET_WORD_MSB == 0)
259#define _POS_LE(START, STOP) (START <= STOP)
260#else
261#define _POS_LE(START, STOP) (STOP <= START)
262#endif
263
264#if (WITH_TARGET_WORD_BITSIZE == 64)
265#define MASK(START, STOP) \
266 (_POS_LE ((START), (STOP)) \
267 ? _MASKn(64, \
268 _MSB ((START), (STOP)), \
269 _LSB ((START), (STOP)) ) \
270 : (_MASKn(64, _MSB_POS (64, 0), (STOP)) \
271 | _MASKn(64, (START), _LSB_POS (64, 0))))
272#endif
273#if (WITH_TARGET_WORD_BITSIZE == 32)
274#define MASK(START, STOP) \
275 (_POS_LE ((START), (STOP)) \
276 ? (_POS_LE ((STOP), _MSB_POS (64, 31)) \
277 ? 0 \
278 : _MASKn (32, \
279 _MSB_32 ((START), (STOP)), \
280 _LSB_32 ((START), (STOP)))) \
281 : (_MASKn (32, \
282 _LSB_32 ((START), (STOP)), \
283 _LSB_POS (32, 0)) \
284 | (_POS_LE ((STOP), _MSB_POS (64, 31)) \
285 ? 0 \
286 : _MASKn (32, \
287 _MSB_POS (32, 0), \
288 _MSB_32 ((START), (STOP))))))
289#endif
290#if !defined (MASK)
291#error "MASK never undefined"
292#endif
293
294
d6fea803
AC
295/* Multi-bit mask on least significant bits */
296
75b3697d
AC
297#define _LSMASKn(WIDTH, FIRST, LAST) _MASKn (WIDTH, \
298 _LSB_POS (WIDTH, FIRST), \
299 _LSB_POS (WIDTH, LAST))
d6fea803 300
b52e58c2 301#define LSMASK8(FIRST, LAST) _LSMASKn ( 8, (FIRST), (LAST))
75b3697d
AC
302#define LSMASK16(FIRST, LAST) _LSMASKn (16, (FIRST), (LAST))
303#define LSMASK32(FIRST, LAST) _LSMASKn (32, (FIRST), (LAST))
304#define LSMASK64(FIRST, LAST) _LSMASKn (64, (FIRST), (LAST))
d6fea803 305
75b3697d 306#define LSMASK(FIRST, LAST) (MASK (_LSB_POS (64, FIRST), _LSB_POS (64, LAST)))
d6fea803
AC
307
308
309/* Multi-bit mask on most significant bits */
310
75b3697d
AC
311#define _MSMASKn(WIDTH, FIRST, LAST) _MASKn (WIDTH, \
312 _MSB_POS (WIDTH, FIRST), \
313 _MSB_POS (WIDTH, LAST))
d6fea803 314
b52e58c2 315#define MSMASK8(FIRST, LAST) _MSMASKn ( 8, (FIRST), (LAST))
75b3697d
AC
316#define MSMASK16(FIRST, LAST) _MSMASKn (16, (FIRST), (LAST))
317#define MSMASK32(FIRST, LAST) _MSMASKn (32, (FIRST), (LAST))
318#define MSMASK64(FIRST, LAST) _MSMASKn (64, (FIRST), (LAST))
d6fea803 319
75b3697d 320#define MSMASK(FIRST, LAST) (MASK (_MSB_POS (64, FIRST), _MSB_POS (64, LAST)))
d6fea803 321
d6fea803 322
d6fea803 323
75b3697d 324#if (WITH_TARGET_WORD_MSB == 0)
b52e58c2 325#define MASK8 MSMASK8
75b3697d
AC
326#define MASK16 MSMASK16
327#define MASK32 MSMASK32
328#define MASK64 MSMASK64
329#else
b52e58c2 330#define MASK8 LSMASK8
75b3697d
AC
331#define MASK16 LSMASK16
332#define MASK32 LSMASK32
333#define MASK64 LSMASK64
334#endif
d6fea803
AC
335
336
d6fea803 337
75b3697d 338/* mask the required bits, leaving them in place */
d6fea803 339
b52e58c2 340INLINE_SIM_BITS(unsigned8) LSMASKED8 (unsigned8 word, int first, int last);
75b3697d
AC
341INLINE_SIM_BITS(unsigned16) LSMASKED16 (unsigned16 word, int first, int last);
342INLINE_SIM_BITS(unsigned32) LSMASKED32 (unsigned32 word, int first, int last);
343INLINE_SIM_BITS(unsigned64) LSMASKED64 (unsigned64 word, int first, int last);
d6fea803 344
75b3697d 345INLINE_SIM_BITS(unsigned_word) LSMASKED (unsigned_word word, int first, int last);
d6fea803 346
b52e58c2 347INLINE_SIM_BITS(unsigned8) MSMASKED8 (unsigned8 word, int first, int last);
75b3697d
AC
348INLINE_SIM_BITS(unsigned16) MSMASKED16 (unsigned16 word, int first, int last);
349INLINE_SIM_BITS(unsigned32) MSMASKED32 (unsigned32 word, int first, int last);
350INLINE_SIM_BITS(unsigned64) MSMASKED64 (unsigned64 word, int first, int last);
d6fea803 351
75b3697d 352INLINE_SIM_BITS(unsigned_word) MSMASKED (unsigned_word word, int first, int last);
d6fea803 353
75b3697d 354#if (WITH_TARGET_WORD_MSB == 0)
b52e58c2 355#define MASKED8 MSMASKED8
75b3697d
AC
356#define MASKED16 MSMASKED16
357#define MASKED32 MSMASKED32
358#define MASKED64 MSMASKED64
b52e58c2 359#define MASKED MSMASKED
75b3697d 360#else
b52e58c2 361#define MASKED8 LSMASKED8
75b3697d
AC
362#define MASKED16 LSMASKED16
363#define MASKED32 LSMASKED32
364#define MASKED64 LSMASKED64
365#define MASKED LSMASKED
366#endif
d6fea803
AC
367
368
369
370/* extract the required bits aligning them with the lsb */
371
b52e58c2 372INLINE_SIM_BITS(unsigned8) LSEXTRACTED8 (unsigned8 val, int start, int stop);
75b3697d
AC
373INLINE_SIM_BITS(unsigned16) LSEXTRACTED16 (unsigned16 val, int start, int stop);
374INLINE_SIM_BITS(unsigned32) LSEXTRACTED32 (unsigned32 val, int start, int stop);
375INLINE_SIM_BITS(unsigned64) LSEXTRACTED64 (unsigned64 val, int start, int stop);
376
377INLINE_SIM_BITS(unsigned_word) LSEXTRACTED (unsigned_word val, int start, int stop);
30efae3a 378
b52e58c2 379INLINE_SIM_BITS(unsigned8) MSEXTRACTED8 (unsigned8 val, int start, int stop);
75b3697d
AC
380INLINE_SIM_BITS(unsigned16) MSEXTRACTED16 (unsigned16 val, int start, int stop);
381INLINE_SIM_BITS(unsigned32) MSEXTRACTED32 (unsigned32 val, int start, int stop);
382INLINE_SIM_BITS(unsigned64) MSEXTRACTED64 (unsigned64 val, int start, int stop);
383
384INLINE_SIM_BITS(unsigned_word) MSEXTRACTED (unsigned_word val, int start, int stop);
30efae3a
AC
385
386#if (WITH_TARGET_WORD_MSB == 0)
b52e58c2 387#define EXTRACTED8 MSEXTRACTED8
75b3697d 388#define EXTRACTED16 MSEXTRACTED16
30efae3a 389#define EXTRACTED32 MSEXTRACTED32
75b3697d
AC
390#define EXTRACTED64 MSEXTRACTED64
391#define EXTRACTED MSEXTRACTED
30efae3a 392#else
b52e58c2 393#define EXTRACTED8 LSEXTRACTED8
75b3697d 394#define EXTRACTED16 LSEXTRACTED16
30efae3a 395#define EXTRACTED32 LSEXTRACTED32
75b3697d
AC
396#define EXTRACTED64 LSEXTRACTED64
397#define EXTRACTED LSEXTRACTED
30efae3a
AC
398#endif
399
400
401
d6fea803
AC
402/* move a single bit around */
403/* NB: the wierdness (N>O?N-O:0) is to stop a warning from GCC */
404#define _SHUFFLEDn(N, WORD, OLD, NEW) \
405((OLD) < (NEW) \
406 ? (((unsigned##N)(WORD) \
407 >> (((NEW) > (OLD)) ? ((NEW) - (OLD)) : 0)) \
408 & MASK32((NEW), (NEW))) \
409 : (((unsigned##N)(WORD) \
410 << (((OLD) > (NEW)) ? ((OLD) - (NEW)) : 0)) \
411 & MASK32((NEW), (NEW))))
412
413#define SHUFFLED32(WORD, OLD, NEW) _SHUFFLEDn (32, WORD, OLD, NEW)
414#define SHUFFLED64(WORD, OLD, NEW) _SHUFFLEDn (64, WORD, OLD, NEW)
415
416#define SHUFFLED(WORD, OLD, NEW) _SHUFFLEDn (_word, WORD, OLD, NEW)
417
418
293a0876 419/* Insert a group of bits into a bit position */
d6fea803 420
b52e58c2 421INLINE_SIM_BITS(unsigned8) LSINSERTED8 (unsigned8 val, int start, int stop);
aa5e6a5a
AC
422INLINE_SIM_BITS(unsigned16) LSINSERTED16 (unsigned16 val, int start, int stop);
423INLINE_SIM_BITS(unsigned32) LSINSERTED32 (unsigned32 val, int start, int stop);
424INLINE_SIM_BITS(unsigned64) LSINSERTED64 (unsigned64 val, int start, int stop);
425INLINE_SIM_BITS(unsigned_word) LSINSERTED (unsigned_word val, int start, int stop);
75b3697d 426
b52e58c2 427INLINE_SIM_BITS(unsigned8) MSINSERTED8 (unsigned8 val, int start, int stop);
aa5e6a5a
AC
428INLINE_SIM_BITS(unsigned16) MSINSERTED16 (unsigned16 val, int start, int stop);
429INLINE_SIM_BITS(unsigned32) MSINSERTED32 (unsigned32 val, int start, int stop);
430INLINE_SIM_BITS(unsigned64) MSINSERTED64 (unsigned64 val, int start, int stop);
431INLINE_SIM_BITS(unsigned_word) MSINSERTED (unsigned_word val, int start, int stop);
432
433#if (WITH_TARGET_WORD_MSB == 0)
b52e58c2 434#define INSERTED8 MSINSERTED8
aa5e6a5a
AC
435#define INSERTED16 MSINSERTED16
436#define INSERTED32 MSINSERTED32
437#define INSERTED64 MSINSERTED64
438#define INSERTED MSINSERTED
439#else
b52e58c2 440#define INSERTED8 LSINSERTED8
aa5e6a5a
AC
441#define INSERTED16 LSINSERTED16
442#define INSERTED32 LSINSERTED32
443#define INSERTED64 LSINSERTED64
444#define INSERTED LSINSERTED
445#endif
75b3697d 446
d6fea803 447
d6fea803 448
293a0876
AC
449/* MOVE bits from one loc to another (combination of extract/insert) */
450
451#define MOVED8(VAL,OH,OL,NH,NL) INSERTED8 (EXTRACTED8 ((VAL), OH, OL), NH, NL)
452#define MOVED16(VAL,OH,OL,NH,NL) INSERTED16(EXTRACTED16((VAL), OH, OL), NH, NL)
453#define MOVED32(VAL,OH,OL,NH,NL) INSERTED32(EXTRACTED32((VAL), OH, OL), NH, NL)
454#define MOVED64(VAL,OH,OL,NH,NL) INSERTED64(EXTRACTED64((VAL), OH, OL), NH, NL)
455#define MOVED(VAL,OH,OL,NH,NL) INSERTED (EXTRACTED ((VAL), OH, OL), NH, NL)
456
457
458
75b3697d 459/* Sign extend the quantity to the targets natural word size */
d6fea803 460
293a0876 461#define EXTEND8(X) ((signed_word)(signed8)(X))
75b3697d
AC
462#define EXTEND16(X) ((signed_word)(signed16)(X))
463#define EXTEND32(X) ((signed_word)(signed32)(X))
464#define EXTEND64(X) ((signed_word)(signed64)(X))
d6fea803
AC
465
466/* depending on MODE return a 64bit or 32bit (sign extended) value */
467#if (WITH_TARGET_WORD_BITSIZE == 64)
468#define EXTENDED(X) ((signed64)(signed32)(X))
469#endif
470#if (WITH_TARGET_WORD_BITSIZE == 32)
471#define EXTENDED(X) (X)
472#endif
473
474
475/* memory alignment macro's */
476#define _ALIGNa(A,X) (((X) + ((A) - 1)) & ~((A) - 1))
477#define _FLOORa(A,X) ((X) & ~((A) - 1))
478
479#define ALIGN_8(X) _ALIGNa (8, X)
480#define ALIGN_16(X) _ALIGNa (16, X)
481
482#define ALIGN_PAGE(X) _ALIGNa (0x1000, X)
483#define FLOOR_PAGE(X) ((X) & ~(0x1000 - 1))
484
485
486/* bit bliting macro's */
487#define BLIT32(V, POS, BIT) \
488do { \
489 if (BIT) \
490 V |= BIT32 (POS); \
491 else \
492 V &= ~BIT32 (POS); \
493} while (0)
494#define MBLIT32(V, LO, HI, VAL) \
495do { \
496 (V) = (((V) & ~MASK32 ((LO), (HI))) \
497 | INSERTED32 (VAL, LO, HI)); \
498} while (0)
499
500
501
502/* some rotate functions. The generic macro's ROT, ROTL, ROTR are
503 intentionally omited. */
504
505
b52e58c2 506INLINE_SIM_BITS(unsigned8) ROT8 (unsigned8 val, int shift);
d6fea803
AC
507INLINE_SIM_BITS(unsigned16) ROT16 (unsigned16 val, int shift);
508INLINE_SIM_BITS(unsigned32) ROT32 (unsigned32 val, int shift);
509INLINE_SIM_BITS(unsigned64) ROT64 (unsigned64 val, int shift);
510
511
b52e58c2 512INLINE_SIM_BITS(unsigned8) ROTL8 (unsigned8 val, int shift);
75b3697d
AC
513INLINE_SIM_BITS(unsigned16) ROTL16 (unsigned16 val, int shift);
514INLINE_SIM_BITS(unsigned32) ROTL32 (unsigned32 val, int shift);
515INLINE_SIM_BITS(unsigned64) ROTL64 (unsigned64 val, int shift);
d6fea803
AC
516
517
b52e58c2 518INLINE_SIM_BITS(unsigned8) ROTR8 (unsigned8 val, int shift);
75b3697d
AC
519INLINE_SIM_BITS(unsigned16) ROTR16 (unsigned16 val, int shift);
520INLINE_SIM_BITS(unsigned32) ROTR32 (unsigned32 val, int shift);
521INLINE_SIM_BITS(unsigned64) ROTR64 (unsigned64 val, int shift);
d6fea803
AC
522
523
524
525/* Sign extension operations */
526
b52e58c2 527INLINE_SIM_BITS(unsigned8) LSSEXT8 (signed8 val, int sign_bit);
aa5e6a5a
AC
528INLINE_SIM_BITS(unsigned16) LSSEXT16 (signed16 val, int sign_bit);
529INLINE_SIM_BITS(unsigned32) LSSEXT32 (signed32 val, int sign_bit);
530INLINE_SIM_BITS(unsigned64) LSSEXT64 (signed64 val, int sign_bit);
531INLINE_SIM_BITS(unsigned_word) LSSEXT (signed_word val, int sign_bit);
d6fea803 532
b52e58c2 533INLINE_SIM_BITS(unsigned8) MSSEXT8 (signed8 val, int sign_bit);
aa5e6a5a
AC
534INLINE_SIM_BITS(unsigned16) MSSEXT16 (signed16 val, int sign_bit);
535INLINE_SIM_BITS(unsigned32) MSSEXT32 (signed32 val, int sign_bit);
536INLINE_SIM_BITS(unsigned64) MSSEXT64 (signed64 val, int sign_bit);
537INLINE_SIM_BITS(unsigned_word) MSSEXT (signed_word val, int sign_bit);
538
539#if (WITH_TARGET_WORD_MSB == 0)
b52e58c2 540#define SEXT8 MSSEXT8
aa5e6a5a
AC
541#define SEXT16 MSSEXT16
542#define SEXT32 MSSEXT32
543#define SEXT64 MSSEXT64
544#define SEXT MSSEXT
545#else
b52e58c2 546#define SEXT8 LSSEXT8
aa5e6a5a
AC
547#define SEXT16 LSSEXT16
548#define SEXT32 LSSEXT32
549#define SEXT64 LSSEXT64
550#define SEXT LSSEXT
551#endif
d6fea803
AC
552
553
554
278bda40 555#if H_REVEALS_MODULE_P (SIM_BITS_INLINE)
d6fea803
AC
556#include "sim-bits.c"
557#endif
558
559#endif /* _SIM_BITS_H_ */
This page took 0.117411 seconds and 4 git commands to generate.