112854Sgabeblack@google.com/***************************************************************************** 212854Sgabeblack@google.com 312854Sgabeblack@google.com Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 412854Sgabeblack@google.com more contributor license agreements. See the NOTICE file distributed 512854Sgabeblack@google.com with this work for additional information regarding copyright ownership. 612854Sgabeblack@google.com Accellera licenses this file to you under the Apache License, Version 2.0 712854Sgabeblack@google.com (the "License"); you may not use this file except in compliance with the 812854Sgabeblack@google.com License. You may obtain a copy of the License at 912854Sgabeblack@google.com 1012854Sgabeblack@google.com http://www.apache.org/licenses/LICENSE-2.0 1112854Sgabeblack@google.com 1212854Sgabeblack@google.com Unless required by applicable law or agreed to in writing, software 1312854Sgabeblack@google.com distributed under the License is distributed on an "AS IS" BASIS, 1412854Sgabeblack@google.com WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 1512854Sgabeblack@google.com implied. See the License for the specific language governing 1612854Sgabeblack@google.com permissions and limitations under the License. 1712854Sgabeblack@google.com 1812854Sgabeblack@google.com *****************************************************************************/ 1912854Sgabeblack@google.com 2012854Sgabeblack@google.com/***************************************************************************** 2112854Sgabeblack@google.com 2212854Sgabeblack@google.com sc_unsigned_bitref.h -- Proxy class that is declared in sc_unsigned.h. 2312854Sgabeblack@google.com 2412854Sgabeblack@google.com Original Author: Ali Dasdan, Synopsys, Inc. 2512854Sgabeblack@google.com 2612854Sgabeblack@google.com *****************************************************************************/ 2712854Sgabeblack@google.com 2812854Sgabeblack@google.com/***************************************************************************** 2912854Sgabeblack@google.com 3012854Sgabeblack@google.com MODIFICATION LOG - modifiers, enter your name, affiliation, date and 3112854Sgabeblack@google.com changes you are making here. 3212854Sgabeblack@google.com 3312854Sgabeblack@google.com Name, Affiliation, Date: 3412854Sgabeblack@google.com Description of Modification: 3512854Sgabeblack@google.com 3612854Sgabeblack@google.com *****************************************************************************/ 3712854Sgabeblack@google.com 3812854Sgabeblack@google.com 3912854Sgabeblack@google.com// ---------------------------------------------------------------------------- 4012854Sgabeblack@google.com// CLASS : sc_unsigned_bitref_r 4112854Sgabeblack@google.com// 4212854Sgabeblack@google.com// Proxy class for sc_unsigned bit selection (r-value only). 4312854Sgabeblack@google.com// ---------------------------------------------------------------------------- 4412854Sgabeblack@google.com 4512854Sgabeblack@google.com// implicit conversion to uint64 4612854Sgabeblack@google.com 4712854Sgabeblack@google.comsc_unsigned_bitref_r::operator uint64 () const 4812854Sgabeblack@google.com{ 4912854Sgabeblack@google.com return m_obj_p->test(m_index); 5012854Sgabeblack@google.com} 5112854Sgabeblack@google.com 5212854Sgabeblack@google.combool 5312854Sgabeblack@google.comsc_unsigned_bitref_r::operator ! () const 5412854Sgabeblack@google.com{ 5512854Sgabeblack@google.com return (!m_obj_p->test(m_index)); 5612854Sgabeblack@google.com} 5712854Sgabeblack@google.com 5812854Sgabeblack@google.combool 5912854Sgabeblack@google.comsc_unsigned_bitref_r::operator ~ () const 6012854Sgabeblack@google.com{ 6112854Sgabeblack@google.com return (!m_obj_p->test(m_index)); 6212854Sgabeblack@google.com} 6312854Sgabeblack@google.com 6412854Sgabeblack@google.com 6512854Sgabeblack@google.com// ---------------------------------------------------------------------------- 6612854Sgabeblack@google.com// CLASS : sc_unsigned_bitref 6712854Sgabeblack@google.com// 6812854Sgabeblack@google.com// Proxy class for sc_unsigned bit selection (r-value and l-value). 6912854Sgabeblack@google.com// ---------------------------------------------------------------------------- 7012854Sgabeblack@google.com 7112854Sgabeblack@google.com// assignment operators 7212854Sgabeblack@google.com 7312854Sgabeblack@google.comconst sc_unsigned_bitref & 7412854Sgabeblack@google.comsc_unsigned_bitref::operator = (const sc_unsigned_bitref_r &b) 7512854Sgabeblack@google.com{ 7612854Sgabeblack@google.com m_obj_p->set(m_index, (bool)b); 7712854Sgabeblack@google.com return *this; 7812854Sgabeblack@google.com} 7912854Sgabeblack@google.com 8012854Sgabeblack@google.comconst sc_unsigned_bitref & 8112854Sgabeblack@google.comsc_unsigned_bitref::operator = (const sc_unsigned_bitref &b) 8212854Sgabeblack@google.com{ 8312854Sgabeblack@google.com m_obj_p->set(m_index, (bool)b); 8412854Sgabeblack@google.com return *this; 8512854Sgabeblack@google.com} 8612854Sgabeblack@google.com 8712854Sgabeblack@google.comconst sc_unsigned_bitref & 8812854Sgabeblack@google.comsc_unsigned_bitref::operator = (bool b) 8912854Sgabeblack@google.com{ 9012854Sgabeblack@google.com m_obj_p->set(m_index, b); 9112854Sgabeblack@google.com return *this; 9212854Sgabeblack@google.com} 9312854Sgabeblack@google.com 9412854Sgabeblack@google.com 9512854Sgabeblack@google.comconst sc_unsigned_bitref & 9612854Sgabeblack@google.comsc_unsigned_bitref::operator &= (bool b) 9712854Sgabeblack@google.com{ 9812854Sgabeblack@google.com if (!b) { 9912854Sgabeblack@google.com m_obj_p->clear(m_index); 10012854Sgabeblack@google.com } 10112854Sgabeblack@google.com return *this; 10212854Sgabeblack@google.com} 10312854Sgabeblack@google.com 10412854Sgabeblack@google.comconst sc_unsigned_bitref & 10512854Sgabeblack@google.comsc_unsigned_bitref::operator |= (bool b) 10612854Sgabeblack@google.com{ 10712854Sgabeblack@google.com if (b) { 10812854Sgabeblack@google.com m_obj_p->set(m_index); 10912854Sgabeblack@google.com } 11012854Sgabeblack@google.com return *this; 11112854Sgabeblack@google.com} 11212854Sgabeblack@google.com 11312854Sgabeblack@google.comconst sc_unsigned_bitref & 11412854Sgabeblack@google.comsc_unsigned_bitref::operator ^= (bool b) 11512854Sgabeblack@google.com{ 11612854Sgabeblack@google.com if (b) { 11712854Sgabeblack@google.com m_obj_p->invert(m_index); 11812854Sgabeblack@google.com } 11912854Sgabeblack@google.com return *this; 12012854Sgabeblack@google.com} 12112854Sgabeblack@google.com 12212854Sgabeblack@google.com// #### OPTIMIZE 12312854Sgabeblack@google.comvoid 12412854Sgabeblack@google.comsc_unsigned_bitref::concat_set(int64 src, int low_i) 12512854Sgabeblack@google.com{ 12612854Sgabeblack@google.com bool value = 1 & ((low_i < 64) ? (src >> low_i) : (src >> 63)); 12712854Sgabeblack@google.com m_obj_p->set(low_i, value); 12812854Sgabeblack@google.com} 12912854Sgabeblack@google.com 13012854Sgabeblack@google.comvoid 13112854Sgabeblack@google.comsc_unsigned_bitref::concat_set(const sc_signed &src, int low_i) 13212854Sgabeblack@google.com{ 13312854Sgabeblack@google.com if (low_i < src.length()) 13412854Sgabeblack@google.com m_obj_p->set(low_i, src.test(low_i)); 13512854Sgabeblack@google.com else 13612854Sgabeblack@google.com m_obj_p->set(low_i, src < 0); 13712854Sgabeblack@google.com} 13812854Sgabeblack@google.com 13912854Sgabeblack@google.comvoid 14012854Sgabeblack@google.comsc_unsigned_bitref::concat_set(const sc_unsigned &src, int low_i) 14112854Sgabeblack@google.com{ 14212854Sgabeblack@google.com if (low_i < src.nbits) 14312854Sgabeblack@google.com m_obj_p->set(low_i, src.test(low_i)); 14412854Sgabeblack@google.com else 14512854Sgabeblack@google.com m_obj_p->set(low_i, 0); 14612854Sgabeblack@google.com} 14712854Sgabeblack@google.com 14812854Sgabeblack@google.comvoid 14912854Sgabeblack@google.comsc_unsigned_bitref::concat_set(uint64 src, int low_i) 15012854Sgabeblack@google.com{ 15112854Sgabeblack@google.com bool value = ((low_i < 64) ? (src >> low_i) & 1 : 0); 15212854Sgabeblack@google.com m_obj_p->set(low_i, value); 15312854Sgabeblack@google.com} 15412854Sgabeblack@google.com 15512854Sgabeblack@google.com// other methods 15612854Sgabeblack@google.comvoid 15712854Sgabeblack@google.comsc_unsigned_bitref::scan(::std::istream &is) 15812854Sgabeblack@google.com{ 15912854Sgabeblack@google.com bool b; 16012854Sgabeblack@google.com is >> b; 16112854Sgabeblack@google.com *this = b; 16212854Sgabeblack@google.com} 163