Commit | Line | Data |
---|---|---|
f2de7dfd AC |
1 | /* This file is part of the program psim. |
2 | ||
3 | Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au> | |
4 | ||
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. | |
9 | ||
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. | |
14 | ||
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. | |
18 | ||
19 | */ | |
20 | ||
21 | ||
22 | #ifndef _SIM_BITS_C_ | |
23 | #define _SIM_BITS_C_ | |
24 | ||
25 | #include "sim-basics.h" | |
d11d59ac | 26 | #include "sim-assert.h" |
75b3697d AC |
27 | #include "sim-io.h" |
28 | ||
f2de7dfd AC |
29 | |
30 | INLINE_SIM_BITS\ | |
31 | (unsigned_word) | |
75b3697d AC |
32 | LSMASKED (unsigned_word val, |
33 | int start, | |
34 | int stop) | |
f2de7dfd | 35 | { |
75b3697d AC |
36 | /* NOTE - start, stop can wrap */ |
37 | val &= LSMASK (start, stop); | |
38 | return val; | |
f2de7dfd AC |
39 | } |
40 | ||
41 | ||
f2de7dfd AC |
42 | INLINE_SIM_BITS\ |
43 | (unsigned_word) | |
75b3697d AC |
44 | MSMASKED (unsigned_word val, |
45 | int start, | |
46 | int stop) | |
f2de7dfd | 47 | { |
75b3697d AC |
48 | /* NOTE - start, stop can wrap */ |
49 | val &= MSMASK (start, stop); | |
50 | return val; | |
f2de7dfd AC |
51 | } |
52 | ||
53 | ||
75b3697d AC |
54 | INLINE_SIM_BITS\ |
55 | (unsigned_word) | |
56 | LSEXTRACTED (unsigned_word val, | |
57 | int start, | |
58 | int stop) | |
59 | { | |
60 | ASSERT (start >= stop); | |
61 | #if (WITH_TARGET_WORD_BITSIZE == 64) | |
62 | return LSEXTRACTED64 (val, start, stop); | |
63 | #endif | |
64 | #if (WITH_TARGET_WORD_BITSIZE == 32) | |
65 | if (stop >= 32) | |
66 | return 0; | |
67 | else | |
68 | { | |
69 | if (start < 32) | |
70 | val &= LSMASK (start, 0); | |
71 | val >>= stop; | |
72 | return val; | |
73 | } | |
74 | #endif | |
75 | } | |
76 | ||
f2de7dfd AC |
77 | |
78 | INLINE_SIM_BITS\ | |
79 | (unsigned_word) | |
75b3697d AC |
80 | MSEXTRACTED (unsigned_word val, |
81 | int start, | |
82 | int stop) | |
f2de7dfd | 83 | { |
75b3697d | 84 | ASSERT (start <= stop); |
f2de7dfd | 85 | #if (WITH_TARGET_WORD_BITSIZE == 64) |
75b3697d | 86 | return MSEXTRACTED64 (val, start, stop); |
f2de7dfd AC |
87 | #endif |
88 | #if (WITH_TARGET_WORD_BITSIZE == 32) | |
89 | if (stop < 32) | |
90 | return 0; | |
91 | else | |
75b3697d AC |
92 | { |
93 | if (start >= 32) | |
94 | val &= MSMASK (start, 64 - 1); | |
95 | val >>= (64 - stop - 1); | |
96 | return val; | |
97 | } | |
f2de7dfd AC |
98 | #endif |
99 | } | |
100 | ||
101 | ||
102 | INLINE_SIM_BITS\ | |
103 | (unsigned_word) | |
aa5e6a5a AC |
104 | LSINSERTED (unsigned_word val, |
105 | int start, | |
106 | int stop) | |
107 | { | |
108 | ASSERT (start >= stop); | |
109 | #if (WITH_TARGET_WORD_BITSIZE == 64) | |
110 | return LSINSERTED64 (val, start, stop); | |
111 | #endif | |
112 | #if (WITH_TARGET_WORD_BITSIZE == 32) | |
113 | /* Bit numbers are 63..0, even for 32 bit targets. | |
114 | On 32 bit targets we ignore 63..32 */ | |
115 | if (stop >= 32) | |
116 | return 0; | |
117 | else | |
118 | { | |
119 | val <<= stop; | |
120 | val &= LSMASK (start, stop); | |
121 | return val; | |
122 | } | |
123 | #endif | |
124 | } | |
125 | ||
126 | INLINE_SIM_BITS\ | |
127 | (unsigned_word) | |
128 | MSINSERTED (unsigned_word val, | |
129 | int start, | |
130 | int stop) | |
f2de7dfd | 131 | { |
aa5e6a5a | 132 | ASSERT (start <= stop); |
f2de7dfd | 133 | #if (WITH_TARGET_WORD_BITSIZE == 64) |
aa5e6a5a | 134 | return MSINSERTED64 (val, start, stop); |
f2de7dfd AC |
135 | #endif |
136 | #if (WITH_TARGET_WORD_BITSIZE == 32) | |
75b3697d AC |
137 | /* Bit numbers are 0..63, even for 32 bit targets. |
138 | On 32 bit targets we ignore 0..31. */ | |
aa5e6a5a | 139 | if (stop < 32) |
f2de7dfd AC |
140 | return 0; |
141 | else | |
75b3697d | 142 | { |
aa5e6a5a AC |
143 | val <<= ((64 - 1) - stop); |
144 | val &= MSMASK (start, stop); | |
75b3697d AC |
145 | return val; |
146 | } | |
f2de7dfd AC |
147 | #endif |
148 | } | |
149 | ||
150 | ||
151 | ||
75b3697d AC |
152 | INLINE_SIM_BITS\ |
153 | (unsigned_word) | |
aa5e6a5a AC |
154 | LSSEXT (signed_word val, |
155 | int sign_bit) | |
156 | { | |
157 | ASSERT (sign_bit < 64); | |
158 | #if (WITH_TARGET_WORD_BITSIZE == 64) | |
159 | return LSSEXT64 (val, sign_bit); | |
160 | #endif | |
161 | #if (WITH_TARGET_WORD_BITSIZE == 32) | |
162 | if (sign_bit >= 32) | |
163 | return val; | |
164 | else { | |
165 | val = LSSEXT32 (val, sign_bit); | |
166 | return val; | |
167 | } | |
168 | #endif | |
169 | } | |
170 | ||
171 | INLINE_SIM_BITS\ | |
172 | (unsigned_word) | |
173 | MSSEXT (signed_word val, | |
174 | int sign_bit) | |
75b3697d | 175 | { |
75b3697d AC |
176 | ASSERT (sign_bit < 64); |
177 | #if (WITH_TARGET_WORD_BITSIZE == 64) | |
aa5e6a5a | 178 | return MSSEXT64 (val, sign_bit); |
75b3697d AC |
179 | #endif |
180 | #if (WITH_TARGET_WORD_BITSIZE == 32) | |
aa5e6a5a | 181 | if (sign_bit < 32) |
75b3697d AC |
182 | return val; |
183 | else { | |
aa5e6a5a | 184 | val = MSSEXT32 (val, sign_bit - 32); |
75b3697d AC |
185 | return val; |
186 | } | |
187 | #endif | |
188 | } | |
189 | ||
190 | ||
f2de7dfd AC |
191 | |
192 | #define N 16 | |
193 | #include "sim-n-bits.h" | |
194 | #undef N | |
195 | ||
196 | #define N 32 | |
197 | #include "sim-n-bits.h" | |
198 | #undef N | |
199 | ||
200 | #define N 64 | |
201 | #include "sim-n-bits.h" | |
202 | #undef N | |
203 | ||
204 | #endif /* _SIM_BITS_C_ */ |