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