Add/use LSEXTRACTED, MSEXTRACTED macros.
[deliverable/binutils-gdb.git] / sim / common / sim-bits.c
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
30 INLINE_SIM_BITS\
31 (unsigned_word)
32 LSMASKED (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
42 INLINE_SIM_BITS\
43 (unsigned_word)
44 MSMASKED (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
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
77
78 INLINE_SIM_BITS\
79 (unsigned_word)
80 MSEXTRACTED (unsigned_word val,
81 int start,
82 int stop)
83 {
84 ASSERT (start <= stop);
85 #if (WITH_TARGET_WORD_BITSIZE == 64)
86 return MSEXTRACTED64 (val, start, stop);
87 #endif
88 #if (WITH_TARGET_WORD_BITSIZE == 32)
89 if (stop < 32)
90 return 0;
91 else
92 {
93 if (start >= 32)
94 val &= MSMASK (start, 64 - 1);
95 val >>= (64 - stop - 1);
96 return val;
97 }
98 #endif
99 }
100
101
102 INLINE_SIM_BITS\
103 (unsigned_word)
104 INSERTED (unsigned_word val,
105 int start,
106 int stop)
107 {
108 ASSERT ((WITH_TARGET_WORD_MSB == 0 && start <= stop)
109 || (WITH_TARGET_WORD_MSB != 0 && start >= stop));
110 #if (WITH_TARGET_WORD_BITSIZE == 64)
111 return INSERTED64 (val, start, stop);
112 #endif
113 #if (WITH_TARGET_WORD_BITSIZE == 32)
114 /* Bit numbers are 0..63, even for 32 bit targets.
115 On 32 bit targets we ignore 0..31. */
116 if (_LSB_SHIFT (64, stop) >= 32)
117 return 0;
118 else
119 {
120 val &= LSMASK (_MAKE_WIDTH (start, stop), 0);
121 val <<= _LSB_SHIFT (64, stop);
122 return val;
123 }
124 #endif
125 }
126
127
128
129 INLINE_SIM_BITS\
130 (unsigned_word)
131 SEXT (signed_word val,
132 int sign_bit)
133 {
134 /* make the sign-bit most significant and then smear it back into
135 position */
136 ASSERT (sign_bit < 64);
137 #if (WITH_TARGET_WORD_BITSIZE == 64)
138 return SEXT64 (val, sign_bit);
139 #endif
140 #if (WITH_TARGET_WORD_BITSIZE == 32)
141 if (_MSB_SHIFT (64, sign_bit) < 32)
142 return val;
143 else {
144 val <<= (_MSB_SHIFT (64, sign_bit) - 32);
145 val >>= (_MSB_SHIFT (64, sign_bit) - 32);
146 return val;
147 }
148 #endif
149 }
150
151
152
153 #define N 16
154 #include "sim-n-bits.h"
155 #undef N
156
157 #define N 32
158 #include "sim-n-bits.h"
159 #undef N
160
161 #define N 64
162 #include "sim-n-bits.h"
163 #undef N
164
165 #endif /* _SIM_BITS_C_ */
This page took 0.032108 seconds and 4 git commands to generate.