📄 sc_int_base.cpp
字号:
/***************************************************************************** The following code is derived, directly or indirectly, from the SystemC source code Copyright (c) 1996-2006 by all Contributors. All Rights reserved. The contents of this file are subject to the restrictions and limitations set forth in the SystemC Open Source License Version 2.4 (the "License"); You may not use this file except in compliance with such restrictions and limitations. You may obtain instructions on how to receive a copy of the License at http://www.systemc.org/. Software distributed by Contributors under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. *****************************************************************************//***************************************************************************** sc_int_base.cpp -- contains interface definitions between sc_int and sc_signed, sc_unsigned, and definitions for sc_int_subref. Original Author: Ali Dasdan, Synopsys, Inc. *****************************************************************************//***************************************************************************** MODIFICATION LOG - modifiers, enter your name, affiliation, date and changes you are making here. Name, Affiliation, Date: Description of Modification: *****************************************************************************/// $Log: sc_int_base.cpp,v $// Revision 1.1.1.1 2006/12/15 20:31:36 acg// SystemC 2.2//// Revision 1.3 2006/01/13 18:49:31 acg// Added $Log command so that CVS check in comments are reproduced in the// source.//#include "sysc/kernel/sc_macros.h"#include "sysc/datatypes/int/sc_signed.h"#include "sysc/datatypes/int/sc_unsigned.h"#include "sysc/datatypes/int/sc_int_base.h"#include "sysc/datatypes/int/sc_uint_base.h"#include "sysc/datatypes/int/sc_signed.h"#include "sysc/datatypes/int/sc_int_ids.h"#include "sysc/datatypes/bit/sc_bv_base.h"#include "sysc/datatypes/bit/sc_lv_base.h"#include "sysc/datatypes/misc/sc_concatref.h"#include "sysc/datatypes/fx/sc_fix.h"#include "sysc/datatypes/fx/scfx_other_defs.h"namespace sc_dt{// to avoid code bloat in sc_int_concref<T1,T2>voidsc_int_concref_invalid_length( int length ){ char msg[BUFSIZ]; std::sprintf( msg, "sc_int_concref<T1,T2> initialization: length = %d " "violates 1 <= length <= %d", length, SC_INTWIDTH ); SC_REPORT_ERROR( sc_core::SC_ID_OUT_OF_BOUNDS_, msg );}// ----------------------------------------------------------------------------// CLASS : sc_int_bitref//// Proxy class for sc_int bit selection (r-value and l-value).// ----------------------------------------------------------------------------sc_core::sc_vpool<sc_int_bitref> sc_int_bitref::m_pool(9);// concatenation methods:// #### OPTIMIZEvoid sc_int_bitref::concat_set(int64 src, int low_i){ sc_int_base aa( 1 ); *this = aa = (low_i < 64) ? src >> low_i : src >> 63;}void sc_int_bitref::concat_set(const sc_signed& src, int low_i){ sc_int_base aa( 1 ); if ( low_i < src.length() ) *this = aa = 1 & (src >> low_i); else *this = aa = (src < 0) ? (int_type)-1 : 0;}void sc_int_bitref::concat_set(const sc_unsigned& src, int low_i){ sc_int_base aa( 1 ); if ( low_i < src.length() ) *this = aa = 1 & (src >> low_i); else *this = aa = 0;}void sc_int_bitref::concat_set(uint64 src, int low_i){ sc_int_base aa( 1 ); *this = aa = (low_i < 64) ? src >> low_i : 0;}// other methodsvoidsc_int_bitref::scan( ::std::istream& is ){ bool b; is >> b; *this = b;}// ----------------------------------------------------------------------------// CLASS : sc_int_subref_r//// Proxy class for sc_int part selection (l-value).// ----------------------------------------------------------------------------bool sc_int_subref_r::concat_get_ctrl( sc_digit* dst_p, int low_i ) const{ int dst_i; // Word in dst_p now processing. int end_i; // Highest order word in dst_p to process. int high_i; // Index of high order bit in dst_p to set. sc_digit mask; // Mask for bits to extract or keep. dst_i = low_i / BITS_PER_DIGIT; high_i = low_i + (m_left-m_right); end_i = high_i / BITS_PER_DIGIT; mask = ~mask_int[m_left][m_right]; // PROCESS THE FIRST WORD: dst_p[dst_i] = (unsigned long)(dst_p[dst_i] & mask); switch ( end_i - dst_i ) { // BITS ARE ACROSS TWO WORDS: case 1: dst_i++; dst_p[dst_i] = 0; break; // BITS ARE ACROSS THREE WORDS: case 2: dst_i++; dst_p[dst_i++] = 0; dst_p[dst_i] = 0; break; // BITS ARE ACROSS FOUR WORDS: case 3: dst_i++; dst_p[dst_i++] = 0; dst_p[dst_i++] = 0; dst_p[dst_i] = 0; break; } return false;}bool sc_int_subref_r::concat_get_data( sc_digit* dst_p, int low_i ) const{ int dst_i; // Word in dst_p now processing. int end_i; // Highest order word in dst_p to process. int high_i; // Index of high order bit in dst_p to set. int left_shift; // Left shift for val. sc_digit mask; // Mask for bits to extract or keep. bool non_zero; // True if value inserted is non-zero. uint_type val; // Selection value extracted from m_obj_p. dst_i = low_i / BITS_PER_DIGIT; left_shift = low_i % BITS_PER_DIGIT; high_i = low_i + (m_left-m_right); end_i = high_i / BITS_PER_DIGIT; mask = ~mask_int[m_left][m_right]; val = (m_obj_p->m_val & mask) >> m_right; non_zero = val != 0; // PROCESS THE FIRST WORD: mask = ~(-1 << left_shift); dst_p[dst_i] = (unsigned long)((dst_p[dst_i] & mask) | ((val << left_shift) & DIGIT_MASK)); switch ( end_i - dst_i ) { // BITS ARE ACROSS TWO WORDS: case 1: dst_i++; val >>= (BITS_PER_DIGIT-left_shift); dst_p[dst_i] = (unsigned long)(val & DIGIT_MASK); break; // BITS ARE ACROSS THREE WORDS: case 2: dst_i++; val >>= (BITS_PER_DIGIT-left_shift); dst_p[dst_i++] = (unsigned long)(val & DIGIT_MASK); val >>= BITS_PER_DIGIT; dst_p[dst_i] = (unsigned long)val; break; // BITS ARE ACROSS FOUR WORDS: case 3: dst_i++; val >>= (BITS_PER_DIGIT-left_shift); dst_p[dst_i++] = (unsigned long)(val & DIGIT_MASK); val >>= BITS_PER_DIGIT; dst_p[dst_i++] = (unsigned long)val; val >>= BITS_PER_DIGIT; dst_p[dst_i] = (unsigned long)val; break; } return non_zero;}// ----------------------------------------------------------------------------// CLASS : sc_int_subref//// Proxy class for sc_int part selection (r-value and l-value).// ----------------------------------------------------------------------------sc_core::sc_vpool<sc_int_subref> sc_int_subref::m_pool(9);// assignment operators sc_int_subref& sc_int_subref::operator = ( int_type v ){ int_type val = m_obj_p->m_val; uint_type mask = mask_int[m_left][m_right]; val &= mask; val |= (v << m_right) & ~mask; m_obj_p->m_val = val; m_obj_p->extend_sign(); return *this;}sc_int_subref&sc_int_subref::operator = ( const sc_signed& a ){ sc_int_base aa( length() ); return ( *this = aa = a );}sc_int_subref&sc_int_subref::operator = ( const sc_unsigned& a ){ sc_int_base aa( length() ); return ( *this = aa = a );}sc_int_subref&sc_int_subref::operator = ( const sc_bv_base& a ){ sc_int_base aa( length() ); return ( *this = aa = a );}sc_int_subref&sc_int_subref::operator = ( const sc_lv_base& a ){ sc_int_base aa( length() ); return ( *this = aa = a );}// concatenation methods:// #### OPTIMIZEvoid sc_int_subref::concat_set(int64 src, int low_i){ sc_int_base aa ( length() ); *this = aa = (low_i < 64) ? src >> low_i : src >> 63;}void sc_int_subref::concat_set(const sc_signed& src, int low_i){ sc_int_base aa( length() ); if ( low_i < src.length() ) *this = aa = src >> low_i; else *this = (src < 0) ? (int_type)-1 : 0;}void sc_int_subref::concat_set(const sc_unsigned& src, int low_i){ sc_int_base aa( length() ); if ( low_i < src.length() ) *this = aa = src >> low_i; else *this = 0;}void sc_int_subref::concat_set(uint64 src, int low_i){ sc_int_base aa ( length() ); *this = aa = (low_i < 64) ? src >> low_i : 0;}// other methodsvoidsc_int_subref::scan( ::std::istream& is ){ std::string s; is >> s; *this = s.c_str();}// ----------------------------------------------------------------------------// CLASS : sc_int_base//// Base class for sc_int.// ----------------------------------------------------------------------------// support methodsvoidsc_int_base::invalid_length() const{ char msg[BUFSIZ]; std::sprintf( msg, "sc_int[_base] initialization: length = %d violates " "1 <= length <= %d", m_len, SC_INTWIDTH ); SC_REPORT_ERROR( sc_core::SC_ID_OUT_OF_BOUNDS_, msg );}void
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -