OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [sim/] [common/] [sim-bits.h] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/*  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
 
42
   NB: Use EXTRACTED, MSEXTRACTED and LSEXTRACTED as a guideline for
43
   naming.  LSMASK and LSMASKED are wrong.
44
 
45
   BIT*(POS): `*' bit constant with just 1 bit set.
46
 
47
   LSBIT*(OFFSET): `*' bit constant with just 1 bit set - LS bit is
48
   zero.
49
 
50
   MSBIT*(OFFSET): `*' bit constant with just 1 bit set - MS bit is
51
   zero.
52
 
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]).
56
 
57
   LSMASK*(FIRST, LAST): Like MASK - LS bit is zero.
58
 
59
   MSMASK*(FIRST, LAST): Like MASK - LS bit is zero.
60
 
61
   MASKED*(VALUE, FIRST, LAST): Masks out all but bits [FIRST
62
   .. LAST].
63
 
64
   LSMASKED*(VALUE, FIRST, LAST): Like MASKED - LS bit is zero.
65
 
66
   MSMASKED*(VALUE, FIRST, LAST): Like MASKED - MS bit is zero.
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
 
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
 
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
 
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.
97
 
98
   FLOOR_*(VALUE): Truncate the value so that it is aligned to a `_*'
99
   byte boundary.
100
 
101
   ROT*(VALUE, NR_BITS): Return the `*' bit VALUE rotated by NR_BITS
102
   right (positive) or left (negative).
103
 
104
   ROTL*(VALUE, NR_BITS): Return the `*' bit value rotated by NR_BITS
105
   left.  0 <= NR_BITS <= `*'.
106
 
107
   ROTR*(VALUE, NR_BITS): Return the `*' bit value rotated by NR_BITS
108
   right.  0 <= NR_BITS <= N.
109
 
110
   SEXT*(VALUE, SIGN_BIT): Treat SIGN_BIT as VALUEs sign, extend it ti
111
   `*' bits.
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
#define _MSB_16(START, STOP) (START <= STOP \
170
                              ? (START < 48 ? 0 : START - 48) \
171
                              : (STOP < 48 ? 0 : STOP - 48))
172
#else
173
#define _MSB_32(START, STOP) (START >= STOP \
174
                              ? (START >= 32 ? 31 : START) \
175
                              : (STOP >= 32 ? 31 : STOP))
176
#define _MSB_16(START, STOP) (START >= STOP \
177
                              ? (START >= 16 ? 15 : START) \
178
                              : (STOP >= 16 ? 15 : STOP))
179
#endif
180
 
181
#if (WITH_TARGET_WORD_MSB == 0)
182
#define _LSB_32(START, STOP) (START <= STOP \
183
                              ? (STOP < 32 ? 0 : STOP - 32) \
184
                              : (START < 32 ? 0 : START - 32))
185
#define _LSB_16(START, STOP) (START <= STOP \
186
                              ? (STOP < 48 ? 0 : STOP - 48) \
187
                              : (START < 48 ? 0 : START - 48))
188
#else
189
#define _LSB_32(START, STOP) (START >= STOP \
190
                              ? (STOP >= 32 ? 31 : STOP) \
191
                              : (START >= 32 ? 31 : START))
192
#define _LSB_16(START, STOP) (START >= STOP \
193
                              ? (STOP >= 16 ? 15 : STOP) \
194
                              : (START >= 16 ? 15 : START))
195
#endif
196
 
197
#if (WITH_TARGET_WORD_MSB == 0)
198
#define _MSB(START, STOP) (START <= STOP ? START : STOP)
199
#else
200
#define _MSB(START, STOP) (START >= STOP ? START : STOP)
201
#endif
202
 
203
#if (WITH_TARGET_WORD_MSB == 0)
204
#define _LSB(START, STOP) (START <= STOP ? STOP : START)
205
#else
206
#define _LSB(START, STOP) (START >= STOP ? STOP : START)
207
#endif
208
 
209
 
210
/* LS/MS Bit operations */
211
 
212
#define LSBIT8(POS)  ((unsigned8) 1 << (POS))
213
#define LSBIT16(POS) ((unsigned16)1 << (POS))
214
#define LSBIT32(POS) ((unsigned32)1 << (POS))
215
#define LSBIT64(POS) ((unsigned64)1 << (POS))
216
 
