Copyright updates for 2007.
[deliverable/binutils-gdb.git] / sim / common / sim-n-bits.h
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 N
26#error "N must be #defined"
27#endif
28
29#include "symcat.h"
30
31#if defined(__STDC__) && defined(signed)
32/* If signed were defined to be say __signed (ie, some versions of Linux),
33 then the signedN macro would not work correctly. If we have a standard
34 compiler, we have signed. */
35#undef signed
36#endif
37
38/* NOTE: See end of file for #undef */
39#define unsignedN XCONCAT2(unsigned,N)
40#define signedN XCONCAT2(signed,N)
41#define LSMASKn XCONCAT2(LSMASK,N)
42#define MSMASKn XCONCAT2(MSMASK,N)
43#define LSMASKEDn XCONCAT2(LSMASKED,N)
44#define MSMASKEDn XCONCAT2(MSMASKED,N)
45#define LSEXTRACTEDn XCONCAT2(LSEXTRACTED,N)
46#define MSEXTRACTEDn XCONCAT2(MSEXTRACTED,N)
47#define LSINSERTEDn XCONCAT2(LSINSERTED,N)
48#define MSINSERTEDn XCONCAT2(MSINSERTED,N)
49#define ROTn XCONCAT2(ROT,N)
50#define ROTLn XCONCAT2(ROTL,N)
51#define ROTRn XCONCAT2(ROTR,N)
52#define MSSEXTn XCONCAT2(MSSEXT,N)
53#define LSSEXTn XCONCAT2(LSSEXT,N)
54
55/* TAGS: LSMASKED16 LSMASKED32 LSMASKED64 */
56
57INLINE_SIM_BITS\
58(unsignedN)
59LSMASKEDn (unsignedN word,
60 int start,
61 int stop)
62{
63 word &= LSMASKn (start, stop);
64 return word;
65}
66
67/* TAGS: MSMASKED16 MSMASKED32 MSMASKED64 */
68
69INLINE_SIM_BITS\
70(unsignedN)
71MSMASKEDn (unsignedN word,
72 int start,
73 int stop)
74{
75 word &= MSMASKn (start, stop);
76 return word;
77}
78
79/* TAGS: LSEXTRACTED16 LSEXTRACTED32 LSEXTRACTED64 */
80
81INLINE_SIM_BITS\
82(unsignedN)
83LSEXTRACTEDn (unsignedN val,
84 int start,
85 int stop)
86{
87 val <<= (N - 1 - start); /* drop high bits */
88 val >>= (N - 1 - start) + (stop); /* drop low bits */
89 return val;
90}
91
92/* TAGS: MSEXTRACTED16 MSEXTRACTED32 MSEXTRACTED64 */
93
94INLINE_SIM_BITS\
95(unsignedN)
96MSEXTRACTEDn (unsignedN val,
97 int start,
98 int stop)
99{
100 val <<= (start); /* drop high bits */
101 val >>= (start) + (N - 1 - stop); /* drop low bits */
102 return val;
103}
104
105/* TAGS: LSINSERTED16 LSINSERTED32 LSINSERTED64 */
106
107INLINE_SIM_BITS\
108(unsignedN)
109LSINSERTEDn (unsignedN val,
110 int start,
111 int stop)
112{
113 val <<= stop;
114 val &= LSMASKn (start, stop);
115 return val;
116}
117
118/* TAGS: MSINSERTED16 MSINSERTED32 MSINSERTED64 */
119
120INLINE_SIM_BITS\
121(unsignedN)
122MSINSERTEDn (unsignedN val,
123 int start,
124 int stop)
125{
126 val <<= ((N - 1) - stop);
127 val &= MSMASKn (start, stop);
128 return val;
129}
130
131/* TAGS: ROT16 ROT32 ROT64 */
132
133INLINE_SIM_BITS\
134(unsignedN)
135ROTn (unsignedN val,
136 int shift)
137{
138 if (shift > 0)
139 return ROTRn (val, shift);
140 else if (shift < 0)
141 return ROTLn (val, -shift);
142 else
143 return val;
144}
145
146/* TAGS: ROTL16 ROTL32 ROTL64 */
147
148INLINE_SIM_BITS\
149(unsignedN)
150ROTLn (unsignedN val,
151 int shift)
152{
153 unsignedN result;
154 ASSERT (shift <= N);
155 result = (((val) << (shift)) | ((val) >> ((N)-(shift))));
156 return result;
157}
158
159/* TAGS: ROTR16 ROTR32 ROTR64 */
160
161INLINE_SIM_BITS\
162(unsignedN)
163ROTRn (unsignedN val,
164 int shift)
165{
166 unsignedN result;
167 ASSERT (shift <= N);
168 result = (((val) >> (shift)) | ((val) << ((N)-(shift))));
169 return result;
170}
171
172/* TAGS: LSSEXT16 LSSEXT32 LSSEXT64 */
173
174INLINE_SIM_BITS\
175(unsignedN)
176LSSEXTn (signedN val,
177 int sign_bit)
178{
179 int shift;
180 /* make the sign-bit most significant and then smear it back into
181 position */
182 ASSERT (sign_bit < N);
183 shift = ((N - 1) - sign_bit);
184 val <<= shift;
185 val >>= shift;
186 return val;
187}
188
189/* TAGS: MSSEXT16 MSSEXT32 MSSEXT64 */
190
191INLINE_SIM_BITS\
192(unsignedN)
193MSSEXTn (signedN val,
194 int sign_bit)
195{
196 /* make the sign-bit most significant and then smear it back into
197 position */
198 ASSERT (sign_bit < N);
199 val <<= sign_bit;
200 val >>= sign_bit;
201 return val;
202}
203
204
205/* NOTE: See start of file for #define */
206#undef LSSEXTn
207#undef MSSEXTn
208#undef ROTLn
209#undef ROTRn
210#undef ROTn
211#undef LSINSERTEDn
212#undef MSINSERTEDn
213#undef LSEXTRACTEDn
214#undef MSEXTRACTEDn
215#undef LSMASKEDn
216#undef LSMASKn
217#undef MSMASKEDn
218#undef MSMASKn
219#undef signedN
220#undef unsignedN
This page took 0.310378 seconds and 4 git commands to generate.