]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/common/sim-n-bits.h
* config/sh/tm-sh.h (BELIEVE_PCC_PROMOTION): Define, so that
[thirdparty/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)
b3e426bc
AC
39#define MASKn XCONCAT2(MASK,N)
40#define LSMASKEDn XCONCAT2(LSMASKED,N)
7ec396d2
AC
41#define LSMASKn XCONCAT2(LSMASK,N)
42#define MSMASKEDn XCONCAT2(MSMASKED,N)
43#define MSMASKn XCONCAT2(MSMASK,N)
30efae3a
AC
44#define LSEXTRACTEDn XCONCAT2(LSEXTRACTED,N)
45#define MSEXTRACTEDn XCONCAT2(MSEXTRACTED,N)
b3e426bc
AC
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: LSMASKED16 LSMASKED32 LSMASKED64 */
b3e426bc
AC
53
54INLINE_SIM_BITS\
55(unsignedN)
7ec396d2 56LSMASKEDn (unsignedN word,
75b3697d
AC
57 int start,
58 int stop)
b3e426bc 59{
75b3697d
AC
60 word &= LSMASKn (start, stop);
61 return word;
b3e426bc
AC
62}
63
74db699d 64/* TAGS: MSMASKED16 MSMASKED32 MSMASKED64 */
b3e426bc
AC
65
66INLINE_SIM_BITS\
67(unsignedN)
7ec396d2 68MSMASKEDn (unsignedN word,
75b3697d
AC
69 int start,
70 int stop)
b3e426bc 71{
75b3697d
AC
72 word &= MSMASKn (start, stop);
73 return word;
b3e426bc
AC
74}
75
30efae3a 76/* TAGS: LSEXTRACTED16 LSEXTRACTED32 LSEXTRACTED64 */
b3e426bc
AC
77
78INLINE_SIM_BITS\
79(unsignedN)
30efae3a 80LSEXTRACTEDn (unsignedN val,
75b3697d
AC
81 int start,
82 int stop)
b3e426bc 83{
30efae3a
AC
84 val <<= (N - 1 - start); /* drop high bits */
85 val >>= (N - 1 - start) + (stop); /* drop low bits */
86 return val;
87}
88
89/* TAGS: MSEXTRACTED16 MSEXTRACTED32 MSEXTRACTED64 */
90
91INLINE_SIM_BITS\
92(unsignedN)
93MSEXTRACTEDn (unsignedN val,
75b3697d
AC
94 int start,
95 int stop)
30efae3a
AC
96{
97 val <<= (start); /* drop high bits */
98 val >>= (start) + (N - 1 - stop); /* drop low bits */
7ec396d2 99 return val;
b3e426bc
AC
100}
101
74db699d 102/* TAGS: INSERTED16 INSERTED32 INSERTED64 */
b3e426bc
AC
103
104INLINE_SIM_BITS\
105(unsignedN)
7ec396d2 106INSERTEDn (unsignedN val,
75b3697d
AC
107 int start,
108 int stop)
7ec396d2 109{
7ec396d2 110 val <<= _LSB_SHIFT (N, stop);
75b3697d 111 val &= MASKn (start, stop);
7ec396d2
AC
112 return val;
113}
114
74db699d 115/* TAGS: ROT16 ROT32 ROT64 */
7ec396d2
AC
116
117INLINE_SIM_BITS\
118(unsignedN)
119ROTn (unsignedN val,
120 int shift)
b3e426bc 121{
b3e426bc 122 if (shift > 0)
7ec396d2 123 return ROTRn (val, shift);
b3e426bc 124 else if (shift < 0)
7ec396d2 125 return ROTLn (val, -shift);
b3e426bc
AC
126 else
127 return val;
128}
129
74db699d 130/* TAGS: ROTL16 ROTL32 ROTL64 */
b3e426bc
AC
131
132INLINE_SIM_BITS\
133(unsignedN)
7ec396d2 134ROTLn (unsignedN val,
75b3697d 135 int shift)
b3e426bc
AC
136{
137 unsignedN result;
7ec396d2 138 ASSERT (shift <= N);
b3e426bc
AC
139 result = (((val) << (shift)) | ((val) >> ((N)-(shift))));
140 return result;
141}
142
74db699d 143/* TAGS: ROTR16 ROTR32 ROTR64 */
b3e426bc
AC
144
145INLINE_SIM_BITS\
146(unsignedN)
7ec396d2 147ROTRn (unsignedN val,
75b3697d 148 int shift)
b3e426bc
AC
149{
150 unsignedN result;
7ec396d2 151 ASSERT (shift <= N);
b3e426bc
AC
152 result = (((val) >> (shift)) | ((val) << ((N)-(shift))));
153 return result;
154}
155
74db699d 156/* TAGS: SEXT16 SEXT32 SEXT64 */
b3e426bc
AC
157
158INLINE_SIM_BITS\
159(unsignedN)
7ec396d2 160SEXTn (signedN val,
75b3697d 161 int sign_bit)
b3e426bc
AC
162{
163 /* make the sign-bit most significant and then smear it back into
164 position */
7ec396d2
AC
165 ASSERT (sign_bit < N);
166 val <<= _MSB_SHIFT (N, sign_bit);
167 val >>= _MSB_SHIFT (N, sign_bit);
168 return val;
b3e426bc
AC
169}
170
171
172/* NOTE: See start of file for #define */
173#undef SEXTn
174#undef ROTLn
175#undef ROTRn
176#undef ROTn
177#undef INSERTEDn
30efae3a
AC
178#undef LSEXTRACTEDn
179#undef MSEXTRACTEDn
b3e426bc 180#undef LSMASKEDn
7ec396d2
AC
181#undef LSMASKn
182#undef MSMASKEDn
183#undef MSMASKn
b3e426bc
AC
184#undef MASKn
185#undef MASKEDn
186#undef signedN
187#undef unsignedN