217
#if (WITH_TARGET_WORD_BITSIZE == 64)
218
#define LSBIT(POS) LSBIT64 (POS)
219
#endif
220
#if (WITH_TARGET_WORD_BITSIZE == 32)
221
#define LSBIT(POS) ((unsigned32)((POS) >= 32 \
222
                                 ? 0 \
223
                                 : (1 << ((POS) >= 32 ? 0 : (POS)))))
224
#endif
225
#if (WITH_TARGET_WORD_BITSIZE == 16)
226
#define LSBIT(POS) ((unsigned16)((POS) >= 16 \
227
                                 ? 0 \
228
                                 : (1 << ((POS) >= 16 ? 0 : (POS)))))
229
#endif
230
 
231
 
232
#define MSBIT8(POS)  ((unsigned8) 1 << ( 8 - 1 - (POS)))
233
#define MSBIT16(POS) ((unsigned16)1 << (16 - 1 - (POS)))
234
#define MSBIT32(POS) ((unsigned32)1 << (32 - 1 - (POS)))
235
#define MSBIT64(POS) ((unsigned64)1 << (64 - 1 - (POS)))
236
 
237
#if (WITH_TARGET_WORD_BITSIZE == 64)
238
#define MSBIT(POS) MSBIT64 (POS)
239
#endif
240
#if (WITH_TARGET_WORD_BITSIZE == 32)
241
#define MSBIT(POS) ((unsigned32)((POS) < 32 \
242
                                 ? 0 \
243
                                 : (1 << ((POS) < 32 ? 0 : (64 - 1) - (POS)))))
244
#endif
245
#if (WITH_TARGET_WORD_BITSIZE == 16)
246
#define MSBIT(POS) ((unsigned16)((POS) < 48 \
247
                                 ? 0 \
248
                                 : (1 << ((POS) < 48 ? 0 : (64 - 1) - (POS)))))
249
#endif
250
 
251
 
252
/* Bit operations */
253
 
254
#define BIT4(POS)  (1 << _LSB_SHIFT (4, (POS)))
255
#define BIT5(POS)  (1 << _LSB_SHIFT (5, (POS)))
256
#define BIT10(POS) (1 << _LSB_SHIFT (10, (POS)))
257
 
258
#if (WITH_TARGET_WORD_MSB == 0)
259
#define BIT8  MSBIT8
260
#define BIT16 MSBIT16
261
#define BIT32 MSBIT32
262
#define BIT64 MSBIT64
263
#define BIT   MSBIT
264
#else
265
#define BIT8  LSBIT8
266
#define BIT16 LSBIT16
267
#define BIT32 LSBIT32
268
#define BIT64 LSBIT64
269
#define BIT   LSBIT
270
#endif
271
 
272
 
273
 
274
/* multi bit mask */
275
 
276
/* 111111 -> mmll11 -> mm11ll */
277
#define _MASKn(WIDTH, START, STOP) (((unsigned##WIDTH)(-1) \
278
                                     >> (_MSB_SHIFT (WIDTH, START) \
279
                                         + _LSB_SHIFT (WIDTH, STOP))) \
280
                                    << _LSB_SHIFT (WIDTH, STOP))
281
 
282
#if (WITH_TARGET_WORD_MSB == 0)
283
#define _POS_LE(START, STOP) (START <= STOP)
284
#else
285
#define _POS_LE(START, STOP) (STOP <= START)
286
#endif
287
 
288
#if (WITH_TARGET_WORD_BITSIZE == 64)
289
#define MASK(START, STOP) \
290
     (_POS_LE ((START), (STOP)) \
291
      ? _MASKn(64, \
292
               _MSB ((START), (STOP)), \
293
               _LSB ((START), (STOP)) ) \
294
      : (_MASKn(64, _MSB_POS (64, 0), (STOP)) \
295
         | _MASKn(64, (START), _LSB_POS (64, 0))))
