⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sc_uint_base.cpp

📁 system C源码 一种替代verilog的语言
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************  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_uint_base.cpp -- contains interface definitions between sc_uint and                 sc_signed, sc_unsigned, and definitions for sc_uint_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_uint_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:32  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_uint_base.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_ufix.h"#include "sysc/datatypes/fx/scfx_other_defs.h"namespace sc_dt{// to avoid code bloat in sc_uint_concat<T1,T2>voidsc_uint_concref_invalid_length( int length ){    char msg[BUFSIZ];    std::sprintf( msg,	     "sc_uint_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_uint_bitref////  Proxy class for sc_uint bit selection (r-value and l-value).// ----------------------------------------------------------------------------sc_core::sc_vpool<sc_uint_bitref> sc_uint_bitref::m_pool(9);// concatenation methods:// #### OPTIMIZEvoid sc_uint_bitref::concat_set(int64 src, int low_i){       sc_uint_base aa( 1 );    *this = aa = (low_i < 64) ? src >> low_i : src >> 63;}void sc_uint_bitref::concat_set(const sc_signed& src, int low_i){    sc_uint_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_uint_bitref::concat_set(const sc_unsigned& src, int low_i){    sc_uint_base aa( 1 );    if ( low_i < src.length() )        *this = aa = 1 & (src >> low_i);    else        *this = aa = 0;}void sc_uint_bitref::concat_set(uint64 src, int low_i){    sc_uint_base aa( 1 );    *this = aa = (low_i < 64) ? src >> low_i : 0;}// other methodsvoidsc_uint_bitref::scan( ::std::istream& is ){    bool b;    is >> b;    *this = b;}// ----------------------------------------------------------------------------//  CLASS : sc_uint_subref_r////  Proxy class for sc_uint part selection (l-value).// ----------------------------------------------------------------------------bool sc_uint_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       left_shift;  // Left shift for val.    sc_digit  mask;	   // Mask for bits to extract or keep.    dst_i = low_i / BITS_PER_DIGIT;    left_shift = low_i % BITS_PER_DIGIT;    end_i = (low_i + (m_left-m_right)) / BITS_PER_DIGIT;     mask = ~(-1 << left_shift);    dst_p[dst_i] = (unsigned long)((dst_p[dst_i] & mask));    dst_i++;    for ( ; dst_i <= end_i; dst_i++ ) dst_p[dst_i] = 0;    return false;}bool sc_uint_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      result;	   // True if inserting non-zero value.    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;    result = 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;        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 THREE 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 & DIGIT_MASK);        val >>= BITS_PER_DIGIT;        dst_p[dst_i] = (unsigned long)val;        break;    }    return result;}// ----------------------------------------------------------------------------//  CLASS : sc_uint_subref////  Proxy class for sc_uint part selection (r-value and l-value).// ----------------------------------------------------------------------------sc_core::sc_vpool<sc_uint_subref> sc_uint_subref::m_pool(9);// assignment operatorssc_uint_subref& sc_uint_subref::operator = ( uint_type v ){    uint_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_uint_subref&sc_uint_subref::operator = ( const sc_signed& a ){    sc_uint_base aa( length() );    return ( *this = aa = a );}sc_uint_subref&sc_uint_subref::operator = ( const sc_unsigned& a ){    sc_uint_base aa( length() );    return ( *this = aa = a );}sc_uint_subref&sc_uint_subref::operator = ( const sc_bv_base& a ){    sc_uint_base aa( length() );    return ( *this = aa = a );}sc_uint_subref&sc_uint_subref::operator = ( const sc_lv_base& a ){    sc_uint_base aa( length() );    return ( *this = aa = a );}// concatenation methods:// #### OPTIMIZEvoid sc_uint_subref::concat_set(int64 src, int low_i){    sc_uint_base aa( length() );    *this = aa = (low_i < 64) ? src >> low_i : src >> 63;}void sc_uint_subref::concat_set(const sc_signed& src, int low_i)   {    sc_uint_base aa( length() );       if ( low_i < src.length() )        *this = aa = src >> low_i;    else        *this = aa = (src < 0) ? (int_type)-1 : 0;}void sc_uint_subref::concat_set(const sc_unsigned& src, int low_i)   {    sc_uint_base aa( length() );    if ( low_i < src.length() )        *this = aa = src >> low_i;    else        *this = aa = 0;} void sc_uint_subref::concat_set(uint64 src, int low_i)   {          sc_uint_base aa( length() );    *this = aa = (low_i < 64) ? src >> low_i : 0;}// other methodsvoidsc_uint_subref::scan( ::std::istream& is ){    std::string s;    is >> s;    *this = s.c_str();}// ----------------------------------------------------------------------------//  CLASS : sc_uint_base////  Base class for sc_uint.// ----------------------------------------------------------------------------// support methodsvoidsc_uint_base::invalid_length() const{    char msg[BUFSIZ];    std::sprintf( msg,	     "sc_uint[_base] initialization: length = %d violates "	     "1 <= length <= %d",	     m_len, SC_INTWIDTH );    SC_REPORT_ERROR( sc_core::SC_ID_OUT_OF_BOUNDS_, msg );}voidsc_uint_base::invalid_index( int i ) const{    char msg[BUFSIZ];    std::sprintf( msg,	     "sc_uint[_base] bit selection: index = %d violates "	     "0 <= index <= %d",	     i, m_len - 1 );    SC_REPORT_ERROR( sc_core::SC_ID_OUT_OF_BOUNDS_, msg );}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -