From 5ee040a534d422ee08918ef49d55620184df7120 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Tue, 22 May 2018 02:21:17 -0700 Subject: Systemc: Port over all of the systemc "datatype" headers. These are the headers originally written by Accellera with a few modifications. Most significantly, I went through and mostly (but not entirely) manually editted them to conform to gem5 style and to be more self consistent. Second, I resolved some macros which optionally select features. I removed support for deprecated functions, and otherwise enabled everything. The actual implementation behind these headers will also be ported over, but in a subsequent change. Change-Id: I203d3f6c8a3af9120b946001d01defbb0643a6b6 Reviewed-on: https://gem5-review.googlesource.com/10843 Reviewed-by: Gabe Black Maintainer: Gabe Black --- src/systemc/ext/dt/fx/sc_fxdefs.hh | 283 +++++++++++++++++++++++++++++++++++++ 1 file changed, 283 insertions(+) create mode 100644 src/systemc/ext/dt/fx/sc_fxdefs.hh (limited to 'src/systemc/ext/dt/fx/sc_fxdefs.hh') diff --git a/src/systemc/ext/dt/fx/sc_fxdefs.hh b/src/systemc/ext/dt/fx/sc_fxdefs.hh new file mode 100644 index 000000000..0d76df6e2 --- /dev/null +++ b/src/systemc/ext/dt/fx/sc_fxdefs.hh @@ -0,0 +1,283 @@ +/***************************************************************************** + + Licensed to Accellera Systems Initiative Inc. (Accellera) under one or + more contributor license agreements. See the NOTICE file distributed + with this work for additional information regarding copyright ownership. + Accellera licenses this file to you under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with the + License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied. See the License for the specific language governing + permissions and limitations under the License. + + *****************************************************************************/ + +/***************************************************************************** + + sc_fxdefs.h - + + 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_fxdefs.h,v $ +// Revision 1.1.1.1 2006/12/15 20:20:04 acg +// SystemC 2.3 +// +// Revision 1.3 2006/01/13 18:53:57 acg +// Andy Goodrich: added $Log command so that CVS comments are reproduced in +// the source. +// + +#ifndef __SYSTEMC_EXT_DT_FX_SC_FXDEFS_HH__ +#define __SYSTEMC_EXT_DT_FX_SC_FXDEFS_HH__ + +#include "../../utils/sc_report_handler.hh" +#include "../int/sc_nbutils.hh" + +namespace sc_dt +{ + +// ---------------------------------------------------------------------------- +// ENUM : sc_enc +// +// Enumeration of sign encodings. +// ---------------------------------------------------------------------------- + +enum sc_enc +{ + SC_TC_, // two's complement + SC_US_ // unsigned +}; + +const std::string to_string(sc_enc); + +inline ::std::ostream & +operator << (::std::ostream &os, sc_enc enc) +{ + return os << to_string(enc); +} + + +// ---------------------------------------------------------------------------- +// ENUM : sc_q_mode +// +// Enumeration of quantization modes. +// ---------------------------------------------------------------------------- + +enum sc_q_mode +{ + SC_RND, // rounding to plus infinity + SC_RND_ZERO, // rounding to zero + SC_RND_MIN_INF, // rounding to minus infinity + SC_RND_INF, // rounding to infinity + SC_RND_CONV, // convergent rounding + SC_TRN, // truncation + SC_TRN_ZERO // truncation to zero +}; + +const std::string to_string(sc_q_mode); + +inline ::std::ostream & +operator << (::std::ostream &os, sc_q_mode q_mode) +{ + return os << to_string(q_mode); +} + + +// ---------------------------------------------------------------------------- +// ENUM : sc_o_mode +// +// Enumeration of overflow modes. +// ---------------------------------------------------------------------------- + +enum sc_o_mode +{ + SC_SAT, // saturation + SC_SAT_ZERO, // saturation to zero + SC_SAT_SYM, // symmetrical saturation + SC_WRAP, // wrap-around (*) + SC_WRAP_SM // sign magnitude wrap-around (*) +}; + +// (*) uses the number of saturated bits argument, see the documentation. + +const std::string to_string( sc_o_mode ); + +inline ::std::ostream & +operator << (::std::ostream &os, sc_o_mode o_mode) +{ + return os << to_string(o_mode); +} + + +// ---------------------------------------------------------------------------- +// ENUM : sc_switch +// +// Enumeration of switch states. +// ---------------------------------------------------------------------------- + +enum sc_switch +{ + SC_OFF, + SC_ON +}; + +const std::string to_string(sc_switch); + +inline ::std::ostream & +operator << (::std::ostream &os, sc_switch sw) +{ + return os << to_string(sw); +} + + +// ---------------------------------------------------------------------------- +// ENUM : sc_fmt +// +// Enumeration of formats for character string conversion. +// ---------------------------------------------------------------------------- + +enum sc_fmt +{ + SC_F, // fixed + SC_E // scientific +}; + +const std::string to_string(sc_fmt); + +inline ::std::ostream & +operator << (::std::ostream &os, sc_fmt fmt) +{ + return os << to_string(fmt); +} + + +// ---------------------------------------------------------------------------- +// Built-in & default fixed-point type parameter values. +// ---------------------------------------------------------------------------- + +const int SC_BUILTIN_WL_ = 32; +const int SC_BUILTIN_IWL_ = 32; +const sc_q_mode SC_BUILTIN_Q_MODE_ = SC_TRN; +const sc_o_mode SC_BUILTIN_O_MODE_ = SC_WRAP; +const int SC_BUILTIN_N_BITS_ = 0; + +const int SC_DEFAULT_WL_ = SC_BUILTIN_WL_; +const int SC_DEFAULT_IWL_ = SC_BUILTIN_IWL_; +const sc_q_mode SC_DEFAULT_Q_MODE_ = SC_BUILTIN_Q_MODE_; +const sc_o_mode SC_DEFAULT_O_MODE_ = SC_BUILTIN_O_MODE_; +const int SC_DEFAULT_N_BITS_ = SC_BUILTIN_N_BITS_; + + +// ---------------------------------------------------------------------------- +// Built-in & default fixed-point cast switch parameter values. +// ---------------------------------------------------------------------------- + +const sc_switch SC_BUILTIN_CAST_SWITCH_ = SC_ON; +const sc_switch SC_DEFAULT_CAST_SWITCH_ = SC_BUILTIN_CAST_SWITCH_; + + +// ---------------------------------------------------------------------------- +// Built-in & default fixed-point value type parameter values. +// ---------------------------------------------------------------------------- + +const int SC_BUILTIN_DIV_WL_ = 64; +const int SC_BUILTIN_CTE_WL_ = 64; +const int SC_BUILTIN_MAX_WL_ = 1024; + + +#if defined(SC_FXDIV_WL) && (SC_FXDIV_WL > 0) +const int SC_DEFAULT_DIV_WL_ = SC_FXDIV_WL; +#else +const int SC_DEFAULT_DIV_WL_ = SC_BUILTIN_DIV_WL_; +#endif + +#if defined(SC_FXCTE_WL) && (SC_FXCTE_WL > 0) +const int SC_DEFAULT_CTE_WL_ = SC_FXCTE_WL; +#else +const int SC_DEFAULT_CTE_WL_ = SC_BUILTIN_CTE_WL_; +#endif + +#if defined(SC_FXMAX_WL) && (SC_FXMAX_WL > 0 || SC_FXMAX_WL == -1) +const int SC_DEFAULT_MAX_WL_ = SC_FXMAX_WL; +#else +const int SC_DEFAULT_MAX_WL_ = SC_BUILTIN_MAX_WL_; +#endif + + +// ---------------------------------------------------------------------------- +// Dedicated error reporting and checking. +// ---------------------------------------------------------------------------- + +#define SC_ERROR_IF_IMPL_(cnd, id, msg) \ + do { \ + if (cnd) { \ + SC_REPORT_ERROR(id, msg); \ + sc_core::sc_abort(); /* can't recover from here */ \ + } \ + } while ( false ) + +#ifdef DEBUG_SYSTEMC +# define SC_ASSERT_(cnd, msg) \ + SC_ERROR_IF_IMPL_(!(cnd), "internal error", msg) +#else +# define SC_ASSERT_(cnd, msg) (void(0)) +#endif + +#define SC_ERROR_IF_(cnd,id) SC_ERROR_IF_IMPL_(cnd, id, 0) + +#define SC_CHECK_WL_(wl) SC_ERROR_IF_((wl) <= 0, \ + "total wordlength <= 0 is not valid") + +#define SC_CHECK_N_BITS_(n_bits) \ + SC_ERROR_IF_((n_bits) < 0, "number of bits < 0 is not valid") + +#define SC_CHECK_DIV_WL_(div_wl) \ + SC_ERROR_IF_((div_wl) <= 0, "division wordlength <= 0 is not valid") + +#define SC_CHECK_CTE_WL_(cte_wl) \ + SC_ERROR_IF_((cte_wl) <= 0, "constant wordlength <= 0 is not valid") + +#define SC_CHECK_MAX_WL_(max_wl) \ + SC_ERROR_IF_((max_wl) <= 0 && (max_wl) != -1, \ + "maximum wordlength <= 0 and != -1 is not valid") + + +// ---------------------------------------------------------------------------- +// Generic observer macros. +// ---------------------------------------------------------------------------- + +#define SC_OBSERVER_(object, observer_type, event) \ +{ \ + if ((object).observer() != 0) { \ + observer_type observer = (object).lock_observer(); \ + observer->event((object)); \ + (object).unlock_observer(observer); \ + } \ +} + +#define SC_OBSERVER_DEFAULT_(observer_type) \ +{ \ + if (m_observer == 0 && observer_type::default_observer != 0) \ + m_observer = (*observer_type::default_observer)(); \ +} + +} // namespace sc_dt + +#endif // __SYSTEMC_EXT_DT_FX_SC_FXDEFS_HH__ -- cgit v1.2.3