sc_fxdefs.hh revision 13322
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/messages.hh" 51#include "../../utils/sc_report_handler.hh" 52#include "../int/sc_nbutils.hh" 53 54#if ULONG_MAX > 0xffffffffUL 55# define SC_LONG_64 1 56#else 57# define SC_LONG_64 0 58#endif 59 60namespace sc_dt 61{ 62 63// ---------------------------------------------------------------------------- 64// ENUM : sc_enc 65// 66// Enumeration of sign encodings. 67// ---------------------------------------------------------------------------- 68 69enum sc_enc 70{ 71 SC_TC_, // two's complement 72 SC_US_ // unsigned 73}; 74 75const std::string to_string(sc_enc); 76 77inline ::std::ostream & 78operator << (::std::ostream &os, sc_enc enc) 79{ 80 return os << to_string(enc); 81} 82 83 84// ---------------------------------------------------------------------------- 85// ENUM : sc_q_mode 86// 87// Enumeration of quantization modes. 88// ---------------------------------------------------------------------------- 89 90enum sc_q_mode 91{ 92 SC_RND, // rounding to plus infinity 93 SC_RND_ZERO, // rounding to zero 94 SC_RND_MIN_INF, // rounding to minus infinity 95 SC_RND_INF, // rounding to infinity 96 SC_RND_CONV, // convergent rounding 97 SC_TRN, // truncation 98 SC_TRN_ZERO // truncation to zero 99}; 100 101const std::string to_string(sc_q_mode); 102 103inline ::std::ostream & 104operator << (::std::ostream &os, sc_q_mode q_mode) 105{ 106 return os << to_string(q_mode); 107} 108 109 110// ---------------------------------------------------------------------------- 111// ENUM : sc_o_mode 112// 113// Enumeration of overflow modes. 114// ---------------------------------------------------------------------------- 115 116enum sc_o_mode 117{ 118 SC_SAT, // saturation 119 SC_SAT_ZERO, // saturation to zero 120 SC_SAT_SYM, // symmetrical saturation 121 SC_WRAP, // wrap-around (*) 122 SC_WRAP_SM // sign magnitude wrap-around (*) 123}; 124 125// (*) uses the number of saturated bits argument, see the documentation. 126 127const std::string to_string( sc_o_mode ); 128 129inline ::std::ostream & 130operator << (::std::ostream &os, sc_o_mode o_mode) 131{ 132 return os << to_string(o_mode); 133} 134 135 136// ---------------------------------------------------------------------------- 137// ENUM : sc_switch 138// 139// Enumeration of switch states. 140// ---------------------------------------------------------------------------- 141 142enum sc_switch 143{ 144 SC_OFF, 145 SC_ON 146}; 147 148const std::string to_string(sc_switch); 149 150inline ::std::ostream & 151operator << (::std::ostream &os, sc_switch sw) 152{ 153 return os << to_string(sw); 154} 155 156 157// ---------------------------------------------------------------------------- 158// ENUM : sc_fmt 159// 160// Enumeration of formats for character string conversion. 161// ---------------------------------------------------------------------------- 162 163enum sc_fmt 164{ 165 SC_F, // fixed 166 SC_E // scientific 167}; 168 169const std::string to_string(sc_fmt); 170 171inline ::std::ostream & 172operator << (::std::ostream &os, sc_fmt fmt) 173{ 174 return os << to_string(fmt); 175} 176 177 178// ---------------------------------------------------------------------------- 179// Built-in & default fixed-point type parameter values. 180// ---------------------------------------------------------------------------- 181 182const int SC_BUILTIN_WL_ = 32; 183const int SC_BUILTIN_IWL_ = 32; 184const sc_q_mode SC_BUILTIN_Q_MODE_ = SC_TRN; 185const sc_o_mode SC_BUILTIN_O_MODE_ = SC_WRAP; 186const int SC_BUILTIN_N_BITS_ = 0; 187 188const int SC_DEFAULT_WL_ = SC_BUILTIN_WL_; 189const int SC_DEFAULT_IWL_ = SC_BUILTIN_IWL_; 190const sc_q_mode SC_DEFAULT_Q_MODE_ = SC_BUILTIN_Q_MODE_; 191const sc_o_mode SC_DEFAULT_O_MODE_ = SC_BUILTIN_O_MODE_; 192const int SC_DEFAULT_N_BITS_ = SC_BUILTIN_N_BITS_; 193 194 195// ---------------------------------------------------------------------------- 196// Built-in & default fixed-point cast switch parameter values. 197// ---------------------------------------------------------------------------- 198 199const sc_switch SC_BUILTIN_CAST_SWITCH_ = SC_ON; 200const sc_switch SC_DEFAULT_CAST_SWITCH_ = SC_BUILTIN_CAST_SWITCH_; 201 202 203// ---------------------------------------------------------------------------- 204// Built-in & default fixed-point value type parameter values. 205// ---------------------------------------------------------------------------- 206 207const int SC_BUILTIN_DIV_WL_ = 64; 208const int SC_BUILTIN_CTE_WL_ = 64; 209const int SC_BUILTIN_MAX_WL_ = 1024; 210 211 212#if defined(SC_FXDIV_WL) && (SC_FXDIV_WL > 0) 213const int SC_DEFAULT_DIV_WL_ = SC_FXDIV_WL; 214#else 215const int SC_DEFAULT_DIV_WL_ = SC_BUILTIN_DIV_WL_; 216#endif 217 218#if defined(SC_FXCTE_WL) && (SC_FXCTE_WL > 0) 219const int SC_DEFAULT_CTE_WL_ = SC_FXCTE_WL; 220#else 221const int SC_DEFAULT_CTE_WL_ = SC_BUILTIN_CTE_WL_; 222#endif 223 224#if defined(SC_FXMAX_WL) && (SC_FXMAX_WL > 0 || SC_FXMAX_WL == -1) 225const int SC_DEFAULT_MAX_WL_ = SC_FXMAX_WL; 226#else 227const int SC_DEFAULT_MAX_WL_ = SC_BUILTIN_MAX_WL_; 228#endif 229 230 231// ---------------------------------------------------------------------------- 232// Dedicated error reporting and checking. 233// ---------------------------------------------------------------------------- 234 235#define SC_ERROR_IF_IMPL_(cnd, id, msg) \ 236 do { \ 237 if (cnd) { \ 238 SC_REPORT_ERROR(id, msg); \ 239 sc_core::sc_abort(); /* can't recover from here */ \ 240 } \ 241 } while ( false ) 242 243#ifdef DEBUG_SYSTEMC 244# define SC_ASSERT_(cnd, msg) \ 245 SC_ERROR_IF_IMPL_(!(cnd), sc_core::SC_ID_INTERNAL_ERROR_, msg) 246#else 247# define SC_ASSERT_(cnd, msg) (void(0)) 248#endif 249 250#define SC_ERROR_IF_(cnd,id) SC_ERROR_IF_IMPL_(cnd, id, 0) 251 252#define SC_CHECK_WL_(wl) SC_ERROR_IF_((wl) <= 0, \ 253 "(E300) total wordlength <= 0 is not valid") 254 255#define SC_CHECK_N_BITS_(n_bits) \ 256 SC_ERROR_IF_((n_bits) < 0, "number of bits < 0 is not valid") 257 258#define SC_CHECK_DIV_WL_(div_wl) \ 259 SC_ERROR_IF_((div_wl) <= 0, "division wordlength <= 0 is not valid") 260 261#define SC_CHECK_CTE_WL_(cte_wl) \ 262 SC_ERROR_IF_((cte_wl) <= 0, "constant wordlength <= 0 is not valid") 263 264#define SC_CHECK_MAX_WL_(max_wl) \ 265 SC_ERROR_IF_((max_wl) <= 0 && (max_wl) != -1, \ 266 "maximum wordlength <= 0 and != -1 is not valid") 267 268 269// ---------------------------------------------------------------------------- 270// Generic observer macros. 271// ---------------------------------------------------------------------------- 272 273#define SC_OBSERVER_(object, observer_type, event) \ 274{ \ 275 if ((object).observer() != 0) { \ 276 observer_type observer = (object).lock_observer(); \ 277 observer->event((object)); \ 278 (object).unlock_observer(observer); \ 279 } \ 280} 281 282#define SC_OBSERVER_DEFAULT_(observer_type) \ 283{ \ 284 if (m_observer == 0 && observer_type::default_observer != 0) \ 285 m_observer = (*observer_type::default_observer)(); \ 286} 287 288} // namespace sc_dt 289 290#endif // __SYSTEMC_EXT_DT_FX_SC_FXDEFS_HH__ 291