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

📄 sc_fxnum.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_fxnum.cpp -   Original Author: Martin Janssen, Synopsys, Inc. *****************************************************************************//*****************************************************************************  MODIFICATION LOG - modifiers, enter your name, affiliation, date and  changes you are making here.      Name, Affiliation, Date:  Description of Modification: *****************************************************************************/// $Log: sc_fxnum.cpp,v $// Revision 1.1.1.1  2006/12/15 20:31:36  acg// SystemC 2.2//// Revision 1.3  2006/01/13 18:53:57  acg// Andy Goodrich: added $Log command so that CVS comments are reproduced in// the source.//#include <math.h>#include "sysc/datatypes/fx/sc_fxnum.h"namespace sc_dt{// ----------------------------------------------------------------------------//  CLASS : sc_fxnum_bitref////  Proxy class for bit-selection in class sc_fxnum, behaves like sc_bit.// ----------------------------------------------------------------------------boolsc_fxnum_bitref::get() const{    return m_num.get_bit( m_idx );}voidsc_fxnum_bitref::set( bool high ){    m_num.set_bit( m_idx, high );}// print or dump contentvoidsc_fxnum_bitref::print( ::std::ostream& os ) const{    os << get();}voidsc_fxnum_bitref::scan( ::std::istream& is ){    bool b;    is >> b;    *this = b;}voidsc_fxnum_bitref::dump( ::std::ostream& os ) const{    os << "sc_fxnum_bitref" << ::std::endl;    os << "(" << ::std::endl;    os << "num = ";    m_num.dump( os );    os << "idx = " << m_idx << ::std::endl;    os << ")" << ::std::endl;}// ----------------------------------------------------------------------------//  CLASS : sc_fxnum_fast_bitref////  Proxy class for bit-selection in class sc_fxnum_fast, behaves like sc_bit.// ----------------------------------------------------------------------------boolsc_fxnum_fast_bitref::get() const{    return m_num.get_bit( m_idx );}voidsc_fxnum_fast_bitref::set( bool high ){    m_num.set_bit( m_idx, high );}// print or dump contentvoidsc_fxnum_fast_bitref::print( ::std::ostream& os ) const{    os << get();}voidsc_fxnum_fast_bitref::scan( ::std::istream& is ){    bool b;    is >> b;    *this = b;}voidsc_fxnum_fast_bitref::dump( ::std::ostream& os ) const{    os << "sc_fxnum_fast_bitref" << ::std::endl;    os << "(" << ::std::endl;    os << "num = ";    m_num.dump( os );    os << "idx = " << m_idx << ::std::endl;    os << ")" << ::std::endl;}// ----------------------------------------------------------------------------//  CLASS : sc_fxnum_subref////  Proxy class for part-selection in class sc_fxnum,//  behaves like sc_bv_base.// ----------------------------------------------------------------------------boolsc_fxnum_subref::get() const{    return m_num.get_slice( m_from, m_to, m_bv );}boolsc_fxnum_subref::set(){    return m_num.set_slice( m_from, m_to, m_bv );}// print or dump contentvoidsc_fxnum_subref::print( ::std::ostream& os ) const{    get();    m_bv.print( os );}voidsc_fxnum_subref::scan( ::std::istream& is ){    m_bv.scan( is );    set();}voidsc_fxnum_subref::dump( ::std::ostream& os ) const{    os << "sc_fxnum_subref" << ::std::endl;    os << "(" << ::std::endl;    os << "num  = ";    m_num.dump( os );    os << "from = " << m_from << ::std::endl;    os << "to   = " << m_to << ::std::endl;    os << ")" << ::std::endl;}// ----------------------------------------------------------------------------//  CLASS : sc_fxnum_fast_subref////  Proxy class for part-selection in class sc_fxnum_fast,//  behaves like sc_bv_base.// ----------------------------------------------------------------------------boolsc_fxnum_fast_subref::get() const{    return m_num.get_slice( m_from, m_to, m_bv );}boolsc_fxnum_fast_subref::set(){    return m_num.set_slice( m_from, m_to, m_bv );}// print or dump contentvoidsc_fxnum_fast_subref::print( ::std::ostream& os ) const{    get();    m_bv.print( os );}voidsc_fxnum_fast_subref::scan( ::std::istream& is ){    m_bv.scan( is );    set();}voidsc_fxnum_fast_subref::dump( ::std::ostream& os ) const{    os << "sc_fxnum_fast_subref" << ::std::endl;    os << "(" << ::std::endl;    os << "num  = ";    m_num.dump( os );    os << "from = " << m_from << ::std::endl;    os << "to   = " << m_to << ::std::endl;    os << ")" << ::std::endl;}// ----------------------------------------------------------------------------//  CLASS : sc_fxnum////  Base class for the fixed-point types; arbitrary precision.// ----------------------------------------------------------------------------// explicit conversion to character stringconst std::stringsc_fxnum::to_string() const{    return std::string( m_rep->to_string( SC_DEC, -1, SC_F, &m_params ) );}const std::stringsc_fxnum::to_string( sc_numrep numrep ) const{    return std::string( m_rep->to_string( numrep, -1, SC_F, &m_params ) );}const std::stringsc_fxnum::to_string( sc_numrep numrep, bool w_prefix ) const{    return std::string( m_rep->to_string( numrep, (w_prefix ? 1 : 0),					SC_F, &m_params ) );}const std::stringsc_fxnum::to_string( sc_fmt fmt ) const{    return std::string( m_rep->to_string( SC_DEC, -1, fmt, &m_params ) );}const std::stringsc_fxnum::to_string( sc_numrep numrep, sc_fmt fmt ) const{    return std::string( m_rep->to_string( numrep, -1, fmt, &m_params ) );}const std::stringsc_fxnum::to_string( sc_numrep numrep, bool w_prefix, sc_fmt fmt ) const{    return std::string( m_rep->to_string( numrep, (w_prefix ? 1 : 0),					fmt, &m_params ) );}const std::stringsc_fxnum::to_dec() const{    return std::string( m_rep->to_string( SC_DEC, -1, SC_F, &m_params ) );}const std::stringsc_fxnum::to_bin() const{    return std::string( m_rep->to_string( SC_BIN, -1, SC_F, &m_params ) );}const std::stringsc_fxnum::to_oct() const{    return std::string( m_rep->to_string( SC_OCT, -1, SC_F, &m_params ) );}const std::stringsc_fxnum::to_hex() const{    return std::string( m_rep->to_string( SC_HEX, -1, SC_F, &m_params ) );}// print or dump contentvoidsc_fxnum::print( ::std::ostream& os ) const{    os << m_rep->to_string( SC_DEC, -1, SC_F, &m_params );}voidsc_fxnum::scan( ::std::istream& is ){    std::string s;    is >> s;    *this = s.c_str();}voidsc_fxnum::dump( ::std::ostream& os ) const{    os << "sc_fxnum" << ::std::endl;    os << "(" << ::std::endl;    os << "rep      = ";    m_rep->dump( os );    os << "params   = ";    m_params.dump( os );    os << "q_flag   = " << m_q_flag << ::std::endl;    os << "o_flag   = " << m_o_flag << ::std::endl;    // TO BE COMPLETED    // os << "observer = ";    // if( m_observer != 0 )    //     m_observer->dump( os );    // else    //     os << "0" << ::std::endl;    os << ")" << ::std::endl;}sc_fxnum_observer*sc_fxnum::lock_observer() const{    SC_ASSERT_( m_observer != 0, "lock observer failed" );    sc_fxnum_observer* tmp = m_observer;    m_observer = 0;    return tmp;}voidsc_fxnum::unlock_observer( sc_fxnum_observer* observer_ ) const{    SC_ASSERT_( observer_ != 0, "unlock observer failed" );    m_observer = observer_;}// ----------------------------------------------------------------------------//  CLASS : sc_fxnum_fast////  Base class for the fixed-point types; limited precision.// ----------------------------------------------------------------------------staticvoidquantization( double& c, const scfx_params& params, bool& q_flag ){    int fwl = params.wl() - params.iwl();    double scale = scfx_pow2( fwl );    double val = scale * c;    double int_part;    double frac_part = modf( val, &int_part );    q_flag = ( frac_part != 0.0 );    if( q_flag )    {        val = int_part;	switch( params.q_mode() )	{            case SC_TRN:			// truncation	    {	        if( c < 0.0 )		    val -= 1.0;		break;	    }            case SC_RND:			// rounding to plus infinity	    {		if( frac_part >= 0.5 )		    val += 1.0;		else if( frac_part < -0.5 )		    val -= 1.0;		break;	    }            case SC_TRN_ZERO:			// truncation to zero	    {	        break;	    }            case SC_RND_INF:			// rounding to infinity	    {		if( frac_part >= 0.5 )		    val += 1.0;		else if( frac_part <= -0.5 )		    val -= 1.0;		break;	    }            case SC_RND_CONV:			// convergent rounding	    {		if( frac_part > 0.5 ||		    frac_part == 0.5 && fmod( int_part, 2.0 ) != 0.0 )		    val += 1.0;		else if( frac_part < -0.5 ||			 frac_part == -0.5 && fmod( int_part, 2.0 ) != 0.0 )		    val -= 1.0;		break;	    }            case SC_RND_ZERO:			// rounding to zero	    {		if( frac_part > 0.5 )		    val += 1.0;		else if( frac_part < -0.5 )		    val -= 1.0;		break;	    }            case SC_RND_MIN_INF:		// rounding to minus infinity	    {		if( frac_part > 0.5 )		    val += 1.0;		else if( frac_part <= -0.5 )		    val -= 1.0;		break;	    }            default:	        ;	}    }    val /= scale;    c = val;}staticvoidoverflow( double& c, const scfx_params& params, bool& o_flag ){    int iwl = params.iwl();    int fwl = params.wl() - iwl;    double full_circle = scfx_pow2( iwl );    double resolution = scfx_pow2( -fwl );    double low, high;    if( params.enc() == SC_TC_ )    {	high = full_circle / 2.0 - resolution;	if( params.o_mode() == SC_SAT_SYM )	    low = - high;	else	    low = - full_circle / 2.0;    }    else    {	low = 0.0;

⌨️ 快捷键说明

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