1 /* This file is part of the program psim.
3 Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 /* bit manipulation routines:
27 Bit numbering: The bits are numbered according to the PowerPC
28 convention - the left most (or most significant) is bit 0 while the
29 right most (least significant) is bit 1.
31 Size convention: Each macro is in three forms - <MACRO>32 which
32 operates in 32bit quantity (bits are numbered 0..31); <MACRO>64
33 which operates using 64bit quantites (and bits are numbered 0..64);
34 and <MACRO> which operates using the bit size of the target
35 architecture (bits are still numbered 0..63), with 32bit
36 architectures ignoring the first 32bits having bit 32 as the most
39 BIT*(POS): Quantity with just 1 bit set.
41 MASK*(FIRST, LAST): Create a constant bit mask of the specified
42 size with bits [FIRST .. LAST] set.
44 MASKED*(VALUE, FIRST, LAST): Masks out all but bits [FIRST
47 EXTRACTED*(VALUE, FIRST, LAST): Masks out bits [FIRST .. LAST] but
48 also right shifts the masked value so that bit LAST becomes the
49 least significant (right most).
51 SHUFFLE*(VALUE, OLD, NEW): Moves things around so that bit pos OLD
52 is extracted and than moved to bit pos NEW.
56 IEA_MASKED(SHOULD_MASK, ADDR): Convert the address to the targets
57 natural size. If in 32bit mode, discard the high 32bits.
59 EXTENDED(VALUE): Convert VALUE (32bits of it) to the targets
60 natural size. If in 64bit mode, sign extend the value.
65 #define BIT4(POS) (1 << _MAKE_SHIFT(4, POS))
66 #define BIT5(POS) (1 << _MAKE_SHIFT(5, POS))
67 #define BIT10(POS) (1 << _MAKE_SHIFT(10, POS))
68 #define BIT32(POS) _BITn(32, POS)
69 #define BIT64(POS) _BITn(64, POS)
71 #if (WITH_64BIT_TARGET)
72 #define BIT(POS) BIT64(POS)
74 #define BIT(POS) (((POS) < 32) ? 0 : _BITn(32, (POS)-32))
80 #define MASK32(START, STOP) _MASKn(32, START, STOP)
81 #define MASK64(START, STOP) _MASKn(64, START, STOP)
83 #if (WITH_64BIT_TARGET)
84 #define MASK(START, STOP) (((START) <= (STOP)) \
85 ? _MASKn(64, START, STOP) \
86 : (_MASKn(64, 0, STOP) \
87 | _MASKn(64, START, 63)))
89 #define MASK(START, STOP) (((START) <= (STOP)) \
93 (START) < 32 ? 0 : (START) - 32, \
96 (START) < 32 ? 0 : (START) - 32, \
106 #define MASKED32(WORD, START, STOP) _MASKEDn(32, WORD, START, STOP)
107 #define MASKED64(WORD, START, STOP) _MASKEDn(64, WORD, START, STOP)
108 #define MASKED10(WORD, START, STOP) _MASKEDn(10, WORD, START, STOP)
109 #define EXTRACTED32(WORD, START, STOP) _EXTRACTEDn(32, WORD, START, STOP)
110 #define EXTRACTED64(WORD, START, STOP) _EXTRACTEDn(64, WORD, START, STOP)
111 #define EXTRACTED10(WORD, START, STOP) _EXTRACTEDn(10, WORD, START, STOP)
113 #define MASKED(WORD, START, STOP) ((natural_word)(WORD) & MASK(START, STOP))
114 #if (WITH_64BITS_TARGET)
115 #define EXTRACTED(WORD, START, STOP) _EXTRACTEDn(64, WORD, START, STOP)
117 #define EXTRACTED(WORD, START, STOP) (STOP < 32 \
119 : (((natural_word)WORD \
121 && MASK(START+(63-STOP), 63)))
125 #define SHUFFLE32(WORD, OLD, NEW) _SHUFFLEn(32, WORD, OLD, NEW)
126 #define SHUFFLE64(WORD, OLD, NEW) _SHUFFLEn(64, WORD, OLD, NEW)
127 #define SHUFFLE(WORD, OLD, NEW) _SHUFFLEn(_word, WORD, OLD, NEW)
128 /* NB: the wierdness (N>O?N-O:0) is to stop a warning from GCC */
129 #define _SHUFFLEn(N, WORD, OLD, NEW) \
131 ? (((unsigned##N)(WORD) \
132 >> (((NEW) > (OLD)) ? ((NEW) - (OLD)) : 0)) \
133 & MASK32((NEW), (NEW))) \
134 : (((unsigned##N)(WORD) \
135 << (((OLD) > (NEW)) ? ((OLD) - (NEW)) : 0)) \
136 & MASK32((NEW), (NEW))))
140 /* depending on MODE return a 64bit or 32bit (sign extended) value */
141 #if (WITH_64BIT_TARGET)
142 #define EXTENDED(X) ((signed64)(signed32)(X))
144 #define EXTENDED(X) (X)
150 /* memory alignment macro's */
151 #define _ALIGNa(A,X) (((X) + ((A)-1)) & ~((A)-1))
152 #define ALIGN_8(X) _ALIGNa(8, X)
153 #define ALIGN_16(X) _ALIGNa(16, X)
154 #define ALIGN_PAGE(X) _ALIGNa(0x1000, X)
155 #define FLOOR_PAGE(X) ((X) & ~(0x1000 - 1))
157 /* bit bliting macro's */
158 #define BLIT32(V, POS, BIT) \
165 #define MLIT32(V, LO, HI, VAL) \
167 (V) = (((V) & ~MASK32((LO), (HI))) \
168 | ((VAL) << _MAKE_SHIFT(32,HI))); \
173 /* Things for creating single bit set values */
175 #define _MAKE_SHIFT(WIDTH, pos) (WIDTH - 1 - (pos))
176 #define _BITn(WIDTH, pos) (((natural##WIDTH)(1)) \
177 << _MAKE_SHIFT(WIDTH, pos))
179 #define _MASKn(WIDTH, START, STOP) (((((unsigned##WIDTH)0) - 1) \
180 >> (WIDTH - ((STOP) - (START) + 1))) \
181 << (WIDTH - 1 - (STOP)))
185 /* mask the required bits, leaving them in place */
186 #define _MASKEDn(WIDTH, WORD, START, STOP) \
187 (((natural##WIDTH)(WORD)) & MASK##WIDTH(START, STOP))
189 /* extract the required bits aligning them with the lsb */
190 #define _EXTRACTEDn(WIDTH, WORD, START, STOP) \
191 ((((natural##WIDTH)(WORD)) >> (WIDTH - (STOP) - 1)) \
192 & _MASKn(WIDTH, WIDTH-1+(START)-(STOP), WIDTH-1))
194 #endif /* _BITS_H_ */
This page took 0.045692 seconds and 4 git commands to generate.