112837Sgabeblack@google.com/*****************************************************************************
212837Sgabeblack@google.com
312837Sgabeblack@google.com  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
412837Sgabeblack@google.com  more contributor license agreements.  See the NOTICE file distributed
512837Sgabeblack@google.com  with this work for additional information regarding copyright ownership.
612837Sgabeblack@google.com  Accellera licenses this file to you under the Apache License, Version 2.0
712837Sgabeblack@google.com  (the "License"); you may not use this file except in compliance with the
812837Sgabeblack@google.com  License.  You may obtain a copy of the License at
912837Sgabeblack@google.com
1012837Sgabeblack@google.com    http://www.apache.org/licenses/LICENSE-2.0
1112837Sgabeblack@google.com
1212837Sgabeblack@google.com  Unless required by applicable law or agreed to in writing, software
1312837Sgabeblack@google.com  distributed under the License is distributed on an "AS IS" BASIS,
1412837Sgabeblack@google.com  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1512837Sgabeblack@google.com  implied.  See the License for the specific language governing
1612837Sgabeblack@google.com  permissions and limitations under the License.
1712837Sgabeblack@google.com
1812837Sgabeblack@google.com *****************************************************************************/
1912837Sgabeblack@google.com
2012837Sgabeblack@google.com/*****************************************************************************
2112853Sgabeblack@google.com
2212837Sgabeblack@google.com  sc_nbdefs.h -- Top level header file for arbitrary precision signed/unsigned
2312837Sgabeblack@google.com                 arithmetic. This file defines all the constants needed.
2412853Sgabeblack@google.com
2512853Sgabeblack@google.com  Original Author: Ali Dasdan, Synopsys, Inc.
2612853Sgabeblack@google.com
2712837Sgabeblack@google.com *****************************************************************************/
2812837Sgabeblack@google.com
2912853Sgabeblack@google.com/*****************************************************************************
3012853Sgabeblack@google.com
3112853Sgabeblack@google.com  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
3212853Sgabeblack@google.com  changes you are making here.
3312853Sgabeblack@google.com
3412853Sgabeblack@google.com      Name, Affiliation, Date: Torsten Maehne, Berner Fachhochschule,
3512853Sgabeblack@google.com                               2016-09-24
3612853Sgabeblack@google.com  Description of Modification: Move constant definitions to the header so that
3712853Sgabeblack@google.com                               that their value is known at compile time.
3812853Sgabeblack@google.com
3912853Sgabeblack@google.com *****************************************************************************/
4012853Sgabeblack@google.com
4112853Sgabeblack@google.com// $Log: sc_nbdefs.h,v $
4212853Sgabeblack@google.com// Revision 1.7  2011/02/18 20:19:15  acg
4312853Sgabeblack@google.com//  Andy Goodrich: updating Copyright notice.
4412853Sgabeblack@google.com//
4512853Sgabeblack@google.com// Revision 1.6  2011/02/18 20:09:34  acg
4612853Sgabeblack@google.com//  Philipp A. Hartmann: added alternative #define for Windows to guard.
4712853Sgabeblack@google.com//
4812853Sgabeblack@google.com// Revision 1.5  2011/01/20 16:52:20  acg
4912853Sgabeblack@google.com//  Andy Goodrich: changes for IEEE 1666 2011.
5012853Sgabeblack@google.com//
5112853Sgabeblack@google.com// Revision 1.4  2010/02/08 18:35:55  acg
5212853Sgabeblack@google.com//  Andy Goodrich: Philipp Hartmann's changes for Solaris and Linux 64.
5312853Sgabeblack@google.com//
5412853Sgabeblack@google.com// Revision 1.2  2009/05/22 16:06:29  acg
5512853Sgabeblack@google.com//  Andy Goodrich: process control updates.
5612853Sgabeblack@google.com//
5712853Sgabeblack@google.com// Revision 1.1.1.1  2006/12/15 20:20:05  acg
5812853Sgabeblack@google.com// SystemC 2.3
5912853Sgabeblack@google.com//
6012853Sgabeblack@google.com// Revision 1.3  2006/01/13 18:49:32  acg
6112853Sgabeblack@google.com// Added $Log command so that CVS check in comments are reproduced in the
6212853Sgabeblack@google.com// source.
6312853Sgabeblack@google.com//
6412853Sgabeblack@google.com
6512853Sgabeblack@google.com#ifndef __SYSTEMC_EXT_DT_INT_SC_NBDEFS_HH__
6612853Sgabeblack@google.com#define __SYSTEMC_EXT_DT_INT_SC_NBDEFS_HH__
6712837Sgabeblack@google.com
6812837Sgabeblack@google.com#include <stdint.h>
6912837Sgabeblack@google.com
7012837Sgabeblack@google.com#include <climits>
7112837Sgabeblack@google.com
7212837Sgabeblack@google.comnamespace sc_dt
7312837Sgabeblack@google.com{
7412837Sgabeblack@google.com
7512837Sgabeblack@google.com// ----------------------------------------------------------------------------
7612837Sgabeblack@google.com//  ENUM : sc_numrep
7712837Sgabeblack@google.com//
7812837Sgabeblack@google.com//  Enumeration of number representations for character string conversion.
7912837Sgabeblack@google.com// ----------------------------------------------------------------------------
8012837Sgabeblack@google.com
8112837Sgabeblack@google.comenum sc_numrep
8212837Sgabeblack@google.com{
8312837Sgabeblack@google.com    SC_NOBASE = 0,
8412837Sgabeblack@google.com    SC_BIN = 2,
8512837Sgabeblack@google.com    SC_OCT = 8,
8612837Sgabeblack@google.com    SC_DEC = 10,
8712837Sgabeblack@google.com    SC_HEX = 16,
8812837Sgabeblack@google.com    SC_BIN_US,
8912837Sgabeblack@google.com    SC_BIN_SM,
9012837Sgabeblack@google.com    SC_OCT_US,
9112837Sgabeblack@google.com    SC_OCT_SM,
9212837Sgabeblack@google.com    SC_HEX_US,
9312837Sgabeblack@google.com    SC_HEX_SM,
9412837Sgabeblack@google.com    SC_CSD
9512837Sgabeblack@google.com};
9612837Sgabeblack@google.com
9712837Sgabeblack@google.com
9812837Sgabeblack@google.com// Sign of a number:
9912837Sgabeblack@google.com#define SC_NEG -1 // Negative number
10012837Sgabeblack@google.com#define SC_ZERO 0 // Zero
10112837Sgabeblack@google.com#define SC_POS 1 // Positive number
10212837Sgabeblack@google.com#define SC_NOSIGN 2 // Uninitialized sc_signed number
10312837Sgabeblack@google.com
10412837Sgabeblack@google.comtypedef unsigned char uchar;
10512837Sgabeblack@google.com
10612837Sgabeblack@google.com// A small_type number is at least a char. Defining an int is probably
10712837Sgabeblack@google.com// better for alignment.
10812837Sgabeblack@google.comtypedef int small_type;
10912837Sgabeblack@google.com
11012837Sgabeblack@google.com// Attributes of a byte.
11112837Sgabeblack@google.com#define BITS_PER_BYTE 8
11212837Sgabeblack@google.com#define BYTE_RADIX 256
11312837Sgabeblack@google.com#define BYTE_MASK 255
11412837Sgabeblack@google.com
11512837Sgabeblack@google.com// LOG2_BITS_PER_BYTE = log2(BITS_PER_BYTE), assuming that
11612837Sgabeblack@google.com// BITS_PER_BYTE is a power of 2.
11712837Sgabeblack@google.com#define LOG2_BITS_PER_BYTE 3
11812837Sgabeblack@google.com
11912837Sgabeblack@google.com// Attributes of the unsigned long. These definitions are used mainly in
12012853Sgabeblack@google.com// the functions that are aware of the internal representation of
12112853Sgabeblack@google.com// digits, e.g., get/set_packed_rep().
12212837Sgabeblack@google.com#define BYTES_PER_DIGIT_TYPE 4
12312837Sgabeblack@google.com#define BITS_PER_DIGIT_TYPE 32
12412837Sgabeblack@google.com
12512837Sgabeblack@google.com// Attributes of a digit, i.e., unsigned long less the overflow bits.
12612837Sgabeblack@google.com#define BYTES_PER_DIGIT 4
12712837Sgabeblack@google.com#define BITS_PER_DIGIT 30
12812837Sgabeblack@google.com#define DIGIT_RADIX (1ul << BITS_PER_DIGIT)
12912837Sgabeblack@google.com#define DIGIT_MASK (DIGIT_RADIX - 1)
13012837Sgabeblack@google.com// Make sure that BYTES_PER_DIGIT = ceil(BITS_PER_DIGIT / BITS_PER_BYTE).
13112837Sgabeblack@google.com
13212837Sgabeblack@google.com// Similar attributes for the half of a digit. Note that
13312837Sgabeblack@google.com// HALF_DIGIT_RADIX is equal to the square root of DIGIT_RADIX. These
13412837Sgabeblack@google.com// definitions are used mainly in the multiplication routines.
13512837Sgabeblack@google.com#define BITS_PER_HALF_DIGIT (BITS_PER_DIGIT / 2)
13612837Sgabeblack@google.com#define HALF_DIGIT_RADIX (1ul << BITS_PER_HALF_DIGIT)
13712837Sgabeblack@google.com#define HALF_DIGIT_MASK (HALF_DIGIT_RADIX - 1)
13812837Sgabeblack@google.com
13912837Sgabeblack@google.com// DIV_CEIL2(x, y) = ceil(x / y). x and y are positive numbers.
14012837Sgabeblack@google.com#define DIV_CEIL2(x, y) (((x) - 1) / (y) + 1)
14112837Sgabeblack@google.com
14212837Sgabeblack@google.com// DIV_CEIL(x) = ceil(x / BITS_PER_DIGIT) = the number of digits to
14312837Sgabeblack@google.com// store x bits. x is a positive number.
14412837Sgabeblack@google.com#define DIV_CEIL(x) DIV_CEIL2(x, BITS_PER_DIGIT)
14512837Sgabeblack@google.com
14612837Sgabeblack@google.com#ifdef SC_MAX_NBITS
14712837Sgabeblack@google.comstatic const int MAX_NDIGITS = DIV_CEIL(SC_MAX_NBITS) + 2;
14812837Sgabeblack@google.com// Consider a number with x bits another with y bits. The maximum
14912837Sgabeblack@google.com// number of bits happens when we multiply them. The result will have
15012837Sgabeblack@google.com// (x + y) bits. Assume that x + y <= SC_MAX_NBITS. Then, DIV_CEIL(x) +
15112837Sgabeblack@google.com// DIV_CEIL(y) <= DIV_CEIL(SC_MAX_NBITS) + 2. This is the reason for +2
15212837Sgabeblack@google.com// above. With this change, MAX_NDIGITS must be enough to hold the
15312837Sgabeblack@google.com// result of any operation.
15412837Sgabeblack@google.com#endif
15512837Sgabeblack@google.com
15612837Sgabeblack@google.com// Support for "digit" vectors used to hold the values of sc_signed,
15712837Sgabeblack@google.com// sc_unsigned, sc_bv_base,  and sc_lv_base data types. This type is also used
15812837Sgabeblack@google.com// in the concatenation support. An sc_digit is currently an unsigned 32-bit
15912837Sgabeblack@google.com// quantity. The typedef used is an unsigned int, rather than an unsigned long,
16012837Sgabeblack@google.com// since the unsigned long data type varies in size between 32-bit and 64-bit
16112837Sgabeblack@google.com// machines.
16212837Sgabeblack@google.com
16312853Sgabeblack@google.comtypedef unsigned int sc_digit; // 32-bit unsigned integer
16412837Sgabeblack@google.com
16512837Sgabeblack@google.com// Support for the long long type. This type is not in the standard
16612837Sgabeblack@google.com// but is usually supported by compilers.
16712853Sgabeblack@google.com#if defined(__x86_64__) || defined(__aarch64__)
16812853Sgabeblack@google.comtypedef long long int64;
16912853Sgabeblack@google.comtypedef unsigned long long uint64;
17012853Sgabeblack@google.com#else
17112837Sgabeblack@google.comtypedef int64_t int64;
17212837Sgabeblack@google.comtypedef uint64_t uint64;
17312853Sgabeblack@google.com#endif
17412837Sgabeblack@google.com
17512853Sgabeblack@google.comstatic const uint64 UINT64_ZERO = 0ULL;
17612853Sgabeblack@google.comstatic const uint64 UINT64_ONE = 1ULL;
17712837Sgabeblack@google.comstatic const uint64 UINT64_32ONES = 0x00000000ffffffffULL;
17812837Sgabeblack@google.com
17912853Sgabeblack@google.com
18012837Sgabeblack@google.com// Bits per ...
18112837Sgabeblack@google.com// will be deleted in the future. Use numeric_limits instead
18212853Sgabeblack@google.com#define BITS_PER_CHAR 8
18312853Sgabeblack@google.com#define BITS_PER_INT (sizeof(int) * BITS_PER_CHAR)
18412853Sgabeblack@google.com#define BITS_PER_LONG (sizeof(long) * BITS_PER_CHAR)
18512853Sgabeblack@google.com#define BITS_PER_INT64 (sizeof(::sc_dt::int64) * BITS_PER_CHAR)
18612853Sgabeblack@google.com#define BITS_PER_UINT (sizeof(unsigned int) * BITS_PER_CHAR)
18712853Sgabeblack@google.com#define BITS_PER_ULONG (sizeof(unsigned long) * BITS_PER_CHAR)
18812837Sgabeblack@google.com#define BITS_PER_UINT64 (sizeof(::sc_dt::uint64) * BITS_PER_CHAR)
18912837Sgabeblack@google.com
19012837Sgabeblack@google.com// Digits per ...
19112853Sgabeblack@google.com#define DIGITS_PER_CHAR 1
19212853Sgabeblack@google.com#define DIGITS_PER_INT ((BITS_PER_INT + 29) / 30)
19312853Sgabeblack@google.com#define DIGITS_PER_LONG ((BITS_PER_LONG + 29) / 30)
19412853Sgabeblack@google.com#define DIGITS_PER_INT64 ((BITS_PER_INT64 + 29) / 30)
19512853Sgabeblack@google.com#define DIGITS_PER_UINT ((BITS_PER_UINT + 29) / 30)
19612853Sgabeblack@google.com#define DIGITS_PER_ULONG ((BITS_PER_ULONG + 29) / 30)
19712853Sgabeblack@google.com#define DIGITS_PER_UINT64 ((BITS_PER_UINT64 + 29) / 30)
19812837Sgabeblack@google.com
19912837Sgabeblack@google.com// Above, BITS_PER_X is mainly used for sc_signed, and BITS_PER_UX is
20012837Sgabeblack@google.com// mainly used for sc_unsigned.
20112837Sgabeblack@google.com
20212837Sgabeblack@google.comstatic const small_type NB_DEFAULT_BASE = SC_DEC;
20312837Sgabeblack@google.com
20412837Sgabeblack@google.com// For sc_int code:
20512837Sgabeblack@google.com
20612837Sgabeblack@google.comtypedef int64 int_type;
20712837Sgabeblack@google.comtypedef uint64 uint_type;
20812837Sgabeblack@google.com#define SC_INTWIDTH 64
20912837Sgabeblack@google.comstatic const uint64 UINT_ZERO = UINT64_ZERO;
21012837Sgabeblack@google.comstatic const uint64 UINT_ONE = UINT64_ONE;
21112837Sgabeblack@google.com
21212837Sgabeblack@google.com} // namespace sc_dt
21312837Sgabeblack@google.com
21412853Sgabeblack@google.com#endif // __SYSTEMC_EXT_DT_INT_SC_NBDEFS_HH__
215