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 5013322Sgabeblack@google.com#include "../../utils/messages.hh" 5112853Sgabeblack@google.com#include "../../utils/sc_report_handler.hh" 5212853Sgabeblack@google.com#include "../int/sc_nbutils.hh" 5313325Sgabeblack@google.com#include "messages.hh" 5412853Sgabeblack@google.com 5513197Sgabeblack@google.com#if ULONG_MAX > 0xffffffffUL 5613197Sgabeblack@google.com# define SC_LONG_64 1 5713197Sgabeblack@google.com#else 5813197Sgabeblack@google.com# define SC_LONG_64 0 5913197Sgabeblack@google.com#endif 6013197Sgabeblack@google.com 6112853Sgabeblack@google.comnamespace sc_dt 6212853Sgabeblack@google.com{ 6312853Sgabeblack@google.com 6412853Sgabeblack@google.com// ---------------------------------------------------------------------------- 6512853Sgabeblack@google.com// ENUM : sc_enc 6612853Sgabeblack@google.com// 6712853Sgabeblack@google.com// Enumeration of sign encodings. 6812853Sgabeblack@google.com// ---------------------------------------------------------------------------- 6912853Sgabeblack@google.com 7012853Sgabeblack@google.comenum sc_enc 7112853Sgabeblack@google.com{ 7212853Sgabeblack@google.com SC_TC_, // two's complement 7312853Sgabeblack@google.com SC_US_ // unsigned 7412853Sgabeblack@google.com}; 7512853Sgabeblack@google.com 7612853Sgabeblack@google.comconst std::string to_string(sc_enc); 7712853Sgabeblack@google.com 7812853Sgabeblack@google.cominline ::std::ostream & 7912853Sgabeblack@google.comoperator << (::std::ostream &os, sc_enc enc) 8012853Sgabeblack@google.com{ 8112853Sgabeblack@google.com return os << to_string(enc); 8212853Sgabeblack@google.com} 8312853Sgabeblack@google.com 8412853Sgabeblack@google.com 8512853Sgabeblack@google.com// ---------------------------------------------------------------------------- 8612853Sgabeblack@google.com// ENUM : sc_q_mode 8712853Sgabeblack@google.com// 8812853Sgabeblack@google.com// Enumeration of quantization modes. 8912853Sgabeblack@google.com// ---------------------------------------------------------------------------- 9012853Sgabeblack@google.com 9112853Sgabeblack@google.comenum sc_q_mode 9212853Sgabeblack@google.com{ 9312853Sgabeblack@google.com SC_RND, // rounding to plus infinity 9412853Sgabeblack@google.com SC_RND_ZERO, // rounding to zero 9512853Sgabeblack@google.com SC_RND_MIN_INF, // rounding to minus infinity 9612853Sgabeblack@google.com SC_RND_INF, // rounding to infinity 9712853Sgabeblack@google.com SC_RND_CONV, // convergent rounding 9812853Sgabeblack@google.com SC_TRN, // truncation 9912853Sgabeblack@google.com SC_TRN_ZERO // truncation to zero 10012853Sgabeblack@google.com}; 10112853Sgabeblack@google.com 10212853Sgabeblack@google.comconst std::string to_string(sc_q_mode); 10312853Sgabeblack@google.com 10412853Sgabeblack@google.cominline ::std::ostream & 10512853Sgabeblack@google.comoperator << (::std::ostream &os, sc_q_mode q_mode) 10612853Sgabeblack@google.com{ 10712853Sgabeblack@google.com return os << to_string(q_mode); 10812853Sgabeblack@google.com} 10912853Sgabeblack@google.com 11012853Sgabeblack@google.com 11112853Sgabeblack@google.com// ---------------------------------------------------------------------------- 11212853Sgabeblack@google.com// ENUM : sc_o_mode 11312853Sgabeblack@google.com// 11412853Sgabeblack@google.com// Enumeration of overflow modes. 11512853Sgabeblack@google.com// ---------------------------------------------------------------------------- 11612853Sgabeblack@google.com 11712853Sgabeblack@google.comenum sc_o_mode 11812853Sgabeblack@google.com{ 11912853Sgabeblack@google.com SC_SAT, // saturation 12012853Sgabeblack@google.com SC_SAT_ZERO, // saturation to zero 12112853Sgabeblack@google.com SC_SAT_SYM, // symmetrical saturation 12212853Sgabeblack@google.com SC_WRAP, // wrap-around (*) 12312853Sgabeblack@google.com SC_WRAP_SM // sign magnitude wrap-around (*) 12412853Sgabeblack@google.com}; 12512853Sgabeblack@google.com 12612853Sgabeblack@google.com// (*) uses the number of saturated bits argument, see the documentation. 12712853Sgabeblack@google.com 12812853Sgabeblack@google.comconst std::string to_string( sc_o_mode ); 12912853Sgabeblack@google.com 13012853Sgabeblack@google.cominline ::std::ostream & 13112853Sgabeblack@google.comoperator << (::std::ostream &os, sc_o_mode o_mode) 13212853Sgabeblack@google.com{ 13312853Sgabeblack@google.com return os << to_string(o_mode); 13412853Sgabeblack@google.com} 13512853Sgabeblack@google.com 13612853Sgabeblack@google.com 13712853Sgabeblack@google.com// ---------------------------------------------------------------------------- 13812853Sgabeblack@google.com// ENUM : sc_switch 13912853Sgabeblack@google.com// 14012853Sgabeblack@google.com// Enumeration of switch states. 14112853Sgabeblack@google.com// ---------------------------------------------------------------------------- 14212853Sgabeblack@google.com 14312853Sgabeblack@google.comenum sc_switch 14412853Sgabeblack@google.com{ 14512853Sgabeblack@google.com SC_OFF, 14612853Sgabeblack@google.com SC_ON 14712853Sgabeblack@google.com}; 14812853Sgabeblack@google.com 14912853Sgabeblack@google.comconst std::string to_string(sc_switch); 15012853Sgabeblack@google.com 15112853Sgabeblack@google.cominline ::std::ostream & 15212853Sgabeblack@google.comoperator << (::std::ostream &os, sc_switch sw) 15312853Sgabeblack@google.com{ 15412853Sgabeblack@google.com return os << to_string(sw); 15512853Sgabeblack@google.com} 15612853Sgabeblack@google.com 15712853Sgabeblack@google.com 15812853Sgabeblack@google.com// ---------------------------------------------------------------------------- 15912853Sgabeblack@google.com// ENUM : sc_fmt 16012853Sgabeblack@google.com// 16112853Sgabeblack@google.com// Enumeration of formats for character string conversion. 16212853Sgabeblack@google.com// ---------------------------------------------------------------------------- 16312853Sgabeblack@google.com 16412853Sgabeblack@google.comenum sc_fmt 16512853Sgabeblack@google.com{ 16612853Sgabeblack@google.com SC_F, // fixed 16712853Sgabeblack@google.com SC_E // scientific 16812853Sgabeblack@google.com}; 16912853Sgabeblack@google.com 17012853Sgabeblack@google.comconst std::string to_string(sc_fmt); 17112853Sgabeblack@google.com 17212853Sgabeblack@google.cominline ::std::ostream & 17312853Sgabeblack@google.comoperator << (::std::ostream &os, sc_fmt fmt) 17412853Sgabeblack@google.com{ 17512853Sgabeblack@google.com return os << to_string(fmt); 17612853Sgabeblack@google.com} 17712853Sgabeblack@google.com 17812853Sgabeblack@google.com 17912853Sgabeblack@google.com// ---------------------------------------------------------------------------- 18012853Sgabeblack@google.com// Built-in & default fixed-point type parameter values. 18112853Sgabeblack@google.com// ---------------------------------------------------------------------------- 18212853Sgabeblack@google.com 18312853Sgabeblack@google.comconst int SC_BUILTIN_WL_ = 32; 18412853Sgabeblack@google.comconst int SC_BUILTIN_IWL_ = 32; 18512853Sgabeblack@google.comconst sc_q_mode SC_BUILTIN_Q_MODE_ = SC_TRN; 18612853Sgabeblack@google.comconst sc_o_mode SC_BUILTIN_O_MODE_ = SC_WRAP; 18712853Sgabeblack@google.comconst int SC_BUILTIN_N_BITS_ = 0; 18812853Sgabeblack@google.com 18912853Sgabeblack@google.comconst int SC_DEFAULT_WL_ = SC_BUILTIN_WL_; 19012853Sgabeblack@google.comconst int SC_DEFAULT_IWL_ = SC_BUILTIN_IWL_; 19112853Sgabeblack@google.comconst sc_q_mode SC_DEFAULT_Q_MODE_ = SC_BUILTIN_Q_MODE_; 19212853Sgabeblack@google.comconst sc_o_mode SC_DEFAULT_O_MODE_ = SC_BUILTIN_O_MODE_; 19312853Sgabeblack@google.comconst int SC_DEFAULT_N_BITS_ = SC_BUILTIN_N_BITS_; 19412853Sgabeblack@google.com 19512853Sgabeblack@google.com 19612853Sgabeblack@google.com// ---------------------------------------------------------------------------- 19712853Sgabeblack@google.com// Built-in & default fixed-point cast switch parameter values. 19812853Sgabeblack@google.com// ---------------------------------------------------------------------------- 19912853Sgabeblack@google.com 20012853Sgabeblack@google.comconst sc_switch SC_BUILTIN_CAST_SWITCH_ = SC_ON; 20112853Sgabeblack@google.comconst sc_switch SC_DEFAULT_CAST_SWITCH_ = SC_BUILTIN_CAST_SWITCH_; 20212853Sgabeblack@google.com 20312853Sgabeblack@google.com 20412853Sgabeblack@google.com// ---------------------------------------------------------------------------- 20512853Sgabeblack@google.com// Built-in & default fixed-point value type parameter values. 20612853Sgabeblack@google.com// ---------------------------------------------------------------------------- 20712853Sgabeblack@google.com 20812853Sgabeblack@google.comconst int SC_BUILTIN_DIV_WL_ = 64; 20912853Sgabeblack@google.comconst int SC_BUILTIN_CTE_WL_ = 64; 21012853Sgabeblack@google.comconst int SC_BUILTIN_MAX_WL_ = 1024; 21112853Sgabeblack@google.com 21212853Sgabeblack@google.com 21312853Sgabeblack@google.com#if defined(SC_FXDIV_WL) && (SC_FXDIV_WL > 0) 21412853Sgabeblack@google.comconst int SC_DEFAULT_DIV_WL_ = SC_FXDIV_WL; 21512853Sgabeblack@google.com#else 21612853Sgabeblack@google.comconst int SC_DEFAULT_DIV_WL_ = SC_BUILTIN_DIV_WL_; 21712853Sgabeblack@google.com#endif 21812853Sgabeblack@google.com 21912853Sgabeblack@google.com#if defined(SC_FXCTE_WL) && (SC_FXCTE_WL > 0) 22012853Sgabeblack@google.comconst int SC_DEFAULT_CTE_WL_ = SC_FXCTE_WL; 22112853Sgabeblack@google.com#else 22212853Sgabeblack@google.comconst int SC_DEFAULT_CTE_WL_ = SC_BUILTIN_CTE_WL_; 22312853Sgabeblack@google.com#endif 22412853Sgabeblack@google.com 22512853Sgabeblack@google.com#if defined(SC_FXMAX_WL) && (SC_FXMAX_WL > 0 || SC_FXMAX_WL == -1) 22612853Sgabeblack@google.comconst int SC_DEFAULT_MAX_WL_ = SC_FXMAX_WL; 22712853Sgabeblack@google.com#else 22812853Sgabeblack@google.comconst int SC_DEFAULT_MAX_WL_ = SC_BUILTIN_MAX_WL_; 22912853Sgabeblack@google.com#endif 23012853Sgabeblack@google.com 23112853Sgabeblack@google.com 23212853Sgabeblack@google.com// ---------------------------------------------------------------------------- 23312853Sgabeblack@google.com// Dedicated error reporting and checking. 23412853Sgabeblack@google.com// ---------------------------------------------------------------------------- 23512853Sgabeblack@google.com 23612853Sgabeblack@google.com#define SC_ERROR_IF_IMPL_(cnd, id, msg) \ 23712853Sgabeblack@google.com do { \ 23812853Sgabeblack@google.com if (cnd) { \ 23912853Sgabeblack@google.com SC_REPORT_ERROR(id, msg); \ 24012853Sgabeblack@google.com sc_core::sc_abort(); /* can't recover from here */ \ 24112853Sgabeblack@google.com } \ 24212853Sgabeblack@google.com } while ( false ) 24312853Sgabeblack@google.com 24412853Sgabeblack@google.com#ifdef DEBUG_SYSTEMC 24512853Sgabeblack@google.com# define SC_ASSERT_(cnd, msg) \ 24613322Sgabeblack@google.com SC_ERROR_IF_IMPL_(!(cnd), sc_core::SC_ID_INTERNAL_ERROR_, msg) 24712853Sgabeblack@google.com#else 24812853Sgabeblack@google.com# define SC_ASSERT_(cnd, msg) (void(0)) 24912853Sgabeblack@google.com#endif 25012853Sgabeblack@google.com 25112853Sgabeblack@google.com#define SC_ERROR_IF_(cnd,id) SC_ERROR_IF_IMPL_(cnd, id, 0) 25212853Sgabeblack@google.com 25313325Sgabeblack@google.com#define SC_CHECK_WL_(wl) SC_ERROR_IF_((wl) <= 0, sc_core::SC_ID_INVALID_WL_) 25412853Sgabeblack@google.com 25512853Sgabeblack@google.com#define SC_CHECK_N_BITS_(n_bits) \ 25613325Sgabeblack@google.com SC_ERROR_IF_((n_bits) < 0, sc_core::SC_ID_INVALID_N_BITS_) 25712853Sgabeblack@google.com 25812853Sgabeblack@google.com#define SC_CHECK_DIV_WL_(div_wl) \ 25913325Sgabeblack@google.com SC_ERROR_IF_((div_wl) <= 0, sc_core::SC_ID_INVALID_DIV_WL_) 26012853Sgabeblack@google.com 26112853Sgabeblack@google.com#define SC_CHECK_CTE_WL_(cte_wl) \ 26213325Sgabeblack@google.com SC_ERROR_IF_((cte_wl) <= 0, sc_core::SC_ID_INVALID_CTE_WL_) 26312853Sgabeblack@google.com 26412853Sgabeblack@google.com#define SC_CHECK_MAX_WL_(max_wl) \ 26512853Sgabeblack@google.com SC_ERROR_IF_((max_wl) <= 0 && (max_wl) != -1, \ 26613325Sgabeblack@google.com sc_core::SC_ID_INVALID_MAX_WL_) 26712853Sgabeblack@google.com 26812853Sgabeblack@google.com 26912853Sgabeblack@google.com// ---------------------------------------------------------------------------- 27012853Sgabeblack@google.com// Generic observer macros. 27112853Sgabeblack@google.com// ---------------------------------------------------------------------------- 27212853Sgabeblack@google.com 27312853Sgabeblack@google.com#define SC_OBSERVER_(object, observer_type, event) \ 27412853Sgabeblack@google.com{ \ 27512853Sgabeblack@google.com if ((object).observer() != 0) { \ 27612853Sgabeblack@google.com observer_type observer = (object).lock_observer(); \ 27712853Sgabeblack@google.com observer->event((object)); \ 27812853Sgabeblack@google.com (object).unlock_observer(observer); \ 27912853Sgabeblack@google.com } \ 28012853Sgabeblack@google.com} 28112853Sgabeblack@google.com 28212853Sgabeblack@google.com#define SC_OBSERVER_DEFAULT_(observer_type) \ 28312853Sgabeblack@google.com{ \ 28412853Sgabeblack@google.com if (m_observer == 0 && observer_type::default_observer != 0) \ 28512853Sgabeblack@google.com m_observer = (*observer_type::default_observer)(); \ 28612853Sgabeblack@google.com} 28712853Sgabeblack@google.com 28812853Sgabeblack@google.com} // namespace sc_dt 28912853Sgabeblack@google.com 29012853Sgabeblack@google.com#endif // __SYSTEMC_EXT_DT_FX_SC_FXDEFS_HH__ 291