1/***************************************************************************** 2 3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 4 more contributor license agreements. See the NOTICE file distributed 5 with this work for additional information regarding copyright ownership. 6 Accellera licenses this file to you under the Apache License, Version 2.0 7 (the "License"); you may not use this file except in compliance with the 8 License. You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 15 implied. See the License for the specific language governing 16 permissions and limitations under the License. 17 18 *****************************************************************************/ 19 20/***************************************************************************** 21 22 sc_unsigned_bitref.h -- Proxy class that is declared in sc_unsigned.h. 23 24 Original Author: Ali Dasdan, Synopsys, Inc. 25 26 *****************************************************************************/ 27 28/***************************************************************************** 29 30 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 31 changes you are making here. 32 33 Name, Affiliation, Date: 34 Description of Modification: 35 36 *****************************************************************************/ 37 38 39// ---------------------------------------------------------------------------- 40// CLASS : sc_unsigned_bitref_r 41// 42// Proxy class for sc_unsigned bit selection (r-value only). 43// ---------------------------------------------------------------------------- 44 45// implicit conversion to uint64 46 47sc_unsigned_bitref_r::operator uint64 () const 48{ 49 return m_obj_p->test(m_index); 50} 51 52bool 53sc_unsigned_bitref_r::operator ! () const 54{ 55 return (!m_obj_p->test(m_index)); 56} 57 58bool 59sc_unsigned_bitref_r::operator ~ () const 60{ 61 return (!m_obj_p->test(m_index)); 62} 63 64 65// ---------------------------------------------------------------------------- 66// CLASS : sc_unsigned_bitref 67// 68// Proxy class for sc_unsigned bit selection (r-value and l-value). 69// ---------------------------------------------------------------------------- 70 71// assignment operators 72 73const sc_unsigned_bitref & 74sc_unsigned_bitref::operator = (const sc_unsigned_bitref_r &b) 75{ 76 m_obj_p->set(m_index, (bool)b); 77 return *this; 78} 79 80const sc_unsigned_bitref & 81sc_unsigned_bitref::operator = (const sc_unsigned_bitref &b) 82{ 83 m_obj_p->set(m_index, (bool)b); 84 return *this; 85} 86 87const sc_unsigned_bitref & 88sc_unsigned_bitref::operator = (bool b) 89{ 90 m_obj_p->set(m_index, b); 91 return *this; 92} 93 94 95const sc_unsigned_bitref & 96sc_unsigned_bitref::operator &= (bool b) 97{ 98 if (!b) { 99 m_obj_p->clear(m_index); 100 } 101 return *this; 102} 103 104const sc_unsigned_bitref & 105sc_unsigned_bitref::operator |= (bool b) 106{ 107 if (b) { 108 m_obj_p->set(m_index); 109 } 110 return *this; 111} 112 113const sc_unsigned_bitref & 114sc_unsigned_bitref::operator ^= (bool b) 115{ 116 if (b) { 117 m_obj_p->invert(m_index); 118 } 119 return *this; 120} 121 122// #### OPTIMIZE 123void 124sc_unsigned_bitref::concat_set(int64 src, int low_i) 125{ 126 bool value = 1 & ((low_i < 64) ? (src >> low_i) : (src >> 63)); 127 m_obj_p->set(low_i, value); 128} 129 130void 131sc_unsigned_bitref::concat_set(const sc_signed &src, int low_i) 132{ 133 if (low_i < src.length()) 134 m_obj_p->set(low_i, src.test(low_i)); 135 else 136 m_obj_p->set(low_i, src < 0); 137} 138 139void 140sc_unsigned_bitref::concat_set(const sc_unsigned &src, int low_i) 141{ 142 if (low_i < src.nbits) 143 m_obj_p->set(low_i, src.test(low_i)); 144 else 145 m_obj_p->set(low_i, 0); 146} 147 148void 149sc_unsigned_bitref::concat_set(uint64 src, int low_i) 150{ 151 bool value = ((low_i < 64) ? (src >> low_i) & 1 : 0); 152 m_obj_p->set(low_i, value); 153} 154 155// other methods 156void 157sc_unsigned_bitref::scan(::std::istream &is) 158{ 159 bool b; 160 is >> b; 161 *this = b; 162} 163