sc_fxdefs.hh revision 12853
112853Sgabeblack@google.com/*****************************************************************************
212853Sgabeblack@google.com
312853Sgabeblack@google.com  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
412853Sgabeblack@google.com  more contributor license agreements.  See the NOTICE file distributed
512853Sgabeblack@google.com  with this work for additional information regarding copyright ownership.
612853Sgabeblack@google.com  Accellera licenses this file to you under the Apache License, Version 2.0
712853Sgabeblack@google.com  (the "License"); you may not use this file except in compliance with the
812853Sgabeblack@google.com  License.  You may obtain a copy of the License at
912853Sgabeblack@google.com
1012853Sgabeblack@google.com    http://www.apache.org/licenses/LICENSE-2.0
1112853Sgabeblack@google.com
1212853Sgabeblack@google.com  Unless required by applicable law or agreed to in writing, software
1312853Sgabeblack@google.com  distributed under the License is distributed on an "AS IS" BASIS,
1412853Sgabeblack@google.com  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1512853Sgabeblack@google.com  implied.  See the License for the specific language governing
1612853Sgabeblack@google.com  permissions and limitations under the License.
1712853Sgabeblack@google.com
1812853Sgabeblack@google.com *****************************************************************************/
1912853Sgabeblack@google.com
2012853Sgabeblack@google.com/*****************************************************************************
2112853Sgabeblack@google.com
2212853Sgabeblack@google.com  sc_fxdefs.h -
2312853Sgabeblack@google.com
2412853Sgabeblack@google.com  Original Author: Martin Janssen, Synopsys, Inc.
2512853Sgabeblack@google.com
2612853Sgabeblack@google.com *****************************************************************************/
2712853Sgabeblack@google.com
2812853Sgabeblack@google.com/*****************************************************************************
2912853Sgabeblack@google.com
3012853Sgabeblack@google.com  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
3112853Sgabeblack@google.com  changes you are making here.
3212853Sgabeblack@google.com
3312853Sgabeblack@google.com      Name, Affiliation, Date:
3412853Sgabeblack@google.com  Description of Modification:
3512853Sgabeblack@google.com
3612853Sgabeblack@google.com *****************************************************************************/
3712853Sgabeblack@google.com
3812853Sgabeblack@google.com// $Log: sc_fxdefs.h,v $
3912853Sgabeblack@google.com// Revision 1.1.1.1  2006/12/15 20:20:04  acg
4012853Sgabeblack@google.com// SystemC 2.3
4112853Sgabeblack@google.com//
4212853Sgabeblack@google.com// Revision 1.3  2006/01/13 18:53:57  acg
4312853Sgabeblack@google.com// Andy Goodrich: added $Log command so that CVS comments are reproduced in
4412853Sgabeblack@google.com// the source.
4512853Sgabeblack@google.com//
4612853Sgabeblack@google.com
4712853Sgabeblack@google.com#ifndef __SYSTEMC_EXT_DT_FX_SC_FXDEFS_HH__
4812853Sgabeblack@google.com#define __SYSTEMC_EXT_DT_FX_SC_FXDEFS_HH__
4912853Sgabeblack@google.com
5012853Sgabeblack@google.com#include "../../utils/sc_report_handler.hh"
5112853Sgabeblack@google.com#include "../int/sc_nbutils.hh"
5212853Sgabeblack@google.com
5312853Sgabeblack@google.comnamespace sc_dt
5412853Sgabeblack@google.com{
5512853Sgabeblack@google.com
5612853Sgabeblack@google.com// ----------------------------------------------------------------------------
5712853Sgabeblack@google.com//  ENUM : sc_enc
5812853Sgabeblack@google.com//
5912853Sgabeblack@google.com//  Enumeration of sign encodings.
6012853Sgabeblack@google.com// ----------------------------------------------------------------------------
6112853Sgabeblack@google.com
6212853Sgabeblack@google.comenum sc_enc
6312853Sgabeblack@google.com{
6412853Sgabeblack@google.com    SC_TC_, // two's complement
6512853Sgabeblack@google.com    SC_US_ // unsigned
6612853Sgabeblack@google.com};
6712853Sgabeblack@google.com
6812853Sgabeblack@google.comconst std::string to_string(sc_enc);
6912853Sgabeblack@google.com
7012853Sgabeblack@google.cominline ::std::ostream &
7112853Sgabeblack@google.comoperator << (::std::ostream &os, sc_enc enc)
7212853Sgabeblack@google.com{
7312853Sgabeblack@google.com    return os << to_string(enc);
7412853Sgabeblack@google.com}
7512853Sgabeblack@google.com
7612853Sgabeblack@google.com
7712853Sgabeblack@google.com// ----------------------------------------------------------------------------
7812853Sgabeblack@google.com//  ENUM : sc_q_mode
7912853Sgabeblack@google.com//
8012853Sgabeblack@google.com//  Enumeration of quantization modes.
8112853Sgabeblack@google.com// ----------------------------------------------------------------------------
8212853Sgabeblack@google.com
8312853Sgabeblack@google.comenum sc_q_mode
8412853Sgabeblack@google.com{
8512853Sgabeblack@google.com    SC_RND, // rounding to plus infinity
8612853Sgabeblack@google.com    SC_RND_ZERO, // rounding to zero
8712853Sgabeblack@google.com    SC_RND_MIN_INF, // rounding to minus infinity
8812853Sgabeblack@google.com    SC_RND_INF, // rounding to infinity
8912853Sgabeblack@google.com    SC_RND_CONV, // convergent rounding
9012853Sgabeblack@google.com    SC_TRN, // truncation
9112853Sgabeblack@google.com    SC_TRN_ZERO // truncation to zero
9212853Sgabeblack@google.com};
9312853Sgabeblack@google.com
9412853Sgabeblack@google.comconst std::string to_string(sc_q_mode);
9512853Sgabeblack@google.com
9612853Sgabeblack@google.cominline ::std::ostream &
9712853Sgabeblack@google.comoperator << (::std::ostream &os, sc_q_mode q_mode)
9812853Sgabeblack@google.com{
9912853Sgabeblack@google.com    return os << to_string(q_mode);
10012853Sgabeblack@google.com}
10112853Sgabeblack@google.com
10212853Sgabeblack@google.com
10312853Sgabeblack@google.com// ----------------------------------------------------------------------------
10412853Sgabeblack@google.com//  ENUM : sc_o_mode
10512853Sgabeblack@google.com//
10612853Sgabeblack@google.com//  Enumeration of overflow modes.
10712853Sgabeblack@google.com// ----------------------------------------------------------------------------
10812853Sgabeblack@google.com
10912853Sgabeblack@google.comenum sc_o_mode
11012853Sgabeblack@google.com{
11112853Sgabeblack@google.com    SC_SAT, // saturation
11212853Sgabeblack@google.com    SC_SAT_ZERO, // saturation to zero
11312853Sgabeblack@google.com    SC_SAT_SYM, // symmetrical saturation
11412853Sgabeblack@google.com    SC_WRAP, // wrap-around (*)
11512853Sgabeblack@google.com    SC_WRAP_SM // sign magnitude wrap-around (*)
11612853Sgabeblack@google.com};
11712853Sgabeblack@google.com
11812853Sgabeblack@google.com// (*) uses the number of saturated bits argument, see the documentation.
11912853Sgabeblack@google.com
12012853Sgabeblack@google.comconst std::string to_string( sc_o_mode );
12112853Sgabeblack@google.com
12212853Sgabeblack@google.cominline ::std::ostream &
12312853Sgabeblack@google.comoperator << (::std::ostream &os, sc_o_mode o_mode)
12412853Sgabeblack@google.com{
12512853Sgabeblack@google.com    return os << to_string(o_mode);
12612853Sgabeblack@google.com}
12712853Sgabeblack@google.com
12812853Sgabeblack@google.com
12912853Sgabeblack@google.com// ----------------------------------------------------------------------------
13012853Sgabeblack@google.com//  ENUM : sc_switch
13112853Sgabeblack@google.com//
13212853Sgabeblack@google.com//  Enumeration of switch states.
13312853Sgabeblack@google.com// ----------------------------------------------------------------------------
13412853Sgabeblack@google.com
13512853Sgabeblack@google.comenum sc_switch
13612853Sgabeblack@google.com{
13712853Sgabeblack@google.com    SC_OFF,
13812853Sgabeblack@google.com    SC_ON
13912853Sgabeblack@google.com};
14012853Sgabeblack@google.com
14112853Sgabeblack@google.comconst std::string to_string(sc_switch);
14212853Sgabeblack@google.com
14312853Sgabeblack@google.cominline ::std::ostream &
14412853Sgabeblack@google.comoperator << (::std::ostream &os, sc_switch sw)
14512853Sgabeblack@google.com{
14612853Sgabeblack@google.com    return os << to_string(sw);
14712853Sgabeblack@google.com}
14812853Sgabeblack@google.com
14912853Sgabeblack@google.com
15012853Sgabeblack@google.com// ----------------------------------------------------------------------------
15112853Sgabeblack@google.com//  ENUM : sc_fmt
15212853Sgabeblack@google.com//
15312853Sgabeblack@google.com//  Enumeration of formats for character string conversion.
15412853Sgabeblack@google.com// ----------------------------------------------------------------------------
15512853Sgabeblack@google.com
15612853Sgabeblack@google.comenum sc_fmt
15712853Sgabeblack@google.com{
15812853Sgabeblack@google.com    SC_F, // fixed
15912853Sgabeblack@google.com    SC_E // scientific
16012853Sgabeblack@google.com};
16112853Sgabeblack@google.com
16212853Sgabeblack@google.comconst std::string to_string(sc_fmt);
16312853Sgabeblack@google.com
16412853Sgabeblack@google.cominline ::std::ostream &
16512853Sgabeblack@google.comoperator << (::std::ostream &os, sc_fmt fmt)
16612853Sgabeblack@google.com{
16712853Sgabeblack@google.com    return os << to_string(fmt);
16812853Sgabeblack@google.com}
16912853Sgabeblack@google.com
17012853Sgabeblack@google.com
17112853Sgabeblack@google.com// ----------------------------------------------------------------------------
17212853Sgabeblack@google.com//  Built-in & default fixed-point type parameter values.
17312853Sgabeblack@google.com// ----------------------------------------------------------------------------
17412853Sgabeblack@google.com
17512853Sgabeblack@google.comconst int SC_BUILTIN_WL_ = 32;
17612853Sgabeblack@google.comconst int SC_BUILTIN_IWL_ = 32;
17712853Sgabeblack@google.comconst sc_q_mode SC_BUILTIN_Q_MODE_ = SC_TRN;
17812853Sgabeblack@google.comconst sc_o_mode SC_BUILTIN_O_MODE_ = SC_WRAP;
17912853Sgabeblack@google.comconst int SC_BUILTIN_N_BITS_ = 0;
18012853Sgabeblack@google.com
18112853Sgabeblack@google.comconst int SC_DEFAULT_WL_ = SC_BUILTIN_WL_;
18212853Sgabeblack@google.comconst int SC_DEFAULT_IWL_ = SC_BUILTIN_IWL_;
18312853Sgabeblack@google.comconst sc_q_mode SC_DEFAULT_Q_MODE_ = SC_BUILTIN_Q_MODE_;
18412853Sgabeblack@google.comconst sc_o_mode SC_DEFAULT_O_MODE_ = SC_BUILTIN_O_MODE_;
18512853Sgabeblack@google.comconst int SC_DEFAULT_N_BITS_ = SC_BUILTIN_N_BITS_;
18612853Sgabeblack@google.com
18712853Sgabeblack@google.com
18812853Sgabeblack@google.com// ----------------------------------------------------------------------------
18912853Sgabeblack@google.com//  Built-in & default fixed-point cast switch parameter values.
19012853Sgabeblack@google.com// ----------------------------------------------------------------------------
19112853Sgabeblack@google.com
19212853Sgabeblack@google.comconst sc_switch SC_BUILTIN_CAST_SWITCH_ = SC_ON;
19312853Sgabeblack@google.comconst sc_switch SC_DEFAULT_CAST_SWITCH_ = SC_BUILTIN_CAST_SWITCH_;
19412853Sgabeblack@google.com
19512853Sgabeblack@google.com
19612853Sgabeblack@google.com// ----------------------------------------------------------------------------
19712853Sgabeblack@google.com//  Built-in & default fixed-point value type parameter values.
19812853Sgabeblack@google.com// ----------------------------------------------------------------------------
19912853Sgabeblack@google.com
20012853Sgabeblack@google.comconst int SC_BUILTIN_DIV_WL_ = 64;
20112853Sgabeblack@google.comconst int SC_BUILTIN_CTE_WL_ = 64;
20212853Sgabeblack@google.comconst int SC_BUILTIN_MAX_WL_ = 1024;
20312853Sgabeblack@google.com
20412853Sgabeblack@google.com
20512853Sgabeblack@google.com#if defined(SC_FXDIV_WL) && (SC_FXDIV_WL > 0)
20612853Sgabeblack@google.comconst int SC_DEFAULT_DIV_WL_ = SC_FXDIV_WL;
20712853Sgabeblack@google.com#else
20812853Sgabeblack@google.comconst int SC_DEFAULT_DIV_WL_ = SC_BUILTIN_DIV_WL_;
20912853Sgabeblack@google.com#endif
21012853Sgabeblack@google.com
21112853Sgabeblack@google.com#if defined(SC_FXCTE_WL) && (SC_FXCTE_WL > 0)
21212853Sgabeblack@google.comconst int SC_DEFAULT_CTE_WL_ = SC_FXCTE_WL;
21312853Sgabeblack@google.com#else
21412853Sgabeblack@google.comconst int SC_DEFAULT_CTE_WL_ = SC_BUILTIN_CTE_WL_;
21512853Sgabeblack@google.com#endif
21612853Sgabeblack@google.com
21712853Sgabeblack@google.com#if defined(SC_FXMAX_WL) && (SC_FXMAX_WL > 0 || SC_FXMAX_WL == -1)
21812853Sgabeblack@google.comconst int SC_DEFAULT_MAX_WL_ = SC_FXMAX_WL;
21912853Sgabeblack@google.com#else
22012853Sgabeblack@google.comconst int SC_DEFAULT_MAX_WL_ = SC_BUILTIN_MAX_WL_;
22112853Sgabeblack@google.com#endif
22212853Sgabeblack@google.com
22312853Sgabeblack@google.com
22412853Sgabeblack@google.com// ----------------------------------------------------------------------------
22512853Sgabeblack@google.com//  Dedicated error reporting and checking.
22612853Sgabeblack@google.com// ----------------------------------------------------------------------------
22712853Sgabeblack@google.com
22812853Sgabeblack@google.com#define SC_ERROR_IF_IMPL_(cnd, id, msg) \
22912853Sgabeblack@google.com    do { \
23012853Sgabeblack@google.com        if (cnd) { \
23112853Sgabeblack@google.com            SC_REPORT_ERROR(id, msg); \
23212853Sgabeblack@google.com            sc_core::sc_abort(); /* can't recover from here */ \
23312853Sgabeblack@google.com        } \
23412853Sgabeblack@google.com    } while ( false )
23512853Sgabeblack@google.com
23612853Sgabeblack@google.com#ifdef DEBUG_SYSTEMC
23712853Sgabeblack@google.com#   define SC_ASSERT_(cnd, msg) \
23812853Sgabeblack@google.com    SC_ERROR_IF_IMPL_(!(cnd), "internal error", msg)
23912853Sgabeblack@google.com#else
24012853Sgabeblack@google.com#   define SC_ASSERT_(cnd, msg) (void(0))
24112853Sgabeblack@google.com#endif
24212853Sgabeblack@google.com
24312853Sgabeblack@google.com#define SC_ERROR_IF_(cnd,id) SC_ERROR_IF_IMPL_(cnd, id, 0)
24412853Sgabeblack@google.com
24512853Sgabeblack@google.com#define SC_CHECK_WL_(wl) SC_ERROR_IF_((wl) <= 0, \
24612853Sgabeblack@google.com        "total wordlength <= 0 is not valid")
24712853Sgabeblack@google.com
24812853Sgabeblack@google.com#define SC_CHECK_N_BITS_(n_bits) \
24912853Sgabeblack@google.com    SC_ERROR_IF_((n_bits) < 0, "number of bits < 0 is not valid")
25012853Sgabeblack@google.com
25112853Sgabeblack@google.com#define SC_CHECK_DIV_WL_(div_wl) \
25212853Sgabeblack@google.com    SC_ERROR_IF_((div_wl) <= 0, "division wordlength <= 0 is not valid")
25312853Sgabeblack@google.com
25412853Sgabeblack@google.com#define SC_CHECK_CTE_WL_(cte_wl) \
25512853Sgabeblack@google.com    SC_ERROR_IF_((cte_wl) <= 0, "constant wordlength <= 0 is not valid")
25612853Sgabeblack@google.com
25712853Sgabeblack@google.com#define SC_CHECK_MAX_WL_(max_wl) \
25812853Sgabeblack@google.com    SC_ERROR_IF_((max_wl) <= 0 && (max_wl) != -1, \
25912853Sgabeblack@google.com            "maximum wordlength <= 0 and != -1 is not valid")
26012853Sgabeblack@google.com
26112853Sgabeblack@google.com
26212853Sgabeblack@google.com// ----------------------------------------------------------------------------
26312853Sgabeblack@google.com//  Generic observer macros.
26412853Sgabeblack@google.com// ----------------------------------------------------------------------------
26512853Sgabeblack@google.com
26612853Sgabeblack@google.com#define SC_OBSERVER_(object, observer_type, event) \
26712853Sgabeblack@google.com{ \
26812853Sgabeblack@google.com    if ((object).observer() != 0) { \
26912853Sgabeblack@google.com        observer_type observer = (object).lock_observer(); \
27012853Sgabeblack@google.com        observer->event((object)); \
27112853Sgabeblack@google.com        (object).unlock_observer(observer); \
27212853Sgabeblack@google.com    } \
27312853Sgabeblack@google.com}
27412853Sgabeblack@google.com
27512853Sgabeblack@google.com#define SC_OBSERVER_DEFAULT_(observer_type) \
27612853Sgabeblack@google.com{ \
27712853Sgabeblack@google.com    if (m_observer == 0 && observer_type::default_observer != 0) \
27812853Sgabeblack@google.com        m_observer = (*observer_type::default_observer)(); \
27912853Sgabeblack@google.com}
28012853Sgabeblack@google.com
28112853Sgabeblack@google.com} // namespace sc_dt
28212853Sgabeblack@google.com
28312853Sgabeblack@google.com#endif // __SYSTEMC_EXT_DT_FX_SC_FXDEFS_HH__
284