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