112027Sjungma@eit.uni-kl.de/***************************************************************************** 212027Sjungma@eit.uni-kl.de 312027Sjungma@eit.uni-kl.de Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 412027Sjungma@eit.uni-kl.de more contributor license agreements. See the NOTICE file distributed 512027Sjungma@eit.uni-kl.de with this work for additional information regarding copyright ownership. 612027Sjungma@eit.uni-kl.de Accellera licenses this file to you under the Apache License, Version 2.0 712027Sjungma@eit.uni-kl.de (the "License"); you may not use this file except in compliance with the 812027Sjungma@eit.uni-kl.de License. You may obtain a copy of the License at 912027Sjungma@eit.uni-kl.de 1012027Sjungma@eit.uni-kl.de http://www.apache.org/licenses/LICENSE-2.0 1112027Sjungma@eit.uni-kl.de 1212027Sjungma@eit.uni-kl.de Unless required by applicable law or agreed to in writing, software 1312027Sjungma@eit.uni-kl.de distributed under the License is distributed on an "AS IS" BASIS, 1412027Sjungma@eit.uni-kl.de WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 1512027Sjungma@eit.uni-kl.de implied. See the License for the specific language governing 1612027Sjungma@eit.uni-kl.de permissions and limitations under the License. 1712027Sjungma@eit.uni-kl.de 1812027Sjungma@eit.uni-kl.de *****************************************************************************/ 1912027Sjungma@eit.uni-kl.de 2012027Sjungma@eit.uni-kl.de/***************************************************************************** 2112027Sjungma@eit.uni-kl.de 2212027Sjungma@eit.uni-kl.de sc_uint.h -- A sc_uint is an unsigned integer whose length is less than the 2312027Sjungma@eit.uni-kl.de machine's native integer length. We provide two implementations 2412027Sjungma@eit.uni-kl.de (i) sc_uint with length between 1 - 64, and (ii) sc_uint with 2512027Sjungma@eit.uni-kl.de length between 1 - 32. Implementation (i) is the default 2612027Sjungma@eit.uni-kl.de implementation, while implementation (ii) can be used only if 2712027Sjungma@eit.uni-kl.de compiled with -D_32BIT_. Unlike arbitrary precision, arithmetic 2812027Sjungma@eit.uni-kl.de and bitwise operations are performed using the native types 2912027Sjungma@eit.uni-kl.de (hence capped at 32/64 bits). The sc_uint integer is useful 3012027Sjungma@eit.uni-kl.de when the user does not need arbitrary precision and the 3112027Sjungma@eit.uni-kl.de performance is superior to sc_bigint/sc_biguint. 3212027Sjungma@eit.uni-kl.de 3312027Sjungma@eit.uni-kl.de Original Author: Amit Rao, Synopsys, Inc. 3412027Sjungma@eit.uni-kl.de 3512027Sjungma@eit.uni-kl.de *****************************************************************************/ 3612027Sjungma@eit.uni-kl.de 3712027Sjungma@eit.uni-kl.de/***************************************************************************** 3812027Sjungma@eit.uni-kl.de 3912027Sjungma@eit.uni-kl.de MODIFICATION LOG - modifiers, enter your name, affiliation, date and 4012027Sjungma@eit.uni-kl.de changes you are making here. 4112027Sjungma@eit.uni-kl.de 4212027Sjungma@eit.uni-kl.de Name, Affiliation, Date: Ali Dasdan, Synopsys, Inc. 4312027Sjungma@eit.uni-kl.de Description of Modification: - Resolved ambiguity with sc_(un)signed. 4412027Sjungma@eit.uni-kl.de - Merged the code for 64- and 32-bit versions 4512027Sjungma@eit.uni-kl.de via the constants in sc_nbdefs.h. 4612027Sjungma@eit.uni-kl.de - Eliminated redundant file inclusions. 4712027Sjungma@eit.uni-kl.de 4812027Sjungma@eit.uni-kl.de Name, Affiliation, Date: 4912027Sjungma@eit.uni-kl.de Description of Modification: 5012027Sjungma@eit.uni-kl.de 5112027Sjungma@eit.uni-kl.de *****************************************************************************/ 5212027Sjungma@eit.uni-kl.de 5312027Sjungma@eit.uni-kl.de// $Log: sc_uint.h,v $ 5412027Sjungma@eit.uni-kl.de// Revision 1.2 2011/02/18 20:19:15 acg 5512027Sjungma@eit.uni-kl.de// Andy Goodrich: updating Copyright notice. 5612027Sjungma@eit.uni-kl.de// 5712027Sjungma@eit.uni-kl.de// Revision 1.1.1.1 2006/12/15 20:20:05 acg 5812027Sjungma@eit.uni-kl.de// SystemC 2.3 5912027Sjungma@eit.uni-kl.de// 6012027Sjungma@eit.uni-kl.de// Revision 1.3 2006/01/13 18:49:32 acg 6112027Sjungma@eit.uni-kl.de// Added $Log command so that CVS check in comments are reproduced in the 6212027Sjungma@eit.uni-kl.de// source. 6312027Sjungma@eit.uni-kl.de// 6412027Sjungma@eit.uni-kl.de 6512027Sjungma@eit.uni-kl.de#ifndef SC_UINT_H 6612027Sjungma@eit.uni-kl.de#define SC_UINT_H 6712027Sjungma@eit.uni-kl.de 6812027Sjungma@eit.uni-kl.de 6912027Sjungma@eit.uni-kl.de#include "sysc/datatypes/int/sc_uint_base.h" 7012027Sjungma@eit.uni-kl.de 7112027Sjungma@eit.uni-kl.de 7212027Sjungma@eit.uni-kl.denamespace sc_dt 7312027Sjungma@eit.uni-kl.de{ 7412027Sjungma@eit.uni-kl.de 7512027Sjungma@eit.uni-kl.de// classes defined in this module 7612027Sjungma@eit.uni-kl.detemplate <int W> class sc_uint; 7712027Sjungma@eit.uni-kl.de 7812027Sjungma@eit.uni-kl.de 7912027Sjungma@eit.uni-kl.de// ---------------------------------------------------------------------------- 8012027Sjungma@eit.uni-kl.de// CLASS TEMPLATE : sc_uint<W> 8112027Sjungma@eit.uni-kl.de// 8212027Sjungma@eit.uni-kl.de// Template class sc_uint<W> is the interface that the user sees. It 8312027Sjungma@eit.uni-kl.de// is derived from sc_uint_base and most of its methods are just 8412027Sjungma@eit.uni-kl.de// wrappers that call the corresponding method in the parent 8512027Sjungma@eit.uni-kl.de// class. Note that the length of sc_uint datatype is specified as a 8612027Sjungma@eit.uni-kl.de// template parameter. 8712027Sjungma@eit.uni-kl.de// ---------------------------------------------------------------------------- 8812027Sjungma@eit.uni-kl.de 8912027Sjungma@eit.uni-kl.detemplate <int W> 9012027Sjungma@eit.uni-kl.declass sc_uint 9112027Sjungma@eit.uni-kl.de : public sc_uint_base 9212027Sjungma@eit.uni-kl.de{ 9312027Sjungma@eit.uni-kl.depublic: 9412027Sjungma@eit.uni-kl.de 9512027Sjungma@eit.uni-kl.de // constructors 9612027Sjungma@eit.uni-kl.de 9712027Sjungma@eit.uni-kl.de sc_uint() 9812027Sjungma@eit.uni-kl.de : sc_uint_base( W ) 9912027Sjungma@eit.uni-kl.de {} 10012027Sjungma@eit.uni-kl.de 10112027Sjungma@eit.uni-kl.de sc_uint( uint_type v ) 10212027Sjungma@eit.uni-kl.de : sc_uint_base( v, W ) 10312027Sjungma@eit.uni-kl.de {} 10412027Sjungma@eit.uni-kl.de 10512027Sjungma@eit.uni-kl.de sc_uint( const sc_uint<W>& a ) 10612027Sjungma@eit.uni-kl.de : sc_uint_base( a ) 10712027Sjungma@eit.uni-kl.de {} 10812027Sjungma@eit.uni-kl.de 10912027Sjungma@eit.uni-kl.de sc_uint( const sc_uint_base& a ) 11012027Sjungma@eit.uni-kl.de : sc_uint_base( W ) 11112027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); } 11212027Sjungma@eit.uni-kl.de 11312027Sjungma@eit.uni-kl.de sc_uint( const sc_uint_subref_r& a ) 11412027Sjungma@eit.uni-kl.de : sc_uint_base( W ) 11512027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); } 11612027Sjungma@eit.uni-kl.de 11712027Sjungma@eit.uni-kl.de template< class T > 11812027Sjungma@eit.uni-kl.de sc_uint( const sc_generic_base<T>& a ) 11912027Sjungma@eit.uni-kl.de : sc_uint_base( W ) 12012027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); } 12112027Sjungma@eit.uni-kl.de 12212027Sjungma@eit.uni-kl.de sc_uint( const sc_signed& a ) 12312027Sjungma@eit.uni-kl.de : sc_uint_base( W ) 12412027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); } 12512027Sjungma@eit.uni-kl.de 12612027Sjungma@eit.uni-kl.de sc_uint( const sc_unsigned& a ) 12712027Sjungma@eit.uni-kl.de : sc_uint_base( W ) 12812027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); } 12912027Sjungma@eit.uni-kl.de 13012027Sjungma@eit.uni-kl.de#ifdef SC_INCLUDE_FX 13112027Sjungma@eit.uni-kl.de 13212027Sjungma@eit.uni-kl.de explicit sc_uint( const sc_fxval& a ) 13312027Sjungma@eit.uni-kl.de : sc_uint_base( W ) 13412027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); } 13512027Sjungma@eit.uni-kl.de 13612027Sjungma@eit.uni-kl.de explicit sc_uint( const sc_fxval_fast& a ) 13712027Sjungma@eit.uni-kl.de : sc_uint_base( W ) 13812027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); } 13912027Sjungma@eit.uni-kl.de 14012027Sjungma@eit.uni-kl.de explicit sc_uint( const sc_fxnum& a ) 14112027Sjungma@eit.uni-kl.de : sc_uint_base( W ) 14212027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); } 14312027Sjungma@eit.uni-kl.de 14412027Sjungma@eit.uni-kl.de explicit sc_uint( const sc_fxnum_fast& a ) 14512027Sjungma@eit.uni-kl.de : sc_uint_base( W ) 14612027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); } 14712027Sjungma@eit.uni-kl.de 14812027Sjungma@eit.uni-kl.de#endif 14912027Sjungma@eit.uni-kl.de 15012027Sjungma@eit.uni-kl.de sc_uint( const sc_bv_base& a ) 15112027Sjungma@eit.uni-kl.de : sc_uint_base( W ) 15212027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); } 15312027Sjungma@eit.uni-kl.de 15412027Sjungma@eit.uni-kl.de sc_uint( const sc_lv_base& a ) 15512027Sjungma@eit.uni-kl.de : sc_uint_base( W ) 15612027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); } 15712027Sjungma@eit.uni-kl.de 15812027Sjungma@eit.uni-kl.de sc_uint( const char* a ) 15912027Sjungma@eit.uni-kl.de : sc_uint_base( W ) 16012027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); } 16112027Sjungma@eit.uni-kl.de 16212027Sjungma@eit.uni-kl.de sc_uint( unsigned long a ) 16312027Sjungma@eit.uni-kl.de : sc_uint_base( W ) 16412027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); } 16512027Sjungma@eit.uni-kl.de 16612027Sjungma@eit.uni-kl.de sc_uint( long a ) 16712027Sjungma@eit.uni-kl.de : sc_uint_base( W ) 16812027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); } 16912027Sjungma@eit.uni-kl.de 17012027Sjungma@eit.uni-kl.de sc_uint( unsigned int a ) 17112027Sjungma@eit.uni-kl.de : sc_uint_base( W ) 17212027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); } 17312027Sjungma@eit.uni-kl.de 17412027Sjungma@eit.uni-kl.de sc_uint( int a ) 17512027Sjungma@eit.uni-kl.de : sc_uint_base( W ) 17612027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); } 17712027Sjungma@eit.uni-kl.de 17812027Sjungma@eit.uni-kl.de sc_uint( int64 a ) 17912027Sjungma@eit.uni-kl.de : sc_uint_base( W ) 18012027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); } 18112027Sjungma@eit.uni-kl.de 18212027Sjungma@eit.uni-kl.de sc_uint( double a ) 18312027Sjungma@eit.uni-kl.de : sc_uint_base( W ) 18412027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); } 18512027Sjungma@eit.uni-kl.de 18612027Sjungma@eit.uni-kl.de 18712027Sjungma@eit.uni-kl.de // assignment operators 18812027Sjungma@eit.uni-kl.de 18912027Sjungma@eit.uni-kl.de sc_uint<W>& operator = ( uint_type v ) 19012027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( v ); return *this; } 19112027Sjungma@eit.uni-kl.de 19212027Sjungma@eit.uni-kl.de sc_uint<W>& operator = ( const sc_uint_base& a ) 19312027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); return *this; } 19412027Sjungma@eit.uni-kl.de 19512027Sjungma@eit.uni-kl.de sc_uint<W>& operator = ( const sc_uint_subref_r& a ) 19612027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); return *this; } 19712027Sjungma@eit.uni-kl.de 19812027Sjungma@eit.uni-kl.de sc_uint<W>& operator = ( const sc_uint<W>& a ) 19912027Sjungma@eit.uni-kl.de { m_val = a.m_val; return *this; } 20012027Sjungma@eit.uni-kl.de 20112027Sjungma@eit.uni-kl.de template<class T> 20212027Sjungma@eit.uni-kl.de sc_uint<W>& operator = ( const sc_generic_base<T>& a ) 20312027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); return *this; } 20412027Sjungma@eit.uni-kl.de 20512027Sjungma@eit.uni-kl.de sc_uint<W>& operator = ( const sc_signed& a ) 20612027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); return *this; } 20712027Sjungma@eit.uni-kl.de 20812027Sjungma@eit.uni-kl.de sc_uint<W>& operator = ( const sc_unsigned& a ) 20912027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); return *this; } 21012027Sjungma@eit.uni-kl.de 21112027Sjungma@eit.uni-kl.de#ifdef SC_INCLUDE_FX 21212027Sjungma@eit.uni-kl.de 21312027Sjungma@eit.uni-kl.de sc_uint<W>& operator = ( const sc_fxval& a ) 21412027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); return *this; } 21512027Sjungma@eit.uni-kl.de 21612027Sjungma@eit.uni-kl.de sc_uint<W>& operator = ( const sc_fxval_fast& a ) 21712027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); return *this; } 21812027Sjungma@eit.uni-kl.de 21912027Sjungma@eit.uni-kl.de sc_uint<W>& operator = ( const sc_fxnum& a ) 22012027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); return *this; } 22112027Sjungma@eit.uni-kl.de 22212027Sjungma@eit.uni-kl.de sc_uint<W>& operator = ( const sc_fxnum_fast& a ) 22312027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); return *this; } 22412027Sjungma@eit.uni-kl.de 22512027Sjungma@eit.uni-kl.de#endif 22612027Sjungma@eit.uni-kl.de 22712027Sjungma@eit.uni-kl.de sc_uint<W>& operator = ( const sc_bv_base& a ) 22812027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); return *this; } 22912027Sjungma@eit.uni-kl.de 23012027Sjungma@eit.uni-kl.de sc_uint<W>& operator = ( const sc_lv_base& a ) 23112027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); return *this; } 23212027Sjungma@eit.uni-kl.de 23312027Sjungma@eit.uni-kl.de sc_uint<W>& operator = ( const char* a ) 23412027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); return *this; } 23512027Sjungma@eit.uni-kl.de 23612027Sjungma@eit.uni-kl.de sc_uint<W>& operator = ( unsigned long a ) 23712027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); return *this; } 23812027Sjungma@eit.uni-kl.de 23912027Sjungma@eit.uni-kl.de sc_uint<W>& operator = ( long a ) 24012027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); return *this; } 24112027Sjungma@eit.uni-kl.de 24212027Sjungma@eit.uni-kl.de sc_uint<W>& operator = ( unsigned int a ) 24312027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); return *this; } 24412027Sjungma@eit.uni-kl.de 24512027Sjungma@eit.uni-kl.de sc_uint<W>& operator = ( int a ) 24612027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); return *this; } 24712027Sjungma@eit.uni-kl.de 24812027Sjungma@eit.uni-kl.de sc_uint<W>& operator = ( int64 a ) 24912027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); return *this; } 25012027Sjungma@eit.uni-kl.de 25112027Sjungma@eit.uni-kl.de sc_uint<W>& operator = ( double a ) 25212027Sjungma@eit.uni-kl.de { sc_uint_base::operator = ( a ); return *this; } 25312027Sjungma@eit.uni-kl.de 25412027Sjungma@eit.uni-kl.de 25512027Sjungma@eit.uni-kl.de // arithmetic assignment operators 25612027Sjungma@eit.uni-kl.de 25712027Sjungma@eit.uni-kl.de sc_uint<W>& operator += ( uint_type v ) 25812027Sjungma@eit.uni-kl.de { sc_uint_base::operator += ( v ); return *this; } 25912027Sjungma@eit.uni-kl.de 26012027Sjungma@eit.uni-kl.de sc_uint<W>& operator -= ( uint_type v ) 26112027Sjungma@eit.uni-kl.de { sc_uint_base::operator -= ( v ); return *this; } 26212027Sjungma@eit.uni-kl.de 26312027Sjungma@eit.uni-kl.de sc_uint<W>& operator *= ( uint_type v ) 26412027Sjungma@eit.uni-kl.de { sc_uint_base::operator *= ( v ); return *this; } 26512027Sjungma@eit.uni-kl.de 26612027Sjungma@eit.uni-kl.de sc_uint<W>& operator /= ( uint_type v ) 26712027Sjungma@eit.uni-kl.de { sc_uint_base::operator /= ( v ); return *this; } 26812027Sjungma@eit.uni-kl.de 26912027Sjungma@eit.uni-kl.de sc_uint<W>& operator %= ( uint_type v ) 27012027Sjungma@eit.uni-kl.de { sc_uint_base::operator %= ( v ); return *this; } 27112027Sjungma@eit.uni-kl.de 27212027Sjungma@eit.uni-kl.de 27312027Sjungma@eit.uni-kl.de // bitwise assignment operators 27412027Sjungma@eit.uni-kl.de 27512027Sjungma@eit.uni-kl.de sc_uint<W>& operator &= ( uint_type v ) 27612027Sjungma@eit.uni-kl.de { sc_uint_base::operator &= ( v ); return *this; } 27712027Sjungma@eit.uni-kl.de 27812027Sjungma@eit.uni-kl.de sc_uint<W>& operator |= ( uint_type v ) 27912027Sjungma@eit.uni-kl.de { sc_uint_base::operator |= ( v ); return *this; } 28012027Sjungma@eit.uni-kl.de 28112027Sjungma@eit.uni-kl.de sc_uint<W>& operator ^= ( uint_type v ) 28212027Sjungma@eit.uni-kl.de { sc_uint_base::operator ^= ( v ); return *this; } 28312027Sjungma@eit.uni-kl.de 28412027Sjungma@eit.uni-kl.de 28512027Sjungma@eit.uni-kl.de sc_uint<W>& operator <<= ( uint_type v ) 28612027Sjungma@eit.uni-kl.de { sc_uint_base::operator <<= ( v ); return *this; } 28712027Sjungma@eit.uni-kl.de 28812027Sjungma@eit.uni-kl.de sc_uint<W>& operator >>= ( uint_type v ) 28912027Sjungma@eit.uni-kl.de { sc_uint_base::operator >>= ( v ); return *this; } 29012027Sjungma@eit.uni-kl.de 29112027Sjungma@eit.uni-kl.de 29212027Sjungma@eit.uni-kl.de // prefix and postfix increment and decrement operators 29312027Sjungma@eit.uni-kl.de 29412027Sjungma@eit.uni-kl.de sc_uint<W>& operator ++ () // prefix 29512027Sjungma@eit.uni-kl.de { sc_uint_base::operator ++ (); return *this; } 29612027Sjungma@eit.uni-kl.de 29712027Sjungma@eit.uni-kl.de const sc_uint<W> operator ++ ( int ) // postfix 29812027Sjungma@eit.uni-kl.de { return sc_uint<W>( sc_uint_base::operator ++ ( 0 ) ); } 29912027Sjungma@eit.uni-kl.de 30012027Sjungma@eit.uni-kl.de sc_uint<W>& operator -- () // prefix 30112027Sjungma@eit.uni-kl.de { sc_uint_base::operator -- (); return *this; } 30212027Sjungma@eit.uni-kl.de 30312027Sjungma@eit.uni-kl.de const sc_uint<W> operator -- ( int ) // postfix 30412027Sjungma@eit.uni-kl.de { return sc_uint<W>( sc_uint_base::operator -- ( 0 ) ); } 30512027Sjungma@eit.uni-kl.de}; 30612027Sjungma@eit.uni-kl.de 30712027Sjungma@eit.uni-kl.de} // namespace sc_dt 30812027Sjungma@eit.uni-kl.de 30912027Sjungma@eit.uni-kl.de 31012027Sjungma@eit.uni-kl.de#endif 31112027Sjungma@eit.uni-kl.de 31212027Sjungma@eit.uni-kl.de// Taf! 313