SystemC  2.3.1
Accellera SystemC proof-of-concept library
sc_nbdefs.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  The following code is derived, directly or indirectly, from the SystemC
4  source code Copyright (c) 1996-2014 by all Contributors.
5  All Rights reserved.
6 
7  The contents of this file are subject to the restrictions and limitations
8  set forth in the SystemC Open Source License (the "License");
9  You may not use this file except in compliance with such restrictions and
10  limitations. You may obtain instructions on how to receive a copy of the
11  License at http://www.accellera.org/. Software distributed by Contributors
12  under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
13  ANY KIND, either express or implied. See the License for the specific
14  language governing rights and limitations under the License.
15 
16  *****************************************************************************/
17 
18 /*****************************************************************************
19 
20  sc_nbdefs.h -- Top level header file for arbitrary precision signed/unsigned
21  arithmetic. This file defines all the constants needed.
22 
23  Original Author: Ali Dasdan, Synopsys, Inc.
24 
25  *****************************************************************************/
26 
27 /*****************************************************************************
28 
29  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
30  changes you are making here.
31 
32  Name, Affiliation, Date:
33  Description of Modification:
34 
35  *****************************************************************************/
36 
37 // $Log: sc_nbdefs.h,v $
38 // Revision 1.7 2011/02/18 20:19:15 acg
39 // Andy Goodrich: updating Copyright notice.
40 //
41 // Revision 1.6 2011/02/18 20:09:34 acg
42 // Philipp A. Hartmann: added alternative #define for Windows to guard.
43 //
44 // Revision 1.5 2011/01/20 16:52:20 acg
45 // Andy Goodrich: changes for IEEE 1666 2011.
46 //
47 // Revision 1.4 2010/02/08 18:35:55 acg
48 // Andy Goodrich: Philipp Hartmann's changes for Solaris and Linux 64.
49 //
50 // Revision 1.2 2009/05/22 16:06:29 acg
51 // Andy Goodrich: process control updates.
52 //
53 // Revision 1.1.1.1 2006/12/15 20:20:05 acg
54 // SystemC 2.3
55 //
56 // Revision 1.3 2006/01/13 18:49:32 acg
57 // Added $Log command so that CVS check in comments are reproduced in the
58 // source.
59 //
60 
61 #ifndef SC_NBDEFS_H
62 #define SC_NBDEFS_H
63 
64 
65 #include "sysc/kernel/sc_cmnhdr.h"
66 
67 #include <climits>
68 
69 #if defined(__sun) || defined(__sun__)
70 # include <inttypes.h>
71 #elif !defined(WIN32) && !defined(_WIN32)
72 # include <stdint.h>
73 #endif
74 
75 #include "sysc/utils/sc_iostream.h"
76 #include "sysc/kernel/sc_constants.h" // For SC_MAX_NBITS
77 
78 // Activate support mixed operands for concatenation via the comma operator
79 #define SC_DT_MIXED_COMMA_OPERATORS
80 
81 
82 namespace sc_dt
83 {
84 
85 // ----------------------------------------------------------------------------
86 // ENUM : sc_numrep
87 //
88 // Enumeration of number representations for character string conversion.
89 // ----------------------------------------------------------------------------
90 
92 {
93  SC_NOBASE = 0,
94  SC_BIN = 2,
95  SC_OCT = 8,
96  SC_DEC = 10,
97  SC_HEX = 16,
105 };
106 
107 
108 // Sign of a number:
109 #define SC_NEG -1 // Negative number
110 #define SC_ZERO 0 // Zero
111 #define SC_POS 1 // Positive number
112 #define SC_NOSIGN 2 // Uninitialized sc_signed number
113 
114 typedef unsigned char uchar;
115 
116 // A small_type number is at least a char. Defining an int is probably
117 // better for alignment.
118 typedef int small_type;
119 
120 // Attributes of a byte.
121 #define BITS_PER_BYTE 8
122 #define BYTE_RADIX 256
123 #define BYTE_MASK 255
124 
125 // LOG2_BITS_PER_BYTE = log2(BITS_PER_BYTE), assuming that
126 // BITS_PER_BYTE is a power of 2.
127 #define LOG2_BITS_PER_BYTE 3
128 
129 // Attributes of the unsigned long. These definitions are used mainly in
130 // the functions that are aware of the internal representation of
131 // digits, e.g., get/set_packed_rep().
132 #define BYTES_PER_DIGIT_TYPE 4
133 #define BITS_PER_DIGIT_TYPE 32
134 
135 // Attributes of a digit, i.e., unsigned long less the overflow bits.
136 #define BYTES_PER_DIGIT 4
137 #define BITS_PER_DIGIT 30
138 #define DIGIT_RADIX (1ul << BITS_PER_DIGIT)
139 #define DIGIT_MASK (DIGIT_RADIX - 1)
140 // Make sure that BYTES_PER_DIGIT = ceil(BITS_PER_DIGIT / BITS_PER_BYTE).
141 
142 // Similar attributes for the half of a digit. Note that
143 // HALF_DIGIT_RADIX is equal to the square root of DIGIT_RADIX. These
144 // definitions are used mainly in the multiplication routines.
145 #define BITS_PER_HALF_DIGIT (BITS_PER_DIGIT / 2)
146 #define HALF_DIGIT_RADIX (1ul << BITS_PER_HALF_DIGIT)
147 #define HALF_DIGIT_MASK (HALF_DIGIT_RADIX - 1)
148 
149 // DIV_CEIL2(x, y) = ceil(x / y). x and y are positive numbers.
150 #define DIV_CEIL2(x, y) (((x) - 1) / (y) + 1)
151 
152 // DIV_CEIL(x) = ceil(x / BITS_PER_DIGIT) = the number of digits to
153 // store x bits. x is a positive number.
154 #define DIV_CEIL(x) DIV_CEIL2(x, BITS_PER_DIGIT)
155 
156 #ifdef SC_MAX_NBITS
157 extern const int MAX_NDIGITS;
158 // Consider a number with x bits another with y bits. The maximum
159 // number of bits happens when we multiply them. The result will have
160 // (x + y) bits. Assume that x + y <= SC_MAX_NBITS. Then, DIV_CEIL(x) +
161 // DIV_CEIL(y) <= DIV_CEIL(SC_MAX_NBITS) + 2. This is the reason for +2
162 // above. With this change, MAX_NDIGITS must be enough to hold the
163 // result of any operation.
164 #endif
165 
166 // Support for "digit" vectors used to hold the values of sc_signed,
167 // sc_unsigned, sc_bv_base, and sc_lv_base data types. This type is also used
168 // in the concatenation support. An sc_digit is currently an unsigned 32-bit
169 // quantity. The typedef used is an unsigned int, rather than an unsigned long,
170 // since the unsigned long data type varies in size between 32-bit and 64-bit
171 // machines.
172 
173 typedef unsigned int sc_digit; // 32-bit unsigned integer
174 
175 // Support for the long long type. This type is not in the standard
176 // but is usually supported by compilers.
177 #ifndef _WIN32
178 # if defined(__x86_64__)
179  typedef long long int64;
180  typedef unsigned long long uint64;
181 # else
182  typedef int64_t int64;
183  typedef uint64_t uint64;
184 # endif
185  extern const uint64 UINT64_ZERO;
186  extern const uint64 UINT64_ONE;
187  extern const uint64 UINT64_32ONES;
188 #else
189  typedef __int64 int64;
190  typedef unsigned __int64 uint64;
191  extern const uint64 UINT64_ZERO;
192  extern const uint64 UINT64_ONE;
193  extern const uint64 UINT64_32ONES;
194 #endif
195 
196 
197 // Bits per ...
198 // will be deleted in the future. Use numeric_limits instead
199 #define BITS_PER_CHAR 8
200 #define BITS_PER_INT (sizeof(int) * BITS_PER_CHAR)
201 #define BITS_PER_LONG (sizeof(long) * BITS_PER_CHAR)
202 #define BITS_PER_INT64 (sizeof(::sc_dt::int64) * BITS_PER_CHAR)
203 #define BITS_PER_UINT (sizeof(unsigned int) * BITS_PER_CHAR)
204 #define BITS_PER_ULONG (sizeof(unsigned long) * BITS_PER_CHAR)
205 #define BITS_PER_UINT64 (sizeof(::sc_dt::uint64) * BITS_PER_CHAR)
206 
207 // Digits per ...
208 #define DIGITS_PER_CHAR 1
209 #define DIGITS_PER_INT ((BITS_PER_INT+29)/30)
210 #define DIGITS_PER_LONG ((BITS_PER_LONG+29)/30)
211 #define DIGITS_PER_INT64 ((BITS_PER_INT64+29)/30)
212 #define DIGITS_PER_UINT ((BITS_PER_UINT+29)/30)
213 #define DIGITS_PER_ULONG ((BITS_PER_ULONG+29)/30)
214 #define DIGITS_PER_UINT64 ((BITS_PER_UINT64+29)/30)
215 
216 // Above, BITS_PER_X is mainly used for sc_signed, and BITS_PER_UX is
217 // mainly used for sc_unsigned.
218 
219 #if defined( _WIN32 ) || defined( __HP_aCC )
220 typedef unsigned long fmtflags;
221 #else
223 #endif
224 
225 extern const small_type NB_DEFAULT_BASE ;
226 
227 // For sc_int code:
228 #define LLWIDTH BITS_PER_INT64
229 #define INTWIDTH BITS_PER_INT
230 
231 #ifndef _32BIT_
232 
233 typedef int64 int_type;
235 #define SC_INTWIDTH 64
236 extern const uint64 UINT_ZERO;
237 extern const uint64 UINT_ONE;
238 
239 #else
240 
241 typedef int int_type;
242 typedef unsigned int uint_type;
243 #define SC_INTWIDTH 32
244 extern const unsigned int UINT_ZERO;
245 extern const unsigned int UINT_ONE;
246 
247 #endif
248 
249 
250 #if defined(_MSC_VER) && ( _MSC_VER < 1300 )
251  // VC++6 bug
252  ::std::ostream& operator << ( ::std::ostream&, int64 );
253  ::std::ostream& operator << ( ::std::ostream&, uint64 );
254 #endif
255 
256 } // namespace sc_dt
257 
258 
259 #if defined(_MSC_VER) && ( _MSC_VER < 1300 )
260 
261  inline
262  ::std::ostream&
263  operator << ( ::std::ostream& os, sc_dt::int64 a )
264  {
265  sc_dt::operator << ( os, a );
266  return os;
267  }
268 
269  inline
270  ::std::ostream&
271  operator << ( ::std::ostream& os, sc_dt::uint64 a )
272  {
273  sc_dt::operator << ( os, a );
274  return os;
275  }
276 
277 #endif
278 
279 
280 #endif
const uint64 UINT_ZERO
const small_type NB_DEFAULT_BASE
unsigned char uchar
Definition: sc_nbdefs.h:114
inline::std::ostream & operator<<(::std::ostream &os, const sc_fifo< T > &a)
Definition: sc_fifo.h:424
sc_numrep
Definition: sc_nbdefs.h:91
unsigned int sc_digit
Definition: sc_nbdefs.h:173
int64 int_type
Definition: sc_nbdefs.h:233
const uint64 UINT64_ZERO
uint64_t uint64
Definition: sc_nbdefs.h:183
int64_t int64
Definition: sc_nbdefs.h:182
int small_type
Definition: sc_nbdefs.h:118
::std::ios::fmtflags fmtflags
Definition: sc_nbdefs.h:222
const uint64 UINT_ONE
const uint64 UINT64_ONE
const uint64 UINT64_32ONES
inline::std::ostream & operator<<(::std::ostream &os, const sc_bit &a)
Definition: sc_bit.h:386
uint64 uint_type
Definition: sc_nbdefs.h:234