296
#endif
297
#if (WITH_TARGET_WORD_BITSIZE == 32)
298
#define MASK(START, STOP) \
299
     (_POS_LE ((START), (STOP)) \
300
      ? (_POS_LE ((STOP), _MSB_POS (64, 31)) \
301
         ? 0 \
302
         : _MASKn (32, \
303
                   _MSB_32 ((START), (STOP)), \
304
                   _LSB_32 ((START), (STOP)))) \
305
      : (_MASKn (32, \
306
                 _LSB_32 ((START), (STOP)), \
307
                 _LSB_POS (32, 0)) \
308
         | (_POS_LE ((STOP), _MSB_POS (64, 31)) \
309
            ? 0 \
310
            : _MASKn (32, \
311
                      _MSB_POS (32, 0), \
312
                      _MSB_32 ((START), (STOP))))))
313
#endif
314
#if (WITH_TARGET_WORD_BITSIZE == 16)
315
#define MASK(START, STOP) \
316
     (_POS_LE ((START), (STOP)) \
317
      ? (_POS_LE ((STOP), _MSB_POS (64, 15)) \
318
         ? 0 \
319
         : _MASKn (16, \
320
                   _MSB_16 ((START), (STOP)), \
321
                   _LSB_16 ((START), (STOP)))) \
322
      : (_MASKn (16, \
323
                 _LSB_16 ((START), (STOP)), \
324
                 _LSB_POS (16, 0)) \
325
         | (_POS_LE ((STOP), _MSB_POS (64, 15)) \
326
            ? 0 \
327
            : _MASKn (16, \
328
                      _MSB_POS (16, 0), \
329
                      _MSB_16 ((START), (STOP))))))
330
#endif
331
#if !defined (MASK)
332
#error "MASK never undefined"
333
#endif
334
 
335
 
336
/* Multi-bit mask on least significant bits */
337
 
338
#define _LSMASKn(WIDTH, FIRST, LAST) _MASKn (WIDTH, \
339
                                             _LSB_POS (WIDTH, FIRST), \
340
                                             _LSB_POS (WIDTH, LAST))
341
 
342
#define LSMASK8(FIRST, LAST)   _LSMASKn ( 8, (FIRST), (LAST))
343
#define LSMASK16(FIRST, LAST)  _LSMASKn (16, (FIRST), (LAST))
344
#define LSMASK32(FIRST, LAST)  _LSMASKn (32, (FIRST), (LAST))
345
#define LSMASK64(FIRST, LAST)  _LSMASKn (64, (FIRST), (LAST))
346
 
347
#define LSMASK(FIRST, LAST) (MASK (_LSB_POS (64, FIRST), _LSB_POS (64, LAST)))
348
 
349
 
350
/* Multi-bit mask on most significant bits */
351
 
352
#define _MSMASKn(WIDTH, FIRST, LAST) _MASKn (WIDTH, \
353
                                             _MSB_POS (WIDTH, FIRST), \
354
                                             _MSB_POS (WIDTH, LAST))
355
 
356
#define MSMASK8(FIRST, LAST)  _MSMASKn ( 8, (FIRST), (LAST))
357
#define MSMASK16(FIRST, LAST) _MSMASKn (16, (FIRST), (LAST))
358
#define MSMASK32(FIRST, LAST) _MSMASKn (32, (FIRST), (LAST))
359
#define MSMASK64(FIRST, LAST) _MSMASKn (64, (FIRST), (LAST))
360
 
361
#define MSMASK(FIRST, LAST) (MASK (_MSB_POS (64, FIRST), _MSB_POS (64, LAST)))
362
 
363
 
364
 
365
#if (WITH_TARGET_WORD_MSB == 0)
366
#define MASK8  MSMASK8
367
#define MASK16 MSMASK16
368
#define MASK32 MSMASK32
369
#define MASK64 MSMASK64
370
#else
371
#define MASK8  LSMASK8
372
#define MASK16 LSMASK16
373
#define MASK32 LSMASK32
374
#define MASK64 LSMASK64
375
#endif
376
 
377
 
378
 
379
/* mask the required bits, leaving them in place */
380
 
381
INLINE_SIM_BITS(unsigned8)  LSMASKED8  (unsigned8  word, int first, int last);
382
INLINE_SIM_BITS(unsigned16) LSMASKED16 (unsigned16 word, int first, int last);
383
INLINE_SIM_BITS(unsigned32) LSMASKED32 (unsigned32 word, int first, int last);
384
INLINE_SIM_BITS(unsigned64) LSMASKED64 (unsigned64 word, int first, int last);
385
 
