bb787794b036fb4da85d5164dd6930cb68b512fa
[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 /* NOTE: See end of file for #undef */
30 #define unsignedN XCONCAT2(unsigned,N)
31 #define signedN XCONCAT2(signed,N)
32 #define MASKEDn XCONCAT2(MASKED,N)
33 #define MASKn XCONCAT2(MASK,N)
34 #define LSMASKEDn XCONCAT2(LSMASKED,N)
35 #define LSMASKn XCONCAT2(LSMASK,N)
36 #define MSMASKEDn XCONCAT2(MSMASKED,N)
37 #define MSMASKn XCONCAT2(MSMASK,N)
38 #define EXTRACTEDn XCONCAT2(EXTRACTED,N)
39 #define INSERTEDn XCONCAT2(INSERTED,N)
40 #define ROTn XCONCAT2(ROT,N)
41 #define ROTLn XCONCAT2(ROTL,N)
42 #define ROTRn XCONCAT2(ROTR,N)
43 #define SEXTn XCONCAT2(SEXT,N)
44
45
46 INLINE_SIM_BITS\
47 (unsignedN)
48 MASKEDn (unsignedN word,
49 unsigned start,
50 unsigned stop)
51 {
52 return (word & MASKn (start, stop));
53 }
54
55
56 INLINE_SIM_BITS\
57 (unsignedN)
58 LSMASKEDn (unsignedN word,
59 unsigned nr_bits)
60 {
61 return (word & LSMASKn (nr_bits));
62 }
63
64
65 INLINE_SIM_BITS\
66 (unsignedN)
67 MSMASKEDn (unsignedN word,
68 unsigned nr_bits)
69 {
70 return (word & MSMASKn (nr_bits));
71 }
72
73
74 INLINE_SIM_BITS\
75 (unsignedN)
76 EXTRACTEDn (unsignedN val,
77 unsigned start,
78 unsigned stop)
79 {
80 val <<= _MSB_SHIFT (N, start);
81 val >>= (_MSB_SHIFT (N, start) + _LSB_SHIFT (N, stop));
82 return val;
83 }
84
85
86 INLINE_SIM_BITS\
87 (unsignedN)
88 INSERTEDn (unsignedN val,
89 unsigned start,
90 unsigned stop)
91 {
92 val &= LSMASKn (_MAKE_WIDTH (start, stop));
93 val <<= _LSB_SHIFT (N, stop);
94 return val;
95 }
96
97
98 INLINE_SIM_BITS\
99 (unsignedN)
100 ROTn (unsignedN val,
101 int shift)
102 {
103 if (shift > 0)
104 return ROTRn (val, shift);
105 else if (shift < 0)
106 return ROTLn (val, -shift);
107 else
108 return val;
109 }
110
111
112 INLINE_SIM_BITS\
113 (unsignedN)
114 ROTLn (unsignedN val,
115 unsigned shift)
116 {
117 unsignedN result;
118 ASSERT (shift <= N);
119 result = (((val) << (shift)) | ((val) >> ((N)-(shift))));
120 return result;
121 }
122
123
124 INLINE_SIM_BITS\
125 (unsignedN)
126 ROTRn (unsignedN val,
127 unsigned shift)
128 {
129 unsignedN result;
130 ASSERT (shift <= N);
131 result = (((val) >> (shift)) | ((val) << ((N)-(shift))));
132 return result;
133 }
134
135
136 INLINE_SIM_BITS\
137 (unsignedN)
138 SEXTn (signedN val,
139 unsigned sign_bit)
140 {
141 /* make the sign-bit most significant and then smear it back into
142 position */
143 ASSERT (sign_bit < N);
144 val <<= _MSB_SHIFT (N, sign_bit);
145 val >>= _MSB_SHIFT (N, sign_bit);
146 return val;
147 }
148
149
150 /* NOTE: See start of file for #define */
151 #undef SEXTn
152 #undef ROTLn
153 #undef ROTRn
154 #undef ROTn
155 #undef INSERTEDn
156 #undef EXTRACTEDn
157 #undef LSMASKEDn
158 #undef LSMASKn
159 #undef MSMASKEDn
160 #undef MSMASKn
161 #undef MASKn
162 #undef MASKEDn
163 #undef signedN
164 #undef unsignedN
This page took 0.032007 seconds and 4 git commands to generate.