]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/common/sim-bits.c
Translation updates.
[thirdparty/binutils-gdb.git] / sim / common / sim-bits.c
CommitLineData
b85e4829
AC
1/* The common simulator framework for GDB, the GNU Debugger.
2
6aba47ca 3 Copyright 2002, 2007 Free Software Foundation, Inc.
b85e4829
AC
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_C_
26#define _SIM_BITS_C_
27
28#include "sim-basics.h"
29#include "sim-assert.h"
30#include "sim-io.h"
31
32
33INLINE_SIM_BITS\
34(unsigned_word)
35LSMASKED (unsigned_word val,
36 int start,
37 int stop)
38{
39 /* NOTE - start, stop can wrap */
40 val &= LSMASK (start, stop);
41 return val;
42}
43
44
45INLINE_SIM_BITS\
46(unsigned_word)
47MSMASKED (unsigned_word val,
48 int start,
49 int stop)
50{
51 /* NOTE - start, stop can wrap */
52 val &= MSMASK (start, stop);
53 return val;
54}
55
56
57INLINE_SIM_BITS\
58(unsigned_word)
59LSEXTRACTED (unsigned_word val,
60 int start,
61 int stop)
62{
63 ASSERT (start >= stop);
64#if (WITH_TARGET_WORD_BITSIZE == 64)
65 return LSEXTRACTED64 (val, start, stop);
66#endif
67#if (WITH_TARGET_WORD_BITSIZE == 32)
68 if (stop >= 32)
69 return 0;
70 else
71 {
72 if (start < 32)
73 val &= LSMASK (start, 0);
74 val >>= stop;
75 return val;
76 }
77#endif
3c765a54
AC
78#if (WITH_TARGET_WORD_BITSIZE == 16)
79 if (stop >= 16)
80 return 0;
81 else
82 {
83 if (start < 16)
84 val &= LSMASK (start, 0);
85 val >>= stop;
86 return val;
87 }
88#endif
c906108c
SS
89}
90
91
92INLINE_SIM_BITS\
93(unsigned_word)
94MSEXTRACTED (unsigned_word val,
95 int start,
96 int stop)
97{
98 ASSERT (start <= stop);
99#if (WITH_TARGET_WORD_BITSIZE == 64)
100 return MSEXTRACTED64 (val, start, stop);
101#endif
102#if (WITH_TARGET_WORD_BITSIZE == 32)
103 if (stop < 32)
104 return 0;
105 else
106 {
107 if (start >= 32)
108 val &= MSMASK (start, 64 - 1);
109 val >>= (64 - stop - 1);
110 return val;
111 }
112#endif
3c765a54
AC
113#if (WITH_TARGET_WORD_BITSIZE == 16)
114 if (stop < 16)
115 return 0;
116 else
117 {
118 if (start >= 16)
119 val &= MSMASK (start, 64 - 1);
120 val >>= (64 - stop - 1);
121 return val;
122 }
123#endif
c906108c
SS
124}
125
126
127INLINE_SIM_BITS\
128(unsigned_word)
129LSINSERTED (unsigned_word val,
130 int start,
131 int stop)
132{
133 ASSERT (start >= stop);
134#if (WITH_TARGET_WORD_BITSIZE == 64)
135 return LSINSERTED64 (val, start, stop);
136#endif
137#if (WITH_TARGET_WORD_BITSIZE == 32)
138 /* Bit numbers are 63..0, even for 32 bit targets.
139 On 32 bit targets we ignore 63..32 */
140 if (stop >= 32)
141 return 0;
142 else
143 {
144 val <<= stop;
145 val &= LSMASK (start, stop);
146 return val;
147 }
148#endif
3c765a54
AC
149#if (WITH_TARGET_WORD_BITSIZE == 16)
150 /* Bit numbers are 63..0, even for 16 bit targets.
151 On 16 bit targets we ignore 63..16 */
152 if (stop >= 16)
153 return 0;
154 else
155 {
156 val <<= stop;
157 val &= LSMASK (start, stop);
158 return val;
159 }
160#endif
c906108c
SS
161}
162
163INLINE_SIM_BITS\
164(unsigned_word)
165MSINSERTED (unsigned_word val,
166 int start,
167 int stop)
168{
169 ASSERT (start <= stop);
170#if (WITH_TARGET_WORD_BITSIZE == 64)
171 return MSINSERTED64 (val, start, stop);
172#endif
173#if (WITH_TARGET_WORD_BITSIZE == 32)
174 /* Bit numbers are 0..63, even for 32 bit targets.
175 On 32 bit targets we ignore 0..31. */
176 if (stop < 32)
177 return 0;
178 else
179 {
180 val <<= ((64 - 1) - stop);
181 val &= MSMASK (start, stop);
182 return val;
183 }
184#endif
3c765a54
AC
185#if (WITH_TARGET_WORD_BITSIZE == 16)
186 /* Bit numbers are 0..63, even for 16 bit targets.
187 On 16 bit targets we ignore 0..47. */
188 if (stop < 32 + 16)
189 return 0;
190 else
191 {
192 val <<= ((64 - 1) - stop);
193 val &= MSMASK (start, stop);
194 return val;
195 }
196#endif
c906108c
SS
197}
198
199
200
201INLINE_SIM_BITS\
202(unsigned_word)
203LSSEXT (signed_word val,
204 int sign_bit)
205{
206 ASSERT (sign_bit < 64);
207#if (WITH_TARGET_WORD_BITSIZE == 64)
208 return LSSEXT64 (val, sign_bit);
209#endif
210#if (WITH_TARGET_WORD_BITSIZE == 32)
211 if (sign_bit >= 32)
212 return val;
213 else {
214 val = LSSEXT32 (val, sign_bit);
215 return val;
216 }
217#endif
3c765a54
AC
218#if (WITH_TARGET_WORD_BITSIZE == 16)
219 if (sign_bit >= 16)
220 return val;
221 else {
222 val = LSSEXT16 (val, sign_bit);
223 return val;
224 }
225#endif
c906108c
SS
226}
227
228INLINE_SIM_BITS\
229(unsigned_word)
230MSSEXT (signed_word val,
231 int sign_bit)
232{
233 ASSERT (sign_bit < 64);
234#if (WITH_TARGET_WORD_BITSIZE == 64)
235 return MSSEXT64 (val, sign_bit);
236#endif
237#if (WITH_TARGET_WORD_BITSIZE == 32)
238 if (sign_bit < 32)
239 return val;
240 else {
241 val = MSSEXT32 (val, sign_bit - 32);
242 return val;
243 }
244#endif
3c765a54
AC
245#if (WITH_TARGET_WORD_BITSIZE == 16)
246 if (sign_bit < 32 + 16)
247 return val;
248 else {
249 val = MSSEXT16 (val, sign_bit - 32 - 16);
250 return val;
251 }
252#endif
c906108c
SS
253}
254
255
256
257#define N 8
258#include "sim-n-bits.h"
259#undef N
260
261#define N 16
262#include "sim-n-bits.h"
263#undef N
264
265#define N 32
266#include "sim-n-bits.h"
267#undef N
268
269#define N 64
270#include "sim-n-bits.h"
271#undef N
272
273#endif /* _SIM_BITS_C_ */