* Makefile.in (TAGS): Add support for "/* TAGS: foo */" marker.
[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 EXTRACTEDn XCONCAT2(EXTRACTED,N)
46 #define INSERTEDn XCONCAT2(INSERTED,N)
47 #define ROTn XCONCAT2(ROT,N)
48 #define ROTLn XCONCAT2(ROTL,N)
49 #define ROTRn XCONCAT2(ROTR,N)
50 #define SEXTn XCONCAT2(SEXT,N)
51
52 /* TAGS: MASKED16 MASKED32 MASKED64 */
53
54 INLINE_SIM_BITS\
55 (unsignedN)
56 MASKEDn (unsignedN word,
57 unsigned start,
58 unsigned stop)
59 {
60 return (word & MASKn (start, stop));
61 }
62
63 /* TAGS: LSMASKED16 LSMASKED32 LSMASKED64 */
64
65 INLINE_SIM_BITS\
66 (unsignedN)
67 LSMASKEDn (unsignedN word,
68 unsigned nr_bits)
69 {
70 return (word & LSMASKn (nr_bits));
71 }
72
73 /* TAGS: MSMASKED16 MSMASKED32 MSMASKED64 */
74
75 INLINE_SIM_BITS\
76 (unsignedN)
77 MSMASKEDn (unsignedN word,
78 unsigned nr_bits)
79 {
80 return (word & MSMASKn (nr_bits));
81 }
82
83 /* TAGS: EXTRACTED16 EXTRACTED32 EXTRACTED64 */
84
85 INLINE_SIM_BITS\
86 (unsignedN)
87 EXTRACTEDn (unsignedN val,
88 unsigned start,
89 unsigned stop)
90 {
91 val <<= _MSB_SHIFT (N, start);
92 val >>= (_MSB_SHIFT (N, start) + _LSB_SHIFT (N, stop));
93 return val;
94 }
95
96 /* TAGS: INSERTED16 INSERTED32 INSERTED64 */
97
98 INLINE_SIM_BITS\
99 (unsignedN)
100 INSERTEDn (unsignedN val,
101 unsigned start,
102 unsigned stop)
103 {
104 val &= LSMASKn (_MAKE_WIDTH (start, stop));
105 val <<= _LSB_SHIFT (N, stop);
106 return val;
107 }
108
109 /* TAGS: ROT16 ROT32 ROT64 */
110
111 INLINE_SIM_BITS\
112 (unsignedN)
113 ROTn (unsignedN val,
114 int shift)
115 {
116 if (shift > 0)
117 return ROTRn (val, shift);
118 else if (shift < 0)
119 return ROTLn (val, -shift);
120 else
121 return val;
122 }
123
124 /* TAGS: ROTL16 ROTL32 ROTL64 */
125
126 INLINE_SIM_BITS\
127 (unsignedN)
128 ROTLn (unsignedN val,
129 unsigned shift)
130 {
131 unsignedN result;
132 ASSERT (shift <= N);
133 result = (((val) << (shift)) | ((val) >> ((N)-(shift))));
134 return result;
135 }
136
137 /* TAGS: ROTR16 ROTR32 ROTR64 */
138
139 INLINE_SIM_BITS\
140 (unsignedN)
141 ROTRn (unsignedN val,
142 unsigned shift)
143 {
144 unsignedN result;
145 ASSERT (shift <= N);
146 result = (((val) >> (shift)) | ((val) << ((N)-(shift))));
147 return result;
148 }
149
150 /* TAGS: SEXT16 SEXT32 SEXT64 */
151
152 INLINE_SIM_BITS\
153 (unsignedN)
154 SEXTn (signedN val,
155 unsigned sign_bit)
156 {
157 /* make the sign-bit most significant and then smear it back into
158 position */
159 ASSERT (sign_bit < N);
160 val <<= _MSB_SHIFT (N, sign_bit);
161 val >>= _MSB_SHIFT (N, sign_bit);
162 return val;
163 }
164
165
166 /* NOTE: See start of file for #define */
167 #undef SEXTn
168 #undef ROTLn
169 #undef ROTRn
170 #undef ROTn
171 #undef INSERTEDn
172 #undef EXTRACTEDn
173 #undef LSMASKEDn
174 #undef LSMASKn
175 #undef MSMASKEDn
176 #undef MSMASKn
177 #undef MASKn
178 #undef MASKEDn
179 #undef signedN
180 #undef unsignedN