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