386
INLINE_SIM_BITS(unsigned_word) LSMASKED (unsigned_word word, int first, int last);
387
 
388
INLINE_SIM_BITS(unsigned8)  MSMASKED8  (unsigned8  word, int first, int last);
389
INLINE_SIM_BITS(unsigned16) MSMASKED16 (unsigned16 word, int first, int last);
390
INLINE_SIM_BITS(unsigned32) MSMASKED32 (unsigned32 word, int first, int last);
391
INLINE_SIM_BITS(unsigned64) MSMASKED64 (unsigned64 word, int first, int last);
392
 
393
INLINE_SIM_BITS(unsigned_word) MSMASKED (unsigned_word word, int first, int last);
394
 
395
#if (WITH_TARGET_WORD_MSB == 0)
396
#define MASKED8  MSMASKED8
397
#define MASKED16 MSMASKED16
398
#define MASKED32 MSMASKED32
399
#define MASKED64 MSMASKED64
400
#define MASKED   MSMASKED
401
#else
402
#define MASKED8  LSMASKED8
403
#define MASKED16 LSMASKED16
404
#define MASKED32 LSMASKED32
405
#define MASKED64 LSMASKED64
406
#define MASKED LSMASKED
407
#endif
408
 
409
 
410
 
411
/* extract the required bits aligning them with the lsb */
412
 
413
INLINE_SIM_BITS(unsigned8)  LSEXTRACTED8  (unsigned8  val, int start, int stop);
414
INLINE_SIM_BITS(unsigned16) LSEXTRACTED16 (unsigned16 val, int start, int stop);
415
INLINE_SIM_BITS(unsigned32) LSEXTRACTED32 (unsigned32 val, int start, int stop);
416
INLINE_SIM_BITS(unsigned64) LSEXTRACTED64 (unsigned64 val, int start, int stop);
417
 
418
INLINE_SIM_BITS(unsigned_word) LSEXTRACTED (unsigned_word val, int start, int stop);
419
 
420
INLINE_SIM_BITS(unsigned8)  MSEXTRACTED8  (unsigned8  val, int start, int stop);
421
INLINE_SIM_BITS(unsigned16) MSEXTRACTED16 (unsigned16 val, int start, int stop);
422
INLINE_SIM_BITS(unsigned32) MSEXTRACTED32 (unsigned32 val, int start, int stop);
423
INLINE_SIM_BITS(unsigned64) MSEXTRACTED64 (unsigned64 val, int start, int stop);
424
 
425
INLINE_SIM_BITS(unsigned_word) MSEXTRACTED (unsigned_word val, int start, int stop);
426
 
427
#if (WITH_TARGET_WORD_MSB == 0)
428
#define EXTRACTED8  MSEXTRACTED8
429
#define EXTRACTED16 MSEXTRACTED16
430
#define EXTRACTED32 MSEXTRACTED32
431
#define EXTRACTED64 MSEXTRACTED64
432
#define EXTRACTED   MSEXTRACTED
433
#else
434
#define EXTRACTED8  LSEXTRACTED8
435
#define EXTRACTED16 LSEXTRACTED16
436
#define EXTRACTED32 LSEXTRACTED32
437
#define EXTRACTED64 LSEXTRACTED64
438
#define EXTRACTED   LSEXTRACTED
439
#endif
440
 
441
 
442
 
