Define SIGNED64 and UNSIGNED64 macros - handle MSC/GCC LL issue.
[deliverable/binutils-gdb.git] / sim / common / sim-n-bits.h
1 /* This file is part of the program psim.
2
3 Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>
4 Copyright (C) 1997, Free Software Foundation, Inc.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 */
21
22
23 #ifndef N
24 #error "N must be #defined"
25 #endif
26
27 #include "sim-xcat.h"
28
29 #if defined(__STDC__) && defined(signed)
30 /* If signed were defined to be say __signed (ie, some versions of Linux),
31 then the signedN macro would not work correctly. If we have a standard
32 compiler, we have signed. */
33 #undef signed
34 #endif
35
36 /* NOTE: See end of file for #undef */
37 #define unsignedN XCONCAT2(unsigned,N)
38 #define signedN XCONCAT2(signed,N)
39 #define MASKEDn XCONCAT2(MASKED,N)
40 #define MASKn XCONCAT2(MASK,N)
41 #define LSMASKEDn XCONCAT2(LSMASKED,N)
42 #define LSMASKn XCONCAT2(LSMASK,N)
43 #define MSMASKEDn XCONCAT2(MSMASKED,N)
44 #define MSMASKn XCONCAT2(MSMASK,N)
45 #define LSEXTRACTEDn XCONCAT2(LSEXTRACTED,N)
46 #define MSEXTRACTEDn XCONCAT2(MSEXTRACTED,N)
47 #define INSERTEDn XCONCAT2(INSERTED,N)
48 #define ROTn XCONCAT2(ROT,N)
49 #define ROTLn XCONCAT2(ROTL,N)
50 #define ROTRn XCONCAT2(ROTR,N)
51 #define SEXTn XCONCAT2(SEXT,N)
52
53 /* TAGS: MASKED16 MASKED32 MASKED64 */
54
55 INLINE_SIM_BITS\
56 (unsignedN)
57 MASKEDn (unsignedN word,
58 unsigned start,
59 unsigned stop)
60 {
61 return (word & MASKn (start, stop));
62 }
63
64 /* TAGS: LSMASKED16 LSMASKED32 LSMASKED64 */
65
66 INLINE_SIM_BITS\
67 (unsignedN)
68 LSMASKEDn (unsignedN word,
69 unsigned nr_bits)
70 {
71 return (word & LSMASKn (nr_bits));
72 }
73
74 /* TAGS: MSMASKED16 MSMASKED32 MSMASKED64 */
75
76 INLINE_SIM_BITS\
77 (unsignedN)
78 MSMASKEDn (unsignedN word,
79 unsigned nr_bits)
80 {
81 return (word & MSMASKn (nr_bits));
82 }
83
84 /* TAGS: LSEXTRACTED16 LSEXTRACTED32 LSEXTRACTED64 */
85
86 INLINE_SIM_BITS\
87 (unsignedN)
88 LSEXTRACTEDn (unsignedN val,
89 unsigned start,
90 unsigned stop)
91 {
92 val <<= (N - 1 - start); /* drop high bits */
93 val >>= (N - 1 - start) + (stop); /* drop low bits */
94 return val;
95 }
96
97 /* TAGS: MSEXTRACTED16 MSEXTRACTED32 MSEXTRACTED64 */
98
99 INLINE_SIM_BITS\
100 (unsignedN)
101 MSEXTRACTEDn (unsignedN val,
102 unsigned start,
103 unsigned stop)
104 {
105 val <<= (start); /* drop high bits */
106 val >>= (start) + (N - 1 - stop); /* drop low bits */
107 return val;
108 }
109
110 /* TAGS: INSERTED16 INSERTED32 INSERTED64 */
111
112 INLINE_SIM_BITS\
113 (unsignedN)
114 INSERTEDn (unsignedN val,
115 unsigned start,
116 unsigned stop)
117 {
118 val &= LSMASKn (_MAKE_WIDTH (start, stop));
119 val <<= _LSB_SHIFT (N, stop);
120 return val;
121 }
122
123 /* TAGS: ROT16 ROT32 ROT64 */
124
125 INLINE_SIM_BITS\
126 (unsignedN)
127 ROTn (unsignedN val,
128 int shift)
129 {
130 if (shift > 0)
131 return ROTRn (val, shift);
132 else if (shift < 0)
133 return ROTLn (val, -shift);
134 else
135 return val;
136 }
137
138 /* TAGS: ROTL16 ROTL32 ROTL64 */
139
140 INLINE_SIM_BITS\
141 (unsignedN)
142 ROTLn (unsignedN val,
143 unsigned shift)
144 {
145 unsignedN result;
146 ASSERT (shift <= N);
147 result = (((val) << (shift)) | ((val) >> ((N)-(shift))));
148 return result;
149 }
150
151 /* TAGS: ROTR16 ROTR32 ROTR64 */
152
153 INLINE_SIM_BITS\
154 (unsignedN)
155 ROTRn (unsignedN val,
156 unsigned shift)
157 {
158 unsignedN result;
159 ASSERT (shift <= N);
160 result = (((val) >> (shift)) | ((val) << ((N)-(shift))));
161 return result;
162 }
163
164 /* TAGS: SEXT16 SEXT32 SEXT64 */
165
166 INLINE_SIM_BITS\
167 (unsignedN)
168 SEXTn (signedN val,
169 unsigned sign_bit)
170 {
171 /* make the sign-bit most significant and then smear it back into
172 position */
173 ASSERT (sign_bit < N);
174 val <<= _MSB_SHIFT (N, sign_bit);
175 val >>= _MSB_SHIFT (N, sign_bit);
176 return val;
177 }
178
179
180 /* NOTE: See start of file for #define */
181 #undef SEXTn
182 #undef ROTLn
183 #undef ROTRn
184 #undef ROTn
185 #undef INSERTEDn
186 #undef LSEXTRACTEDn
187 #undef MSEXTRACTEDn
188 #undef LSMASKEDn
189 #undef LSMASKn
190 #undef MSMASKEDn
191 #undef MSMASKn
192 #undef MASKn
193 #undef MASKEDn
194 #undef signedN
195 #undef unsignedN
This page took 0.0354 seconds and 4 git commands to generate.