sc_uint.hh revision 12853
112853Sgabeblack@google.com/***************************************************************************** 212853Sgabeblack@google.com 312853Sgabeblack@google.com Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 412853Sgabeblack@google.com more contributor license agreements. See the NOTICE file distributed 512853Sgabeblack@google.com with this work for additional information regarding copyright ownership. 612853Sgabeblack@google.com Accellera licenses this file to you under the Apache License, Version 2.0 712853Sgabeblack@google.com (the "License"); you may not use this file except in compliance with the 812853Sgabeblack@google.com License. You may obtain a copy of the License at 912853Sgabeblack@google.com 1012853Sgabeblack@google.com http://www.apache.org/licenses/LICENSE-2.0 1112853Sgabeblack@google.com 1212853Sgabeblack@google.com Unless required by applicable law or agreed to in writing, software 1312853Sgabeblack@google.com distributed under the License is distributed on an "AS IS" BASIS, 1412853Sgabeblack@google.com WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 1512853Sgabeblack@google.com implied. See the License for the specific language governing 1612853Sgabeblack@google.com permissions and limitations under the License. 1712853Sgabeblack@google.com 1812853Sgabeblack@google.com *****************************************************************************/ 1912853Sgabeblack@google.com 2012853Sgabeblack@google.com/***************************************************************************** 2112853Sgabeblack@google.com 2212853Sgabeblack@google.com sc_uint.h -- An unsigned integer whose length is less than 64 bits. 2312853Sgabeblack@google.com 2412853Sgabeblack@google.com Unlike arbitrary precision, arithmetic and bitwise operations 2512853Sgabeblack@google.com are performed using the native types (hence capped at 64 bits). 2612853Sgabeblack@google.com The sc_uint integer is useful when the user does not need 2712853Sgabeblack@google.com arbitrary precision and the performance is superior to 2812853Sgabeblack@google.com sc_bigint/sc_biguint. 2912853Sgabeblack@google.com 3012853Sgabeblack@google.com Original Author: Amit Rao, Synopsys, Inc. 3112853Sgabeblack@google.com 3212853Sgabeblack@google.com *****************************************************************************/ 3312853Sgabeblack@google.com 3412853Sgabeblack@google.com/***************************************************************************** 3512853Sgabeblack@google.com 3612853Sgabeblack@google.com MODIFICATION LOG - modifiers, enter your name, affiliation, date and 3712853Sgabeblack@google.com changes you are making here. 3812853Sgabeblack@google.com 3912853Sgabeblack@google.com Name, Affiliation, Date: Ali Dasdan, Synopsys, Inc. 4012853Sgabeblack@google.com Description of Modification: - Resolved ambiguity with sc_(un)signed. 4112853Sgabeblack@google.com - Merged the code for 64- and 32-bit versions 4212853Sgabeblack@google.com via the constants in sc_nbdefs.h. 4312853Sgabeblack@google.com - Eliminated redundant file inclusions. 4412853Sgabeblack@google.com 4512853Sgabeblack@google.com Name, Affiliation, Date: 4612853Sgabeblack@google.com Description of Modification: 4712853Sgabeblack@google.com 4812853Sgabeblack@google.com *****************************************************************************/ 4912853Sgabeblack@google.com 5012853Sgabeblack@google.com// $Log: sc_uint.h,v $ 5112853Sgabeblack@google.com// Revision 1.2 2011/02/18 20:19:15 acg 5212853Sgabeblack@google.com// Andy Goodrich: updating Copyright notice. 5312853Sgabeblack@google.com// 5412853Sgabeblack@google.com// Revision 1.1.1.1 2006/12/15 20:20:05 acg 5512853Sgabeblack@google.com// SystemC 2.3 5612853Sgabeblack@google.com// 5712853Sgabeblack@google.com// Revision 1.3 2006/01/13 18:49:32 acg 5812853Sgabeblack@google.com// Added $Log command so that CVS check in comments are reproduced in the 5912853Sgabeblack@google.com// source. 6012853Sgabeblack@google.com// 6112853Sgabeblack@google.com 6212853Sgabeblack@google.com#ifndef __SYSTEMC_EXT_DT_INT_SC_UINT_HH__ 6312853Sgabeblack@google.com#define __SYSTEMC_EXT_DT_INT_SC_UINT_HH__ 6412853Sgabeblack@google.com 6512853Sgabeblack@google.com#include "sc_uint_base.hh" 6612853Sgabeblack@google.com 6712853Sgabeblack@google.comnamespace sc_dt 6812853Sgabeblack@google.com{ 6912853Sgabeblack@google.com 7012853Sgabeblack@google.com// classes defined in this module 7112853Sgabeblack@google.comtemplate <int W> 7212853Sgabeblack@google.comclass sc_uint; 7312853Sgabeblack@google.com 7412853Sgabeblack@google.com 7512853Sgabeblack@google.com// ---------------------------------------------------------------------------- 7612853Sgabeblack@google.com// CLASS TEMPLATE : sc_uint<W> 7712853Sgabeblack@google.com// 7812853Sgabeblack@google.com// Template class sc_uint<W> is the interface that the user sees. It 7912853Sgabeblack@google.com// is derived from sc_uint_base and most of its methods are just 8012853Sgabeblack@google.com// wrappers that call the corresponding method in the parent 8112853Sgabeblack@google.com// class. Note that the length of sc_uint datatype is specified as a 8212853Sgabeblack@google.com// template parameter. 8312853Sgabeblack@google.com// ---------------------------------------------------------------------------- 8412853Sgabeblack@google.com 8512853Sgabeblack@google.comtemplate <int W> 8612853Sgabeblack@google.comclass sc_uint : public sc_uint_base 8712853Sgabeblack@google.com{ 8812853Sgabeblack@google.com public: 8912853Sgabeblack@google.com // constructors 9012853Sgabeblack@google.com sc_uint() : sc_uint_base(W) {} 9112853Sgabeblack@google.com sc_uint(uint_type v) : sc_uint_base(v, W) {} 9212853Sgabeblack@google.com sc_uint(const sc_uint<W> &a) : sc_uint_base(a) {} 9312853Sgabeblack@google.com sc_uint(const sc_uint_base &a) : sc_uint_base(W) 9412853Sgabeblack@google.com { 9512853Sgabeblack@google.com sc_uint_base::operator = (a); 9612853Sgabeblack@google.com } 9712853Sgabeblack@google.com sc_uint(const sc_uint_subref_r &a) : sc_uint_base(W) 9812853Sgabeblack@google.com { 9912853Sgabeblack@google.com sc_uint_base::operator = (a); 10012853Sgabeblack@google.com } 10112853Sgabeblack@google.com template< class T > 10212853Sgabeblack@google.com sc_uint(const sc_generic_base<T> &a) : sc_uint_base(W) 10312853Sgabeblack@google.com { 10412853Sgabeblack@google.com sc_uint_base::operator = (a); 10512853Sgabeblack@google.com } 10612853Sgabeblack@google.com sc_uint(const sc_signed &a) : sc_uint_base(W) 10712853Sgabeblack@google.com { 10812853Sgabeblack@google.com sc_uint_base::operator = (a); 10912853Sgabeblack@google.com } 11012853Sgabeblack@google.com sc_uint(const sc_unsigned &a) : sc_uint_base(W) 11112853Sgabeblack@google.com { 11212853Sgabeblack@google.com sc_uint_base::operator = (a); 11312853Sgabeblack@google.com } 11412853Sgabeblack@google.com explicit sc_uint(const sc_fxval &a) : sc_uint_base(W) 11512853Sgabeblack@google.com { 11612853Sgabeblack@google.com sc_uint_base::operator = (a); 11712853Sgabeblack@google.com } 11812853Sgabeblack@google.com explicit sc_uint(const sc_fxval_fast &a) : sc_uint_base(W) 11912853Sgabeblack@google.com { 12012853Sgabeblack@google.com sc_uint_base::operator = (a); 12112853Sgabeblack@google.com } 12212853Sgabeblack@google.com explicit sc_uint(const sc_fxnum &a) : sc_uint_base(W) 12312853Sgabeblack@google.com { 12412853Sgabeblack@google.com sc_uint_base::operator = (a); 12512853Sgabeblack@google.com } 12612853Sgabeblack@google.com explicit sc_uint(const sc_fxnum_fast &a) : sc_uint_base(W) 12712853Sgabeblack@google.com { 12812853Sgabeblack@google.com sc_uint_base::operator = (a); 12912853Sgabeblack@google.com } 13012853Sgabeblack@google.com sc_uint(const sc_bv_base &a) : sc_uint_base(W) 13112853Sgabeblack@google.com { 13212853Sgabeblack@google.com sc_uint_base::operator = (a); 13312853Sgabeblack@google.com } 13412853Sgabeblack@google.com sc_uint(const sc_lv_base &a) : sc_uint_base(W) 13512853Sgabeblack@google.com { 13612853Sgabeblack@google.com sc_uint_base::operator = (a); 13712853Sgabeblack@google.com } 13812853Sgabeblack@google.com sc_uint(const char* a) : sc_uint_base(W) 13912853Sgabeblack@google.com { 14012853Sgabeblack@google.com sc_uint_base::operator = (a); 14112853Sgabeblack@google.com } 14212853Sgabeblack@google.com sc_uint(unsigned long a) : sc_uint_base(W) 14312853Sgabeblack@google.com { 14412853Sgabeblack@google.com sc_uint_base::operator = (a); 14512853Sgabeblack@google.com } 14612853Sgabeblack@google.com sc_uint(long a) : sc_uint_base(W) 14712853Sgabeblack@google.com { 14812853Sgabeblack@google.com sc_uint_base::operator = (a); 14912853Sgabeblack@google.com } 15012853Sgabeblack@google.com sc_uint(unsigned int a) : sc_uint_base(W) 15112853Sgabeblack@google.com { 15212853Sgabeblack@google.com sc_uint_base::operator = (a); 15312853Sgabeblack@google.com } 15412853Sgabeblack@google.com sc_uint(int a) : sc_uint_base(W) 15512853Sgabeblack@google.com { 15612853Sgabeblack@google.com sc_uint_base::operator = (a); 15712853Sgabeblack@google.com } 15812853Sgabeblack@google.com sc_uint(int64 a) : sc_uint_base(W) 15912853Sgabeblack@google.com { 16012853Sgabeblack@google.com sc_uint_base::operator = (a); 16112853Sgabeblack@google.com } 16212853Sgabeblack@google.com sc_uint(double a) : sc_uint_base(W) 16312853Sgabeblack@google.com { 16412853Sgabeblack@google.com sc_uint_base::operator = (a); 16512853Sgabeblack@google.com } 16612853Sgabeblack@google.com 16712853Sgabeblack@google.com // assignment operators 16812853Sgabeblack@google.com sc_uint<W> & 16912853Sgabeblack@google.com operator = (uint_type v) 17012853Sgabeblack@google.com { 17112853Sgabeblack@google.com sc_uint_base::operator = (v); 17212853Sgabeblack@google.com return *this; 17312853Sgabeblack@google.com } 17412853Sgabeblack@google.com sc_uint<W> & 17512853Sgabeblack@google.com operator = (const sc_uint_base &a) 17612853Sgabeblack@google.com { 17712853Sgabeblack@google.com sc_uint_base::operator = (a); 17812853Sgabeblack@google.com return *this; 17912853Sgabeblack@google.com } 18012853Sgabeblack@google.com sc_uint<W> & 18112853Sgabeblack@google.com operator = (const sc_uint_subref_r &a) 18212853Sgabeblack@google.com { 18312853Sgabeblack@google.com sc_uint_base::operator = (a); 18412853Sgabeblack@google.com return *this; 18512853Sgabeblack@google.com } 18612853Sgabeblack@google.com sc_uint<W> & 18712853Sgabeblack@google.com operator = (const sc_uint<W> &a) 18812853Sgabeblack@google.com { 18912853Sgabeblack@google.com m_val = a.m_val; 19012853Sgabeblack@google.com return *this; 19112853Sgabeblack@google.com } 19212853Sgabeblack@google.com template<class T> 19312853Sgabeblack@google.com sc_uint<W> & 19412853Sgabeblack@google.com operator = (const sc_generic_base<T> &a) 19512853Sgabeblack@google.com { 19612853Sgabeblack@google.com sc_uint_base::operator = (a); 19712853Sgabeblack@google.com return *this; 19812853Sgabeblack@google.com } 19912853Sgabeblack@google.com sc_uint<W> & 20012853Sgabeblack@google.com operator = (const sc_signed &a) 20112853Sgabeblack@google.com { 20212853Sgabeblack@google.com sc_uint_base::operator = (a); 20312853Sgabeblack@google.com return *this; 20412853Sgabeblack@google.com } 20512853Sgabeblack@google.com sc_uint<W> & 20612853Sgabeblack@google.com operator = (const sc_unsigned &a) 20712853Sgabeblack@google.com { 20812853Sgabeblack@google.com sc_uint_base::operator = (a); 20912853Sgabeblack@google.com return *this; 21012853Sgabeblack@google.com } 21112853Sgabeblack@google.com sc_uint<W> & 21212853Sgabeblack@google.com operator = (const sc_fxval &a) 21312853Sgabeblack@google.com { 21412853Sgabeblack@google.com sc_uint_base::operator = (a); 21512853Sgabeblack@google.com return *this; 21612853Sgabeblack@google.com } 21712853Sgabeblack@google.com sc_uint<W> & 21812853Sgabeblack@google.com operator = (const sc_fxval_fast &a) 21912853Sgabeblack@google.com { 22012853Sgabeblack@google.com sc_uint_base::operator = (a); 22112853Sgabeblack@google.com return *this; 22212853Sgabeblack@google.com } 22312853Sgabeblack@google.com sc_uint<W> & 22412853Sgabeblack@google.com operator = (const sc_fxnum &a) 22512853Sgabeblack@google.com { 22612853Sgabeblack@google.com sc_uint_base::operator = (a); 22712853Sgabeblack@google.com return *this; 22812853Sgabeblack@google.com } 22912853Sgabeblack@google.com sc_uint<W> & 23012853Sgabeblack@google.com operator = (const sc_fxnum_fast &a) 23112853Sgabeblack@google.com { 23212853Sgabeblack@google.com sc_uint_base::operator = (a); 23312853Sgabeblack@google.com return *this; 23412853Sgabeblack@google.com } 23512853Sgabeblack@google.com sc_uint<W> & 23612853Sgabeblack@google.com operator = (const sc_bv_base &a) 23712853Sgabeblack@google.com { 23812853Sgabeblack@google.com sc_uint_base::operator = (a); 23912853Sgabeblack@google.com return *this; 24012853Sgabeblack@google.com } 24112853Sgabeblack@google.com sc_uint<W> & 24212853Sgabeblack@google.com operator = (const sc_lv_base &a) 24312853Sgabeblack@google.com { 24412853Sgabeblack@google.com sc_uint_base::operator = (a); 24512853Sgabeblack@google.com return *this; 24612853Sgabeblack@google.com } 24712853Sgabeblack@google.com sc_uint<W> & 24812853Sgabeblack@google.com operator = (const char* a) 24912853Sgabeblack@google.com { 25012853Sgabeblack@google.com sc_uint_base::operator = (a); 25112853Sgabeblack@google.com return *this; 25212853Sgabeblack@google.com } 25312853Sgabeblack@google.com sc_uint<W> & 25412853Sgabeblack@google.com operator = (unsigned long a) 25512853Sgabeblack@google.com { 25612853Sgabeblack@google.com sc_uint_base::operator = (a); 25712853Sgabeblack@google.com return *this; 25812853Sgabeblack@google.com } 25912853Sgabeblack@google.com sc_uint<W> & 26012853Sgabeblack@google.com operator = (long a) 26112853Sgabeblack@google.com { 26212853Sgabeblack@google.com sc_uint_base::operator = (a); 26312853Sgabeblack@google.com return *this; 26412853Sgabeblack@google.com } 26512853Sgabeblack@google.com sc_uint<W> & 26612853Sgabeblack@google.com operator = (unsigned int a) 26712853Sgabeblack@google.com { 26812853Sgabeblack@google.com sc_uint_base::operator = (a); 26912853Sgabeblack@google.com return *this; 27012853Sgabeblack@google.com } 27112853Sgabeblack@google.com sc_uint<W> & 27212853Sgabeblack@google.com operator = (int a) 27312853Sgabeblack@google.com { 27412853Sgabeblack@google.com sc_uint_base::operator = (a); 27512853Sgabeblack@google.com return *this; 27612853Sgabeblack@google.com } 27712853Sgabeblack@google.com sc_uint<W> & 27812853Sgabeblack@google.com operator = (int64 a) 27912853Sgabeblack@google.com { 28012853Sgabeblack@google.com sc_uint_base::operator = (a); 28112853Sgabeblack@google.com return *this; 28212853Sgabeblack@google.com } 28312853Sgabeblack@google.com sc_uint<W> & 28412853Sgabeblack@google.com operator = (double a) 28512853Sgabeblack@google.com { 28612853Sgabeblack@google.com sc_uint_base::operator = (a); 28712853Sgabeblack@google.com return *this; 28812853Sgabeblack@google.com } 28912853Sgabeblack@google.com 29012853Sgabeblack@google.com // arithmetic assignment operators 29112853Sgabeblack@google.com sc_uint<W> & 29212853Sgabeblack@google.com operator += (uint_type v) 29312853Sgabeblack@google.com { 29412853Sgabeblack@google.com sc_uint_base::operator += (v); 29512853Sgabeblack@google.com return *this; 29612853Sgabeblack@google.com } 29712853Sgabeblack@google.com sc_uint<W> & 29812853Sgabeblack@google.com operator -= (uint_type v) 29912853Sgabeblack@google.com { 30012853Sgabeblack@google.com sc_uint_base::operator -= (v); 30112853Sgabeblack@google.com return *this; 30212853Sgabeblack@google.com } 30312853Sgabeblack@google.com sc_uint<W> & 30412853Sgabeblack@google.com operator *= (uint_type v) 30512853Sgabeblack@google.com { 30612853Sgabeblack@google.com sc_uint_base::operator *= (v); 30712853Sgabeblack@google.com return *this; 30812853Sgabeblack@google.com } 30912853Sgabeblack@google.com sc_uint<W> & 31012853Sgabeblack@google.com operator /= (uint_type v) 31112853Sgabeblack@google.com { 31212853Sgabeblack@google.com sc_uint_base::operator /= (v); 31312853Sgabeblack@google.com return *this; 31412853Sgabeblack@google.com } 31512853Sgabeblack@google.com sc_uint<W> & 31612853Sgabeblack@google.com operator %= (uint_type v) 31712853Sgabeblack@google.com { 31812853Sgabeblack@google.com sc_uint_base::operator %= (v); 31912853Sgabeblack@google.com return *this; 32012853Sgabeblack@google.com } 32112853Sgabeblack@google.com 32212853Sgabeblack@google.com // bitwise assignment operators 32312853Sgabeblack@google.com sc_uint<W> & 32412853Sgabeblack@google.com operator &= (uint_type v) 32512853Sgabeblack@google.com { 32612853Sgabeblack@google.com sc_uint_base::operator &= (v); 32712853Sgabeblack@google.com return *this; 32812853Sgabeblack@google.com } 32912853Sgabeblack@google.com sc_uint<W> & 33012853Sgabeblack@google.com operator |= (uint_type v) 33112853Sgabeblack@google.com { 33212853Sgabeblack@google.com sc_uint_base::operator |= (v); 33312853Sgabeblack@google.com return *this; 33412853Sgabeblack@google.com } 33512853Sgabeblack@google.com sc_uint<W> & 33612853Sgabeblack@google.com operator ^= (uint_type v) 33712853Sgabeblack@google.com { 33812853Sgabeblack@google.com sc_uint_base::operator ^= (v); 33912853Sgabeblack@google.com return *this; 34012853Sgabeblack@google.com } 34112853Sgabeblack@google.com 34212853Sgabeblack@google.com sc_uint<W> & 34312853Sgabeblack@google.com operator <<= (uint_type v) 34412853Sgabeblack@google.com { 34512853Sgabeblack@google.com sc_uint_base::operator <<= (v); 34612853Sgabeblack@google.com return *this; 34712853Sgabeblack@google.com } 34812853Sgabeblack@google.com sc_uint<W> & 34912853Sgabeblack@google.com operator >>= (uint_type v) 35012853Sgabeblack@google.com { 35112853Sgabeblack@google.com sc_uint_base::operator >>= (v); 35212853Sgabeblack@google.com return *this; 35312853Sgabeblack@google.com } 35412853Sgabeblack@google.com 35512853Sgabeblack@google.com // prefix and postfix increment and decrement operators 35612853Sgabeblack@google.com sc_uint<W> & 35712853Sgabeblack@google.com operator ++ () // prefix 35812853Sgabeblack@google.com { 35912853Sgabeblack@google.com sc_uint_base::operator ++ (); 36012853Sgabeblack@google.com return *this; 36112853Sgabeblack@google.com } 36212853Sgabeblack@google.com const sc_uint<W> 36312853Sgabeblack@google.com operator ++ ( int ) // postfix 36412853Sgabeblack@google.com { 36512853Sgabeblack@google.com return sc_uint<W>(sc_uint_base::operator ++ (0)); 36612853Sgabeblack@google.com } 36712853Sgabeblack@google.com sc_uint<W> & 36812853Sgabeblack@google.com operator -- () // prefix 36912853Sgabeblack@google.com { 37012853Sgabeblack@google.com sc_uint_base::operator -- (); 37112853Sgabeblack@google.com return *this; 37212853Sgabeblack@google.com } 37312853Sgabeblack@google.com const sc_uint<W> 37412853Sgabeblack@google.com operator -- (int) // postfix 37512853Sgabeblack@google.com { 37612853Sgabeblack@google.com return sc_uint<W>(sc_uint_base::operator -- (0)); 37712853Sgabeblack@google.com } 37812853Sgabeblack@google.com}; 37912853Sgabeblack@google.com 38012853Sgabeblack@google.com} // namespace sc_dt 38112853Sgabeblack@google.com 38212853Sgabeblack@google.com#endif // __SYSTEMC_EXT_DT_INT_SC_UINT_HH__ 383