443
/* move a single bit around */
444
/* NB: the wierdness (N>O?N-O:0) is to stop a warning from GCC */
445
#define _SHUFFLEDn(N, WORD, OLD, NEW) \
446
((OLD) < (NEW) \
447
 ? (((unsigned##N)(WORD) \
448
     >> (((NEW) > (OLD)) ? ((NEW) - (OLD)) : 0)) \
449
    & MASK32((NEW), (NEW))) \
450
 : (((unsigned##N)(WORD) \
451
     << (((OLD) > (NEW)) ? ((OLD) - (NEW)) : 0)) \
452
    & MASK32((NEW), (NEW))))
453
 
454
#define SHUFFLED32(WORD, OLD, NEW) _SHUFFLEDn (32, WORD, OLD, NEW)
455
#define SHUFFLED64(WORD, OLD, NEW) _SHUFFLEDn (64, WORD, OLD, NEW)
456
 
457
#define SHUFFLED(WORD, OLD, NEW) _SHUFFLEDn (_word, WORD, OLD, NEW)
458
 
459
 
460
/* Insert a group of bits into a bit position */
461
 
462
INLINE_SIM_BITS(unsigned8)  LSINSERTED8  (unsigned8  val, int start, int stop);
463
INLINE_SIM_BITS(unsigned16) LSINSERTED16 (unsigned16 val, int start, int stop);
464
INLINE_SIM_BITS(unsigned32) LSINSERTED32 (unsigned32 val, int start, int stop);
465
INLINE_SIM_BITS(unsigned64) LSINSERTED64 (unsigned64 val, int start, int stop);
466
INLINE_SIM_BITS(unsigned_word) LSINSERTED (unsigned_word val, int start, int stop);
467
 
468
INLINE_SIM_BITS(unsigned8)  MSINSERTED8  (unsigned8  val, int start, int stop);
469
INLINE_SIM_BITS(unsigned16) MSINSERTED16 (unsigned16 val, int start, int stop);
470
INLINE_SIM_BITS(unsigned32) MSINSERTED32 (unsigned32 val, int start, int stop);
471
INLINE_SIM_BITS(unsigned64) MSINSERTED64 (unsigned64 val, int start, int stop);
472
INLINE_SIM_BITS(unsigned_word) MSINSERTED (unsigned_word val, int start, int stop);
473
 
474
#if (WITH_TARGET_WORD_MSB == 0)
475
#define INSERTED8  MSINSERTED8
476
#define INSERTED16 MSINSERTED16
477
#define INSERTED32 MSINSERTED32
478
#define INSERTED64 MSINSERTED64
479
#define INSERTED   MSINSERTED
480
#else
481
#define INSERTED8  LSINSERTED8
482
#define INSERTED16 LSINSERTED16
483
#define INSERTED32 LSINSERTED32
484
#define INSERTED64 LSINSERTED64
485
#define INSERTED   LSINSERTED
486
#endif
487
 
488
 
489
 
490
/* MOVE bits from one loc to another (combination of extract/insert) */
491
 
492
#define MOVED8(VAL,OH,OL,NH,NL)  INSERTED8 (EXTRACTED8 ((VAL), OH, OL), NH, NL)
493
#define MOVED16(VAL,OH,OL,NH,NL) INSERTED16(EXTRACTED16((VAL), OH, OL), NH, NL)
494
#define MOVED32(VAL,OH,OL,NH,NL) INSERTED32(EXTRACTED32((VAL), OH, OL), NH, NL)
495
#define MOVED64(VAL,OH,OL,NH,NL) INSERTED64(EXTRACTED64((VAL), OH, OL), NH, NL)
496
#define MOVED(VAL,OH,OL,NH,NL)   INSERTED  (EXTRACTED  ((VAL), OH, OL), NH, NL)
497
 
498
 
499
 
500
/* Sign extend the quantity to the targets natural word size */
501
 
502
#define EXTEND4(X)  (LSSEXT ((X), 3))
503
#define EXTEND5(X)  (LSSEXT ((X), 4))
504
#define EXTEND8(X)  ((signed_word)(signed8)(X))
505
#define EXTEND11(X)  (LSSEXT ((X), 10))
506
#define EXTEND15(X)  (LSSEXT ((X), 14))
507
#define EXTEND16(X) ((signed_word)(signed16)(X))
508
#define EXTEND24(X)  (LSSEXT ((X), 23))
509
#define EXTEND32(X) ((signed_word)(signed32)(X))
510
#define EXTEND64(X) ((signed_word)(signed64)(X))
511
 
512
/* depending on MODE return a 64bit or 32bit (sign extended) value */
513
#if (WITH_TARGET_WORD_BITSIZE == 64)
514
#define EXTENDED(X)     ((signed64)(signed32)(X))
515
#endif
516
#if (WITH_TARGET_WORD_BITSIZE == 32)
517
#define EXTENDED(X)     (X)
518
#endif
519
#if (WITH_TARGET_WORD_BITSIZE == 16)
520
#define EXTENDED(X)     (X)
521
#endif
522
 
523
 
524
/* memory alignment macro's */
525
#define _ALIGNa(A,X)  (((X) + ((A) - 1)) & ~((A) - 1))
526
#define _FLOORa(A,X)  ((X) & ~((A) - 1))
527
 
528
#define ALIGN_8(X)      _ALIGNa (8, X)
529
#define ALIGN_16(X)     _ALIGNa (16, X)
530
 
531
#define ALIGN_PAGE(X)   _ALIGNa (0x1000, X)
532
#define FLOOR_PAGE(X)   ((X) & ~(0x1000 - 1))
533
 
534
 
535
/* bit bliting macro's */
536
#define BLIT32(V, POS, BIT) \
537
do { \
538
  if (BIT) \
539
    V |= BIT32 (POS); \
540
  else \
541
    V &= ~BIT32 (POS); \
542
} while (0)
543
#define MBLIT32(V, LO, HI, VAL) \
544
do { \
545
  (V) = (((V) & ~MASK32 ((LO), (HI))) \
546
         | INSERTED32 (VAL, LO, HI)); \
547
} while (0)
548
 
549
 
550
 
551
/* some rotate functions.  The generic macro's ROT, ROTL, ROTR are
552
   intentionally omited. */
553
 
554
 
555
INLINE_SIM_BITS(unsigned8)  ROT8  (unsigned8  val, int shift);
556
INLINE_SIM_BITS(unsigned16) ROT16 (unsigned16 val, int shift);
557
INLINE_SIM_BITS(unsigned32) ROT32 (unsigned32 val, int shift);
558
INLINE_SIM_BITS(unsigned64) ROT64 (unsigned64 val, int shift);
559
 
560
 
561
INLINE_SIM_BITS(unsigned8)  ROTL8  (unsigned8  val, int shift);
562
INLINE_SIM_BITS(unsigned16) ROTL16 (unsigned16 val, int shift);
563
INLINE_SIM_BITS(unsigned32) ROTL32 (unsigned32 val, int shift);
564
INLINE_SIM_BITS(unsigned64) ROTL64 (unsigned64 val, int shift);
565
 
566
 
567
INLINE_SIM_BITS(unsigned8)  ROTR8  (unsigned8  val, int shift);
568
INLINE_SIM_BITS(unsigned16) ROTR16 (unsigned16 val, int shift);
569
INLINE_SIM_BITS(unsigned32) ROTR32 (unsigned32 val, int shift);
570
INLINE_SIM_BITS(unsigned64) ROTR64 (unsigned64 val, int shift);
571
 
572
 
573
 
574
/* Sign extension operations */
575
 
576
INLINE_SIM_BITS(unsigned8)  LSSEXT8  (signed8  val, int sign_bit);
577
INLINE_SIM_BITS(unsigned16) LSSEXT16 (signed16 val, int sign_bit);
578
INLINE_SIM_BITS(unsigned32) LSSEXT32 (signed32 val, int sign_bit);
579
INLINE_SIM_BITS(unsigned64) LSSEXT64 (signed64 val, int sign_bit);
580
INLINE_SIM_BITS(unsigned_word) LSSEXT (signed_word val, int sign_bit);
581
 
582
INLINE_SIM_BITS(unsigned8)  MSSEXT8  (signed8  val, int sign_bit);
583
INLINE_SIM_BITS(unsigned16) MSSEXT16 (signed16 val, int sign_bit);
584
INLINE_SIM_BITS(unsigned32) MSSEXT32 (signed32 val, int sign_bit);
585
INLINE_SIM_BITS(unsigned64) MSSEXT64 (signed64 val, int sign_bit);
586
INLINE_SIM_BITS(unsigned_word) MSSEXT (signed_word val, int sign_bit);
587
 
588
#if (WITH_TARGET_WORD_MSB == 0)
589
#define SEXT8  MSSEXT8
590
#define SEXT16 MSSEXT16
591
#define SEXT32 MSSEXT32
592
#define SEXT64 MSSEXT64
593
#define SEXT   MSSEXT
594
#else
595
#define SEXT8  LSSEXT8
596
#define SEXT16 LSSEXT16
597
#define SEXT32 LSSEXT32
598
#define SEXT64 LSSEXT64
599
#define SEXT   LSSEXT
600
#endif
601
 
602
 
603
 
604
#if H_REVEALS_MODULE_P (SIM_BITS_INLINE)
605
#include "sim-bits.c"
606
#endif
607
 
608
#endif /* _SIM_BITS_H_ */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.