sc_fxdefs.hh revision 13197
1/***************************************************************************** 2 3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 4 more contributor license agreements. See the NOTICE file distributed 5 with this work for additional information regarding copyright ownership. 6 Accellera licenses this file to you under the Apache License, Version 2.0 7 (the "License"); you may not use this file except in compliance with the 8 License. You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 15 implied. See the License for the specific language governing 16 permissions and limitations under the License. 17 18 *****************************************************************************/ 19 20/***************************************************************************** 21 22 sc_fxdefs.h - 23 24 Original Author: Martin Janssen, Synopsys, Inc. 25 26 *****************************************************************************/ 27 28/***************************************************************************** 29 30 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 31 changes you are making here. 32 33 Name, Affiliation, Date: 34 Description of Modification: 35 36 *****************************************************************************/ 37 38// $Log: sc_fxdefs.h,v $ 39// Revision 1.1.1.1 2006/12/15 20:20:04 acg 40// SystemC 2.3 41// 42// Revision 1.3 2006/01/13 18:53:57 acg 43// Andy Goodrich: added $Log command so that CVS comments are reproduced in 44// the source. 45// 46 47#ifndef __SYSTEMC_EXT_DT_FX_SC_FXDEFS_HH__ 48#define __SYSTEMC_EXT_DT_FX_SC_FXDEFS_HH__ 49 50#include "../../utils/sc_report_handler.hh" 51#include "../int/sc_nbutils.hh" 52 53#if ULONG_MAX > 0xffffffffUL 54# define SC_LONG_64 1 55#else 56# define SC_LONG_64 0 57#endif 58 59namespace sc_dt 60{ 61 62// ---------------------------------------------------------------------------- 63// ENUM : sc_enc 64// 65// Enumeration of sign encodings. 66// ---------------------------------------------------------------------------- 67 68enum sc_enc 69{ 70 SC_TC_, // two's complement 71 SC_US_ // unsigned 72}; 73 74const std::string to_string(sc_enc); 75 76inline ::std::ostream & 77operator << (::std::ostream &os, sc_enc enc) 78{ 79 return os << to_string(enc); 80} 81 82 83// ---------------------------------------------------------------------------- 84// ENUM : sc_q_mode 85// 86// Enumeration of quantization modes. 87// ---------------------------------------------------------------------------- 88 89enum sc_q_mode 90{ 91 SC_RND, // rounding to plus infinity 92 SC_RND_ZERO, // rounding to zero 93 SC_RND_MIN_INF, // rounding to minus infinity 94 SC_RND_INF, // rounding to infinity 95 SC_RND_CONV, // convergent rounding 96 SC_TRN, // truncation 97 SC_TRN_ZERO // truncation to zero 98}; 99 100const std::string to_string(sc_q_mode); 101 102inline ::std::ostream & 103operator << (::std::ostream &os, sc_q_mode q_mode) 104{ 105 return os << to_string(q_mode); 106} 107 108 109// ---------------------------------------------------------------------------- 110// ENUM : sc_o_mode 111// 112// Enumeration of overflow modes. 113// ---------------------------------------------------------------------------- 114 115enum sc_o_mode 116{ 117 SC_SAT, // saturation 118 SC_SAT_ZERO, // saturation to zero 119 SC_SAT_SYM, // symmetrical saturation 120 SC_WRAP, // wrap-around (*) 121 SC_WRAP_SM // sign magnitude wrap-around (*) 122}; 123 124// (*) uses the number of saturated bits argument, see the documentation. 125 126const std::string to_string( sc_o_mode ); 127 128inline ::std::ostream & 129operator << (::std::ostream &os, sc_o_mode o_mode) 130{ 131 return os << to_string(o_mode); 132} 133 134 135// ---------------------------------------------------------------------------- 136// ENUM : sc_switch 137// 138// Enumeration of switch states. 139// ---------------------------------------------------------------------------- 140 141enum sc_switch 142{ 143 SC_OFF, 144 SC_ON 145}; 146 147const std::string to_string(sc_switch); 148 149inline ::std::ostream & 150operator << (::std::ostream &os, sc_switch sw) 151{ 152 return os << to_string(sw); 153} 154 155 156// ---------------------------------------------------------------------------- 157// ENUM : sc_fmt 158// 159// Enumeration of formats for character string conversion. 160// ---------------------------------------------------------------------------- 161 162enum sc_fmt 163{ 164 SC_F, // fixed 165 SC_E // scientific 166}; 167 168const std::string to_string(sc_fmt); 169 170inline ::std::ostream & 171operator << (::std::ostream &os, sc_fmt fmt) 172{ 173 return os << to_string(fmt); 174} 175 176 177// ---------------------------------------------------------------------------- 178// Built-in & default fixed-point type parameter values. 179// ---------------------------------------------------------------------------- 180 181const int SC_BUILTIN_WL_ = 32; 182const int SC_BUILTIN_IWL_ = 32; 183const sc_q_mode SC_BUILTIN_Q_MODE_ = SC_TRN; 184const sc_o_mode SC_BUILTIN_O_MODE_ = SC_WRAP; 185const int SC_BUILTIN_N_BITS_ = 0; 186 187const int SC_DEFAULT_WL_ = SC_BUILTIN_WL_; 188const int SC_DEFAULT_IWL_ = SC_BUILTIN_IWL_; 189const sc_q_mode SC_DEFAULT_Q_MODE_ = SC_BUILTIN_Q_MODE_; 190const sc_o_mode SC_DEFAULT_O_MODE_ = SC_BUILTIN_O_MODE_; 191const int SC_DEFAULT_N_BITS_ = SC_BUILTIN_N_BITS_; 192 193 194// ---------------------------------------------------------------------------- 195// Built-in & default fixed-point cast switch parameter values. 196// ---------------------------------------------------------------------------- 197 198const sc_switch SC_BUILTIN_CAST_SWITCH_ = SC_ON; 199const sc_switch SC_DEFAULT_CAST_SWITCH_ = SC_BUILTIN_CAST_SWITCH_; 200 201 202// ---------------------------------------------------------------------------- 203// Built-in & default fixed-point value type parameter values. 204// ---------------------------------------------------------------------------- 205 206const int SC_BUILTIN_DIV_WL_ = 64; 207const int SC_BUILTIN_CTE_WL_ = 64; 208const int SC_BUILTIN_MAX_WL_ = 1024; 209 210 211#if defined(SC_FXDIV_WL) && (SC_FXDIV_WL > 0) 212const int SC_DEFAULT_DIV_WL_ = SC_FXDIV_WL; 213#else 214const int SC_DEFAULT_DIV_WL_ = SC_BUILTIN_DIV_WL_; 215#endif 216 217#if defined(SC_FXCTE_WL) && (SC_FXCTE_WL > 0) 218const int SC_DEFAULT_CTE_WL_ = SC_FXCTE_WL; 219#else 220const int SC_DEFAULT_CTE_WL_ = SC_BUILTIN_CTE_WL_; 221#endif 222 223#if defined(SC_FXMAX_WL) && (SC_FXMAX_WL > 0 || SC_FXMAX_WL == -1) 224const int SC_DEFAULT_MAX_WL_ = SC_FXMAX_WL; 225#else 226const int SC_DEFAULT_MAX_WL_ = SC_BUILTIN_MAX_WL_; 227#endif 228 229 230// ---------------------------------------------------------------------------- 231// Dedicated error reporting and checking. 232// ---------------------------------------------------------------------------- 233 234#define SC_ERROR_IF_IMPL_(cnd, id, msg) \ 235 do { \ 236 if (cnd) { \ 237 SC_REPORT_ERROR(id, msg); \ 238 sc_core::sc_abort(); /* can't recover from here */ \ 239 } \ 240 } while ( false ) 241 242#ifdef DEBUG_SYSTEMC 243# define SC_ASSERT_(cnd, msg) \ 244 SC_ERROR_IF_IMPL_(!(cnd), "internal error", msg) 245#else 246# define SC_ASSERT_(cnd, msg) (void(0)) 247#endif 248 249#define SC_ERROR_IF_(cnd,id) SC_ERROR_IF_IMPL_(cnd, id, 0) 250 251#define SC_CHECK_WL_(wl) SC_ERROR_IF_((wl) <= 0, \ 252 "(E300) total wordlength <= 0 is not valid") 253 254#define SC_CHECK_N_BITS_(n_bits) \ 255 SC_ERROR_IF_((n_bits) < 0, "number of bits < 0 is not valid") 256 257#define SC_CHECK_DIV_WL_(div_wl) \ 258 SC_ERROR_IF_((div_wl) <= 0, "division wordlength <= 0 is not valid") 259 260#define SC_CHECK_CTE_WL_(cte_wl) \ 261 SC_ERROR_IF_((cte_wl) <= 0, "constant wordlength <= 0 is not valid") 262 263#define SC_CHECK_MAX_WL_(max_wl) \ 264 SC_ERROR_IF_((max_wl) <= 0 && (max_wl) != -1, \ 265 "maximum wordlength <= 0 and != -1 is not valid") 266 267 268// ---------------------------------------------------------------------------- 269// Generic observer macros. 270// ---------------------------------------------------------------------------- 271 272#define SC_OBSERVER_(object, observer_type, event) \ 273{ \ 274 if ((object).observer() != 0) { \ 275 observer_type observer = (object).lock_observer(); \ 276 observer->event((object)); \ 277 (object).unlock_observer(observer); \ 278 } \ 279} 280 281#define SC_OBSERVER_DEFAULT_(observer_type) \ 282{ \ 283 if (m_observer == 0 && observer_type::default_observer != 0) \ 284 m_observer = (*observer_type::default_observer)(); \ 285} 286 287} // namespace sc_dt 288 289#endif // __SYSTEMC_EXT_DT_FX_SC_FXDEFS_HH__ 290