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: Torsten Maehne, Berner Fachhochschule, 2016-09-24 35 Description of Modification: Move constant definitions to the header so that 36 that their value is known at compile time. 37 38 *****************************************************************************/ 39 40 // $Log: sc_nbdefs.h,v $ 41 // Revision 1.7 2011/02/18 20:19:15 acg 42 // Andy Goodrich: updating Copyright notice. 43 // 44 // Revision 1.6 2011/02/18 20:09:34 acg 45 // Philipp A. Hartmann: added alternative #define for Windows to guard. 46 // 47 // Revision 1.5 2011/01/20 16:52:20 acg 48 // Andy Goodrich: changes for IEEE 1666 2011. 49 // 50 // Revision 1.4 2010/02/08 18:35:55 acg 51 // Andy Goodrich: Philipp Hartmann's changes for Solaris and Linux 64. 52 // 53 // Revision 1.2 2009/05/22 16:06:29 acg 54 // Andy Goodrich: process control updates. 55 // 56 // Revision 1.1.1.1 2006/12/15 20:20:05 acg 57 // SystemC 2.3 58 // 59 // Revision 1.3 2006/01/13 18:49:32 acg 60 // Added $Log command so that CVS check in comments are reproduced in the 61 // source. 62 // 63 64 #ifndef SC_NBDEFS_H 65 #define SC_NBDEFS_H 66 67 68 #include "sysc/kernel/sc_cmnhdr.h" 69 70 #include <climits> 71 72 #if defined(__sun) || defined(__sun__) 73 # include <inttypes.h> 74 #elif !defined(WIN32) && !defined(_WIN32) 75 # include <stdint.h> 76 #endif 77 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 84 namespace sc_dt 85 { 86 87 // ---------------------------------------------------------------------------- 88 // ENUM : sc_numrep 89 // 90 // Enumeration of number representations for character string conversion. 91 // ---------------------------------------------------------------------------- 92 93 enum 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 116 typedef unsigned char uchar; 117 118 // A small_type number is at least a char. Defining an int is probably 119 // better for alignment. 120 typedef 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 159 static const int MAX_NDIGITS = DIV_CEIL(SC_MAX_NBITS) + 2; 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 175 typedef 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__) || defined(__aarch64__) 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 #else 188 typedef __int64 int64; 189 typedef unsigned __int64 uint64; 190 #endif 191 192 #if !defined(_WIN32) || defined(__MINGW32__) 193 static const uint64 UINT64_ZERO = 0ULL; 194 static const uint64 UINT64_ONE = 1ULL; 195 static const uint64 UINT64_32ONES = 0x00000000ffffffffULL; 196 #else 197 static const uint64 UINT64_ZERO = 0i64; 198 static const uint64 UINT64_ONE = 1i64; 199 static const uint64 UINT64_32ONES = 0x00000000ffffffffi64; 200 #endif 201 202 203 // Bits per ... 204 // will be deleted in the future. Use numeric_limits instead 205 #define BITS_PER_CHAR 8 206 #define BITS_PER_INT (sizeof(int) * BITS_PER_CHAR) 207 #define BITS_PER_LONG (sizeof(long) * BITS_PER_CHAR) 208 #define BITS_PER_INT64 (sizeof(::sc_dt::int64) * BITS_PER_CHAR) 209 #define BITS_PER_UINT (sizeof(unsigned int) * BITS_PER_CHAR) 210 #define BITS_PER_ULONG (sizeof(unsigned long) * BITS_PER_CHAR) 211 #define BITS_PER_UINT64 (sizeof(::sc_dt::uint64) * BITS_PER_CHAR) 212 213 // Digits per ... 214 #define DIGITS_PER_CHAR 1 215 #define DIGITS_PER_INT ((BITS_PER_INT+29)/30) 216 #define DIGITS_PER_LONG ((BITS_PER_LONG+29)/30) 217 #define DIGITS_PER_INT64 ((BITS_PER_INT64+29)/30) 218 #define DIGITS_PER_UINT ((BITS_PER_UINT+29)/30) 219 #define DIGITS_PER_ULONG ((BITS_PER_ULONG+29)/30) 220 #define DIGITS_PER_UINT64 ((BITS_PER_UINT64+29)/30) 221 222 // Above, BITS_PER_X is mainly used for sc_signed, and BITS_PER_UX is 223 // mainly used for sc_unsigned. 224 225 static const small_type NB_DEFAULT_BASE = SC_DEC; 226 227 // For sc_int code: 228 229 typedef int64 int_type; 230 typedef uint64 uint_type; 231 # define SC_INTWIDTH 64 232 static const uint64 UINT_ZERO = UINT64_ZERO; 233 static const uint64 UINT_ONE = UINT64_ONE; 234 235 } // namespace sc_dt 236 237 #endif 238