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