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-2006 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 // $Log: sc_nbdefs.h,v $
00038 // Revision 1.1.1.1  2006/12/15 20:31:36  acg
00039 // SystemC 2.2
00040 //
00041 // Revision 1.3  2006/01/13 18:49:32  acg
00042 // Added $Log command so that CVS check in comments are reproduced in the
00043 // source.
00044 //
00045 
00046 #ifndef SC_NBDEFS_H
00047 #define SC_NBDEFS_H
00048 
00049 
00050 #include "sysc/kernel/sc_cmnhdr.h"
00051 
00052 #include <climits>
00053 
00054 #include "sysc/utils/sc_iostream.h"
00055 #include "sysc/kernel/sc_constants.h"   // For SC_MAX_NBITS
00056 #include "sysc/utils/sc_string.h"      // For sc_numrep
00057 
00058 
00059 #if defined( __SUNPRO_CC ) || defined( _MSC_VER ) || 1
00060 #define SC_DT_MIXED_COMMA_OPERATORS
00061 #endif
00062 
00063 
00064 namespace sc_dt
00065 {
00066 
00067 // Sign of a number:
00068 #define SC_NEG       -1     // Negative number
00069 #define SC_ZERO      0      // Zero
00070 #define SC_POS       1      // Positive number
00071 #define SC_NOSIGN    2      // Uninitialized sc_signed number
00072 
00073 typedef unsigned char uchar;
00074 
00075 // A small_type number is at least a char. Defining an int is probably
00076 // better for alignment.
00077 typedef int small_type;
00078 
00079 // Attributes of a byte.
00080 #define BITS_PER_BYTE   8
00081 #define BYTE_RADIX      256
00082 #define BYTE_MASK       255
00083 
00084 // LOG2_BITS_PER_BYTE = log2(BITS_PER_BYTE), assuming that
00085 // BITS_PER_BYTE is a power of 2.
00086 #define LOG2_BITS_PER_BYTE 3
00087 
00088 // Attributes of the unsigned long. These definitions are used mainly in
00089 // the functions that are aware of the internal representation of
00090 // digits, e.g., get/set_packed_rep().
00091 #define BYTES_PER_DIGIT_TYPE  4
00092 #define BITS_PER_DIGIT_TYPE   32
00093 
00094 // Attributes of a digit, i.e., unsigned long less the overflow bits.
00095 #define BYTES_PER_DIGIT 4
00096 #define BITS_PER_DIGIT  30
00097 #define DIGIT_RADIX     (1ul << BITS_PER_DIGIT)
00098 #define DIGIT_MASK      (DIGIT_RADIX - 1)
00099 // Make sure that BYTES_PER_DIGIT = ceil(BITS_PER_DIGIT / BITS_PER_BYTE).
00100 
00101 // Similar attributes for the half of a digit. Note that
00102 // HALF_DIGIT_RADIX is equal to the square root of DIGIT_RADIX. These
00103 // definitions are used mainly in the multiplication routines.
00104 #define BITS_PER_HALF_DIGIT (BITS_PER_DIGIT / 2)
00105 #define HALF_DIGIT_RADIX    (1ul << BITS_PER_HALF_DIGIT)
00106 #define HALF_DIGIT_MASK     (HALF_DIGIT_RADIX - 1)
00107 
00108 // DIV_CEIL2(x, y) = ceil(x / y). x and y are positive numbers.
00109 #define DIV_CEIL2(x, y) (((x) - 1) / (y) + 1)
00110 
00111 // DIV_CEIL(x) = ceil(x / BITS_PER_DIGIT) = the number of digits to
00112 // store x bits. x is a positive number.
00113 #define DIV_CEIL(x) DIV_CEIL2(x, BITS_PER_DIGIT)
00114 
00115 #ifdef SC_MAX_NBITS
00116 extern const int MAX_NDIGITS;
00117 // Consider a number with x bits another with y bits. The maximum
00118 // number of bits happens when we multiply them. The result will have
00119 // (x + y) bits. Assume that x + y <= SC_MAX_NBITS. Then, DIV_CEIL(x) +
00120 // DIV_CEIL(y) <= DIV_CEIL(SC_MAX_NBITS) + 2. This is the reason for +2
00121 // above. With this change, MAX_NDIGITS must be enough to hold the
00122 // result of any operation.
00123 #endif
00124 
00125 // Support for "digit" vectors used to hold the values of sc_signed,
00126 // sc_unsigned, sc_bv_base,  and sc_lv_base data types. This type is also used 
00127 // in the concatenation support. An sc_digit is currently an unsigned 32-bit 
00128 // quantity. The typedef used is an unsigned int, rather than an unsigned long,
00129 // since the unsigned long data type varies in size between 32-bit and 64-bit 
00130 // machines.
00131 
00132 typedef unsigned int sc_digit;  // 32-bit unsigned integer
00133 
00134 // Support for the long long type. This type is not in the standard
00135 // but is usually supported by compilers.
00136 #ifndef WIN32
00137     typedef long long          int64;
00138     typedef unsigned long long uint64;
00139     extern const uint64        UINT64_ZERO;
00140     extern const uint64        UINT64_ONE;
00141     extern const uint64        UINT64_32ONES;
00142 #else
00143     typedef __int64            int64;
00144     typedef unsigned __int64   uint64;
00145     extern const uint64        UINT64_ZERO;
00146     extern const uint64        UINT64_ONE;
00147     extern const uint64        UINT64_32ONES;
00148 #endif
00149 
00150 
00151 // Bits per ...
00152 // will be deleted in the future. Use numeric_limits instead
00153 #define BITS_PER_CHAR    8
00154 #define BITS_PER_INT    (sizeof(int) * BITS_PER_CHAR)
00155 #define BITS_PER_LONG   (sizeof(long) * BITS_PER_CHAR)
00156 #define BITS_PER_INT64  (sizeof(long long) * BITS_PER_CHAR)
00157 #define BITS_PER_UINT   (sizeof(unsigned int) * BITS_PER_CHAR)
00158 #define BITS_PER_ULONG  (sizeof(unsigned long) * BITS_PER_CHAR)
00159 #define BITS_PER_UINT64 (sizeof(unsigned long long) * BITS_PER_CHAR)
00160 
00161 // Digits per ...
00162 #define DIGITS_PER_CHAR   1
00163 #define DIGITS_PER_INT    ((BITS_PER_INT+29)/30)
00164 #define DIGITS_PER_LONG   ((BITS_PER_LONG+29)/30)
00165 #define DIGITS_PER_INT64  ((BITS_PER_INT64+29)/30)
00166 #define DIGITS_PER_UINT   ((BITS_PER_UINT+29)/30)
00167 #define DIGITS_PER_ULONG  ((BITS_PER_ULONG+29)/30)
00168 #define DIGITS_PER_UINT64 ((BITS_PER_UINT64+29)/30)
00169 
00170 // Above, BITS_PER_X is mainly used for sc_signed, and BITS_PER_UX is
00171 // mainly used for sc_unsigned.
00172 
00173 #if defined( WIN32 ) || defined( __SUNPRO_CC ) || defined( __HP_aCC )
00174 typedef unsigned long fmtflags;
00175 #else
00176 typedef ::std::ios::fmtflags fmtflags;
00177 #endif
00178 
00179 extern const small_type NB_DEFAULT_BASE ;
00180 
00181 // For sc_int code:
00182 #define LLWIDTH  BITS_PER_INT64
00183 #define INTWIDTH BITS_PER_INT
00184 
00185 #ifndef _32BIT_
00186 
00187 typedef int64 int_type;
00188 typedef uint64 uint_type;
00189 #define SC_INTWIDTH 64
00190 extern const uint64 UINT_ZERO;
00191 extern const uint64 UINT_ONE;
00192 
00193 #else
00194 
00195 typedef int int_type;
00196 typedef unsigned int uint_type;
00197 #define SC_INTWIDTH 32
00198 extern const unsigned int UINT_ZERO;
00199 extern const unsigned int UINT_ONE;
00200 
00201 #endif
00202 
00203 
00204 #if defined(_MSC_VER) && ( _MSC_VER < 1300 )
00205     // VC++6 bug
00206     ::std::ostream& operator << ( ::std::ostream&, int64 );
00207     ::std::ostream& operator << ( ::std::ostream&, uint64 );
00208 #endif
00209 
00210 } // namespace sc_dt
00211 
00212 
00213 #if defined(_MSC_VER) && ( _MSC_VER < 1300 )
00214 
00215     inline
00216     ::std::ostream&
00217     operator << ( ::std::ostream& os, sc_dt::int64 a )
00218     {
00219     sc_dt::operator << ( os, a );
00220     return os;
00221     }
00222 
00223     inline
00224     ::std::ostream&
00225     operator << ( ::std::ostream& os, sc_dt::uint64 a )
00226     {
00227     sc_dt::operator << ( os, a );
00228     return os;
00229     }
00230 
00231 #endif
00232 
00233 
00234 #endif

Generated on Wed Jan 21 15:32:08 2009 for SystemC by  doxygen 1.5.5