1 /* This file is part of the program psim.
3 Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>
4 Copyright (C) 1997, Free Software Foundation, Inc.
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.
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.
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.
24 #error "N must be #defined"
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. */
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)
52 /* TAGS: MASKED16 MASKED32 MASKED64 */
56 MASKEDn (unsignedN word
,
60 return (word
& MASKn (start
, stop
));
63 /* TAGS: LSMASKED16 LSMASKED32 LSMASKED64 */
67 LSMASKEDn (unsignedN word
,
70 return (word
& LSMASKn (nr_bits
));
73 /* TAGS: MSMASKED16 MSMASKED32 MSMASKED64 */
77 MSMASKEDn (unsignedN word
,
80 return (word
& MSMASKn (nr_bits
));
83 /* TAGS: EXTRACTED16 EXTRACTED32 EXTRACTED64 */
87 EXTRACTEDn (unsignedN val
,
91 val
<<= _MSB_SHIFT (N
, start
);
92 val
>>= (_MSB_SHIFT (N
, start
) + _LSB_SHIFT (N
, stop
));
96 /* TAGS: INSERTED16 INSERTED32 INSERTED64 */
100 INSERTEDn (unsignedN val
,
104 val
&= LSMASKn (_MAKE_WIDTH (start
, stop
));
105 val
<<= _LSB_SHIFT (N
, stop
);
109 /* TAGS: ROT16 ROT32 ROT64 */
117 return ROTRn (val
, shift
);
119 return ROTLn (val
, -shift
);
124 /* TAGS: ROTL16 ROTL32 ROTL64 */
128 ROTLn (unsignedN val
,
133 result
= (((val
) << (shift
)) | ((val
) >> ((N
)-(shift
))));
137 /* TAGS: ROTR16 ROTR32 ROTR64 */
141 ROTRn (unsignedN val
,
146 result
= (((val
) >> (shift
)) | ((val
) << ((N
)-(shift
))));
150 /* TAGS: SEXT16 SEXT32 SEXT64 */
157 /* make the sign-bit most significant and then smear it back into
159 ASSERT (sign_bit
< N
);
160 val
<<= _MSB_SHIFT (N
, sign_bit
);
161 val
>>= _MSB_SHIFT (N
, sign_bit
);
166 /* NOTE: See start of file for #define */
This page took 0.03238 seconds and 4 git commands to generate.