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