src/sysc/datatypes/int/sc_nbdefs.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003   The following code is derived, directly or indirectly, from the SystemC
00004   source code Copyright (c) 1996-2005 by all Contributors.
00005   All Rights reserved.
00006 
00007   The contents of this file are subject to the restrictions and limitations
00008   set forth in the SystemC Open Source License Version 2.4 (the "License");
00009   You may not use this file except in compliance with such restrictions and
00010   limitations. You may obtain instructions on how to receive a copy of the
00011   License at http://www.systemc.org/. Software distributed by Contributors
00012   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
00013   ANY KIND, either express or implied. See the License for the specific
00014   language governing rights and limitations under the License.
00015 
00016  *****************************************************************************/
00017 
00018 /*****************************************************************************
00019 
00020   sc_nbdefs.h -- Top level header file for arbitrary precision signed/unsigned
00021                  arithmetic. This file defines all the constants needed.
00022 
00023   Original Author: Ali Dasdan, Synopsys, Inc.
00024   
00025  *****************************************************************************/
00026 
00027 /*****************************************************************************
00028 
00029   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00030   changes you are making here.
00031 
00032       Name, Affiliation, Date:
00033   Description of Modification:
00034 
00035  *****************************************************************************/
00036 
00037 #ifndef SC_NBDEFS_H
00038 #define SC_NBDEFS_H
00039 
00040 
00041 #include "sysc/kernel/sc_cmnhdr.h"
00042 
00043 #include <climits>
00044 
00045 #include "sysc/utils/sc_iostream.h"
00046 #include "sysc/kernel/sc_constants.h"   // For SC_MAX_NBITS
00047 #include "sysc/utils/sc_string.h"      // For sc_numrep
00048 
00049 
00050 #if defined( __SUNPRO_CC ) || defined( _MSC_VER ) || 1
00051 #define SC_DT_MIXED_COMMA_OPERATORS
00052 #endif
00053 
00054 
00055 namespace sc_dt
00056 {
00057 
00058 // Sign of a number:
00059 #define SC_NEG       -1     // Negative number
00060 #define SC_ZERO      0      // Zero
00061 #define SC_POS       1      // Positive number
00062 #define SC_NOSIGN    2      // Uninitialized sc_signed number
00063 
00064 typedef unsigned char uchar;
00065 
00066 // A small_type number is at least a char. Defining an int is probably
00067 // better for alignment.
00068 typedef int small_type;
00069 
00070 // Attributes of a byte.
00071 #define BITS_PER_BYTE   8
00072 #define BYTE_RADIX      256
00073 #define BYTE_MASK       255
00074 
00075 // LOG2_BITS_PER_BYTE = log2(BITS_PER_BYTE), assuming that
00076 // BITS_PER_BYTE is a power of 2.
00077 #define LOG2_BITS_PER_BYTE 3
00078 
00079 // Attributes of the unsigned long. These definitions are used mainly in
00080 // the functions that are aware of the internal representation of
00081 // digits, e.g., get/set_packed_rep().
00082 #define BYTES_PER_DIGIT_TYPE  4
00083 #define BITS_PER_DIGIT_TYPE   32
00084 
00085 // Attributes of a digit, i.e., unsigned long less the overflow bits.
00086 #define BYTES_PER_DIGIT 4
00087 #define BITS_PER_DIGIT  30
00088 #define DIGIT_RADIX     (1ul << BITS_PER_DIGIT)
00089 #define DIGIT_MASK      (DIGIT_RADIX - 1)
00090 // Make sure that BYTES_PER_DIGIT = ceil(BITS_PER_DIGIT / BITS_PER_BYTE).
00091 
00092 // Similar attributes for the half of a digit. Note that
00093 // HALF_DIGIT_RADIX is equal to the square root of DIGIT_RADIX. These
00094 // definitions are used mainly in the multiplication routines.
00095 #define BITS_PER_HALF_DIGIT (BITS_PER_DIGIT / 2)
00096 #define HALF_DIGIT_RADIX    (1ul << BITS_PER_HALF_DIGIT)
00097 #define HALF_DIGIT_MASK     (HALF_DIGIT_RADIX - 1)
00098 
00099 // DIV_CEIL2(x, y) = ceil(x / y). x and y are positive numbers.
00100 #define DIV_CEIL2(x, y) (((x) - 1) / (y) + 1)
00101 
00102 // DIV_CEIL(x) = ceil(x / BITS_PER_DIGIT) = the number of digits to
00103 // store x bits. x is a positive number.
00104 #define DIV_CEIL(x) DIV_CEIL2(x, BITS_PER_DIGIT)
00105 
00106 #ifdef SC_MAX_NBITS
00107 extern const int MAX_NDIGITS;
00108 // Consider a number with x bits another with y bits. The maximum
00109 // number of bits happens when we multiply them. The result will have
00110 // (x + y) bits. Assume that x + y <= SC_MAX_NBITS. Then, DIV_CEIL(x) +
00111 // DIV_CEIL(y) <= DIV_CEIL(SC_MAX_NBITS) + 2. This is the reason for +2
00112 // above. With this change, MAX_NDIGITS must be enough to hold the
00113 // result of any operation.
00114 #endif
00115 
00116 // Support for the long long type. This type is not in the standard
00117 // but is usually supported by compilers.
00118 #ifndef WIN32
00119     typedef long long          int64;
00120     typedef unsigned long long uint64;
00121     extern const uint64        UINT64_ZERO;
00122     extern const uint64        UINT64_ONE;
00123     extern const uint64        UINT64_32ONES;
00124 #else
00125     typedef __int64            int64;
00126     typedef unsigned __int64   uint64;
00127     extern const uint64        UINT64_ZERO;
00128     extern const uint64        UINT64_ONE;
00129     extern const uint64        UINT64_32ONES;
00130 #endif
00131 
00132 
00133 // Bits per ...
00134 // will be deleted in the future. Use numeric_limits instead
00135 #define BITS_PER_CHAR    8
00136 #define BITS_PER_INT    32
00137 #define BITS_PER_LONG   32
00138 #define BITS_PER_INT64  64
00139 #define BITS_PER_UINT   32
00140 #define BITS_PER_ULONG  32
00141 #define BITS_PER_UINT64 64
00142 
00143 // Digits per ...
00144 #define DIGITS_PER_CHAR   1
00145 #define DIGITS_PER_INT    2
00146 #define DIGITS_PER_LONG   2
00147 #define DIGITS_PER_INT64  3
00148 #define DIGITS_PER_UINT   2
00149 #define DIGITS_PER_ULONG  2
00150 #define DIGITS_PER_UINT64 3
00151 
00152 // Above, BITS_PER_X is mainly used for sc_signed, and BITS_PER_UX is
00153 // mainly used for sc_unsigned.
00154 
00155 #if defined( WIN32 ) || defined( __SUNPRO_CC ) || defined( __HP_aCC )
00156 typedef unsigned long fmtflags;
00157 #else
00158 typedef ::std::ios::fmtflags fmtflags;
00159 #endif
00160 
00161 extern const small_type NB_DEFAULT_BASE ;
00162 
00163 // For sc_int code:
00164 #define LLWIDTH  BITS_PER_INT64
00165 #define INTWIDTH BITS_PER_INT
00166 
00167 #ifndef _32BIT_
00168 
00169 typedef int64 int_type;
00170 typedef uint64 uint_type;
00171 #define SC_INTWIDTH 64
00172 extern const uint64 UINT_ZERO;
00173 extern const uint64 UINT_ONE;
00174 
00175 #else
00176 
00177 typedef int int_type;
00178 typedef unsigned int uint_type;
00179 #define SC_INTWIDTH 32
00180 extern const unsigned int UINT_ZERO;
00181 extern const unsigned int UINT_ONE;
00182 
00183 #endif
00184 
00185 
00186 #if defined(_MSC_VER) && ( _MSC_VER < 1300 )
00187     // VC++6 bug
00188     ::std::ostream& operator << ( ::std::ostream&, int64 );
00189     ::std::ostream& operator << ( ::std::ostream&, uint64 );
00190 #endif
00191 
00192 } // namespace sc_dt
00193 
00194 
00195 #if defined(_MSC_VER) && ( _MSC_VER < 1300 )
00196 
00197     inline
00198     ::std::ostream&
00199     operator << ( ::std::ostream& os, sc_dt::int64 a )
00200     {
00201         sc_dt::operator << ( os, a );
00202         return os;
00203     }
00204 
00205     inline
00206     ::std::ostream&
00207     operator << ( ::std::ostream& os, sc_dt::uint64 a )
00208     {
00209         sc_dt::operator << ( os, a );
00210         return os;
00211     }
00212 
00213 #endif
00214 
00215 
00216 #endif

Generated on Wed Apr 25 13:53:27 2007 for SystemC by  doxygen 1.5.1