Add missing end itemize.
[deliverable/binutils-gdb.git] / sim / common / sim-n-bits.h
CommitLineData
b3e426bc
AC
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
7ec396d2
AC
27#include "sim-xcat.h"
28
74db699d 29#if defined(__STDC__) && defined(signed)
564e2a3f
MM
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
b3e426bc
AC
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)
7ec396d2
AC
42#define LSMASKn XCONCAT2(LSMASK,N)
43#define MSMASKEDn XCONCAT2(MSMASKED,N)
44#define MSMASKn XCONCAT2(MSMASK,N)
b3e426bc
AC
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
74db699d 52/* TAGS: MASKED16 MASKED32 MASKED64 */
b3e426bc
AC
53
54INLINE_SIM_BITS\
55(unsignedN)
7ec396d2
AC
56MASKEDn (unsignedN word,
57 unsigned start,
58 unsigned stop)
b3e426bc 59{
7ec396d2 60 return (word & MASKn (start, stop));
b3e426bc
AC
61}
62
74db699d 63/* TAGS: LSMASKED16 LSMASKED32 LSMASKED64 */
b3e426bc
AC
64
65INLINE_SIM_BITS\
66(unsignedN)
7ec396d2
AC
67LSMASKEDn (unsignedN word,
68 unsigned nr_bits)
b3e426bc 69{
7ec396d2 70 return (word & LSMASKn (nr_bits));
b3e426bc
AC
71}
72
74db699d 73/* TAGS: MSMASKED16 MSMASKED32 MSMASKED64 */
b3e426bc
AC
74
75INLINE_SIM_BITS\
76(unsignedN)
7ec396d2
AC
77MSMASKEDn (unsignedN word,
78 unsigned nr_bits)
b3e426bc 79{
7ec396d2 80 return (word & MSMASKn (nr_bits));
b3e426bc
AC
81}
82
74db699d 83/* TAGS: EXTRACTED16 EXTRACTED32 EXTRACTED64 */
b3e426bc
AC
84
85INLINE_SIM_BITS\
86(unsignedN)
7ec396d2
AC
87EXTRACTEDn (unsignedN val,
88 unsigned start,
89 unsigned stop)
b3e426bc 90{
7ec396d2
AC
91 val <<= _MSB_SHIFT (N, start);
92 val >>= (_MSB_SHIFT (N, start) + _LSB_SHIFT (N, stop));
93 return val;
b3e426bc
AC
94}
95
74db699d 96/* TAGS: INSERTED16 INSERTED32 INSERTED64 */
b3e426bc
AC
97
98INLINE_SIM_BITS\
99(unsignedN)
7ec396d2
AC
100INSERTEDn (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
74db699d 109/* TAGS: ROT16 ROT32 ROT64 */
7ec396d2
AC
110
111INLINE_SIM_BITS\
112(unsignedN)
113ROTn (unsignedN val,
114 int shift)
b3e426bc 115{
b3e426bc 116 if (shift > 0)
7ec396d2 117 return ROTRn (val, shift);
b3e426bc 118 else if (shift < 0)
7ec396d2 119 return ROTLn (val, -shift);
b3e426bc
AC
120 else
121 return val;
122}
123
74db699d 124/* TAGS: ROTL16 ROTL32 ROTL64 */
b3e426bc
AC
125
126INLINE_SIM_BITS\
127(unsignedN)
7ec396d2
AC
128ROTLn (unsignedN val,
129 unsigned shift)
b3e426bc
AC
130{
131 unsignedN result;
7ec396d2 132 ASSERT (shift <= N);
b3e426bc
AC
133 result = (((val) << (shift)) | ((val) >> ((N)-(shift))));
134 return result;
135}
136
74db699d 137/* TAGS: ROTR16 ROTR32 ROTR64 */
b3e426bc
AC
138
139INLINE_SIM_BITS\
140(unsignedN)
7ec396d2
AC
141ROTRn (unsignedN val,
142 unsigned shift)
b3e426bc
AC
143{
144 unsignedN result;
7ec396d2 145 ASSERT (shift <= N);
b3e426bc
AC
146 result = (((val) >> (shift)) | ((val) << ((N)-(shift))));
147 return result;
148}
149
74db699d 150/* TAGS: SEXT16 SEXT32 SEXT64 */
b3e426bc
AC
151
152INLINE_SIM_BITS\
153(unsignedN)
7ec396d2
AC
154SEXTn (signedN val,
155 unsigned sign_bit)
b3e426bc
AC
156{
157 /* make the sign-bit most significant and then smear it back into
158 position */
7ec396d2
AC
159 ASSERT (sign_bit < N);
160 val <<= _MSB_SHIFT (N, sign_bit);
161 val >>= _MSB_SHIFT (N, sign_bit);
162 return val;
b3e426bc
AC
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
7ec396d2
AC
174#undef LSMASKn
175#undef MSMASKEDn
176#undef MSMASKn
b3e426bc
AC
177#undef MASKn
178#undef MASKEDn
179#undef signedN
180#undef unsignedN
This page took 0.043648 seconds and 4 git commands to generate.