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 <gabeblack@google.com>
Maintainer: Gabe Black <gabeblack@google.com>
This commit is contained in:
Gabe Black
2018-05-22 02:21:17 -07:00
parent 7adb1b250b
commit 5ee040a534
60 changed files with 33895 additions and 55 deletions

View File

@@ -106,7 +106,7 @@ class sc_fifo : public sc_fifo_in_if<T>,
}
virtual const sc_event &
data_Written_event() const
data_written_event() const
{
sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
return *(const sc_event *)nullptr;

View File

@@ -41,7 +41,7 @@ template <class T>
class sc_fifo_nonblocking_in_if : virtual public sc_interface
{
public:
virtual bool ab_read(T &) = 0;
virtual bool nb_read(T &) = 0;
virtual const sc_event &data_written_event() const = 0;
};
@@ -58,7 +58,7 @@ class sc_fifo_in_if : public sc_fifo_nonblocking_in_if<T>,
public sc_fifo_blocking_in_if<T>
{
public:
virtual int num_avaialble() const = 0;
virtual int num_available() const = 0;
protected:
sc_fifo_in_if() : sc_interface() {}

View File

@@ -41,7 +41,7 @@ template <class T>
class sc_fifo_nonblocking_out_if : virtual public sc_interface
{
public:
virtual bool ab_write(const T &) = 0;
virtual bool nb_write(const T &) = 0;
virtual const sc_event &data_read_event() const = 0;
};

View File

@@ -32,12 +32,12 @@
#include "sc_in.hh"
namespace
namespace sc_dt
{
class sc_logic;
}
} // namespace sc_dt
namespace sc_core
{

View File

@@ -35,12 +35,12 @@
#include "sc_signal_inout_if.hh"
#include "warn_unimpl.hh"
namespace
namespace sc_dt
{
class sc_logic;
}
} // namespace sc_dt
namespace sc_core
{

View File

@@ -35,12 +35,12 @@
#include "sc_signal_inout_if.hh"
#include "warn_unimpl.hh"
namespace
namespace sc_dt
{
class sc_logic;
}
} // namespace sc_dt
namespace sc_core
{

View File

@@ -27,9 +27,12 @@
* Authors: Gabe Black
*/
#ifndef __SYSTEMC_EXT_CORE__DT_HH__
#define __SYSTEMC_EXT_CORE__DT_HH__
#ifndef __SYSTEMC_EXT_DT__DT_HH__
#define __SYSTEMC_EXT_DT__DT_HH__
#include "bit/_bit.hh"
#include "fx/_fx.hh"
#include "int/_int.hh"
#include "misc/_misc.hh"
#endif //__SYSTEMC_EXT_CORE__DT_HH__
#endif //__SYSTEMC_EXT_DT__DT_HH__

View File

@@ -27,9 +27,12 @@
* Authors: Gabe Black
*/
#ifndef __SYSTEMC_EXT_CORE__USING_HH__
#define __SYSTEMC_EXT_CORE__USING_HH__
#ifndef __SYSTEMC_EXT_DT__USING_HH__
#define __SYSTEMC_EXT_DT__USING_HH__
#include "bit/_using.hh"
#include "fx/_using.hh"
#include "int/_using.hh"
#include "misc/_using.hh"
#endif //__SYSTEMC_EXT_CORE__USING_HH__
#endif //__SYSTEMC_EXT_DT__USING_HH__

View File

@@ -0,0 +1,42 @@
/*
* Copyright 2018 Google, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: Gabe Black
*/
#ifndef __SYSTEMC_EXT_DT_BIT__BIT_HH__
#define __SYSTEMC_EXT_DT_BIT__BIT_HH__
#include "sc_bit.hh"
#include "sc_bit_proxies.hh"
#include "sc_bv.hh"
#include "sc_bv_base.hh"
#include "sc_logic.hh"
#include "sc_lv.hh"
#include "sc_lv_base.hh"
#include "sc_proxy.hh"
#endif //__SYSTEMC_EXT_DT_BIT__BIT_HH__

View File

@@ -0,0 +1,45 @@
/*
* Copyright 2018 Google, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: Gabe Black
*/
#ifndef __SYSTEMC_EXT_DT_BIT__USING_HH__
#define __SYSTEMC_EXT_DT_BIT__USING_HH__
#include "_bit.hh"
using sc_dt::SC_LOGIC_0;
using sc_dt::SC_LOGIC_1;
using sc_dt::SC_LOGIC_X;
using sc_dt::SC_LOGIC_Z;
using sc_dt::sc_bit;
using sc_dt::sc_bv;
using sc_dt::sc_bv_base;
using sc_dt::sc_lv;
using sc_dt::sc_lv_base;
#endif //__SYSTEMC_EXT_DT_BIT__USING_HH__

View File

@@ -0,0 +1,381 @@
/*****************************************************************************
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_bit.h -- Bit class.
Original Author: Stan Y. Liao, Synopsys, Inc.
*****************************************************************************/
/*****************************************************************************
MODIFICATION LOG - modifiers, enter your name, affiliation, date and
changes you are making here.
Name, Affiliation, Date:
Description of Modification:
*****************************************************************************/
// $Log: sc_bit.h,v $
// Revision 1.2 2011/08/07 18:54:19 acg
// Philipp A. Hartmann: remove friend function declarations that implement
// code, and clean up how bit and logic operators are defined in general.
//
// Revision 1.1.1.1 2006/12/15 20:20:04 acg
// SystemC 2.3
//
// Revision 1.6 2006/05/08 17:49:59 acg
// Andy Goodrich: Added David Long's declarations for friend operators,
// functions, and methods, to keep the Microsoft compiler happy.
//
// Revision 1.5 2006/04/12 20:17:52 acg
// Andy Goodrich: enabled deprecation message for sc_bit.
//
// Revision 1.4 2006/01/24 20:50:55 acg
// Andy Goodrich: added warnings indicating that sc_bit is deprecated and that
// the C bool data type should be used in its place.
//
// Revision 1.3 2006/01/13 18:53:53 acg
// Andy Goodrich: added $Log command so that CVS comments are reproduced in
// the source.
//
#ifndef __SYSTEMC_EXT_DT_BIT_SC_BIT_HH__
#define __SYSTEMC_EXT_DT_BIT_SC_BIT_HH__
#include <iostream>
#include "../int/sc_nbdefs.hh"
namespace sc_dt
{
// classes defined in this module
class sc_bit;
// forward class declarations
class sc_logic;
extern void sc_deprecated_sc_bit();
// ----------------------------------------------------------------------------
// CLASS : sc_bit
//
// Bit class.
// Note: VSIA compatibility indicated.
// ----------------------------------------------------------------------------
class sc_bit
{
// support methods
static void invalid_value(char);
static void invalid_value(int);
static bool
to_value(char c)
{
if (c != '0' && c != '1') {
invalid_value(c);
}
return (c == '0' ? false : true);
}
static bool
to_value(int i)
{
if (i != 0 && i != 1) {
invalid_value(i);
}
return (i == 0 ? false : true);
}
static bool to_value(bool b) { return b; }
#define DEFN_TO_VALUE_T(tp) \
static bool to_value(tp i) { return to_value((int)i); }
DEFN_TO_VALUE_T(unsigned)
DEFN_TO_VALUE_T(long)
DEFN_TO_VALUE_T(unsigned long)
DEFN_TO_VALUE_T(int64)
DEFN_TO_VALUE_T(uint64)
#undef DEFN_TO_VALUE_T
public:
// constructors
// MANDATORY
sc_bit() : m_val(false) { sc_deprecated_sc_bit(); }
#define DEFN_CTOR_T(tp) \
explicit sc_bit(tp a) : m_val(to_value(a)) { sc_deprecated_sc_bit(); }
DEFN_CTOR_T(bool)
DEFN_CTOR_T(char)
DEFN_CTOR_T(int)
DEFN_CTOR_T(unsigned)
DEFN_CTOR_T(long)
DEFN_CTOR_T(unsigned long)
DEFN_CTOR_T(int64)
DEFN_CTOR_T(uint64)
#undef DEFN_CTOR_T
explicit sc_bit(const sc_logic &a); // non-VSIA
// copy constructor
// MANDATORY
sc_bit(const sc_bit &a) : m_val(a.m_val) {}
// destructor
// MANDATORY
~sc_bit() {}
// assignment operators
// MANDATORY
sc_bit &
operator = (const sc_bit &b)
{
m_val = b.m_val;
return *this;
}
#define DEFN_ASN_OP_T(op, tp) \
sc_bit &operator op(tp b) { return (*this op sc_bit(b)); }
#define DEFN_ASN_OP(op) \
DEFN_ASN_OP_T(op,int) \
DEFN_ASN_OP_T(op,bool) \
DEFN_ASN_OP_T(op,char)
DEFN_ASN_OP(=)
DEFN_ASN_OP_T(=,int64)
DEFN_ASN_OP_T(=,uint64)
DEFN_ASN_OP_T(=,long)
DEFN_ASN_OP_T(=,unsigned long)
sc_bit &operator = (const sc_logic &b); // non-VSIA
// bitwise assignment operators
sc_bit &
operator &= (const sc_bit &b)
{
m_val = (m_val && b.m_val);
return *this;
}
sc_bit &
operator |= (const sc_bit &b)
{
m_val = (m_val || b.m_val);
return *this;
}
sc_bit &
operator ^= (const sc_bit &b)
{
m_val = (m_val != b.m_val);
return *this;
}
DEFN_ASN_OP(&=)
DEFN_ASN_OP(|=)
DEFN_ASN_OP(^=)
#undef DEFN_ASN_OP_T
#undef DEFN_ASN_OP
// conversions
// MANDATORY
// implicit conversion to bool
operator bool () const { return m_val; }
// non-VSIA
bool operator ! () const { return !m_val; }
// explicit conversions - non-VSIA
bool to_bool() const { return m_val; }
char to_char() const { return (m_val ? '1' : '0'); }
// relational operators and functions
// MANDATORY
friend bool operator == (const sc_bit &a, const sc_bit &b);
friend bool operator != (const sc_bit &a, const sc_bit &b);
// bitwise operators and functions
// bitwise complement
// MANDATORY
friend const sc_bit operator ~ (const sc_bit &a);
// RECOMMENDED
sc_bit &
b_not()
{
m_val = (!m_val);
return *this;
}
// binary bit-wise operations
friend const sc_bit operator | (const sc_bit &a, const sc_bit &b);
friend const sc_bit operator & (const sc_bit &a, const sc_bit &b);
friend const sc_bit operator ^ (const sc_bit &a, const sc_bit &b);
// other methods
void print(::std::ostream &os=::std::cout) const { os << to_bool(); }
void scan(::std::istream & =::std::cin);
private:
bool m_val;
};
// ----------------------------------------------------------------------------
// relational operators and functions
#define DEFN_BIN_FUN_T(ret,fun,tp) \
inline ret fun(const sc_bit& a, tp b) { return fun(a, sc_bit(b)); } \
inline ret fun(tp b, const sc_bit &a) { return fun(sc_bit(a), b); }
#define DEFN_BIN_FUN(ret,fun) \
DEFN_BIN_FUN_T(ret,fun,bool) \
DEFN_BIN_FUN_T(ret,fun,char) \
DEFN_BIN_FUN_T(ret,fun,int)
// MANDATORY
inline bool
operator == (const sc_bit &a, const sc_bit &b)
{
return (a.m_val == b.m_val);
}
inline bool
operator != (const sc_bit &a, const sc_bit &b)
{
return (a.m_val != b.m_val);
}
DEFN_BIN_FUN(bool, operator ==)
DEFN_BIN_FUN(bool, operator !=)
// OPTIONAL
inline bool equal(const sc_bit &a, const sc_bit &b) { return (a == b); }
inline bool not_equal(const sc_bit &a, const sc_bit &b) { return (a != b); }
DEFN_BIN_FUN(bool,equal)
DEFN_BIN_FUN(bool,not_equal)
// ----------------------------------------------------------------------------
// bitwise operators and functions
// bitwise complement
// MANDATORY
inline const sc_bit operator ~ (const sc_bit &a) { return sc_bit(!a.m_val); }
// OPTIONAL
inline const sc_bit b_not(const sc_bit &a) { return (~a); }
// RECOMMENDED
inline void b_not(sc_bit &r, const sc_bit &a) { r = (~a); }
// binary bit-wise operations
// MANDATORY
inline const sc_bit
operator & (const sc_bit &a, const sc_bit &b)
{
return sc_bit(a.m_val && b.m_val);
}
inline const sc_bit
operator | (const sc_bit &a, const sc_bit &b)
{
return sc_bit(a.m_val || b.m_val);
}
inline const sc_bit
operator ^ (const sc_bit &a, const sc_bit &b)
{
return sc_bit(a.m_val != b.m_val);
}
DEFN_BIN_FUN(const sc_bit,operator&)
DEFN_BIN_FUN(const sc_bit,operator|)
DEFN_BIN_FUN(const sc_bit,operator^)
// OPTIONAL
inline const sc_bit b_and(const sc_bit &a, const sc_bit &b) { return a & b; }
inline const sc_bit b_or(const sc_bit &a, const sc_bit &b) { return a | b; }
inline const sc_bit b_xor(const sc_bit &a, const sc_bit &b) { return a ^ b; }
DEFN_BIN_FUN(const sc_bit,b_and)
DEFN_BIN_FUN(const sc_bit,b_or)
DEFN_BIN_FUN(const sc_bit,b_xor)
// RECOMMENDED
#define DEFN_TRN_FUN_T(fun,tp) \
inline void \
fun(sc_bit &r, const sc_bit &a, tp b) \
{ r = fun(a, sc_bit(b)); } \
inline void \
fun(sc_bit &r, tp a, const sc_bit &b) \
{ r = fun(sc_bit(a), b); }
#define DEFN_TRN_FUN(fun) \
inline void \
fun(sc_bit &r, const sc_bit &a, const sc_bit &b) { r = fun(a , b); } \
DEFN_TRN_FUN_T(fun, int) \
DEFN_TRN_FUN_T(fun, bool) \
DEFN_TRN_FUN_T(fun, char)
DEFN_TRN_FUN(b_and)
DEFN_TRN_FUN(b_or)
DEFN_TRN_FUN(b_xor)
#undef DEFN_BIN_FUN_T
#undef DEFN_BIN_FUN
#undef DEFN_TRN_FUN_T
#undef DEFN_TRN_FUN
// ----------------------------------------------------------------------------
inline ::std::ostream &
operator << (::std::ostream &os, const sc_bit &a)
{
a.print(os);
return os;
}
inline ::std::istream &
operator >> (::std::istream &is, sc_bit &a)
{
a.scan(is);
return is;
}
} // namespace sc_dt
#endif // __SYSTEMC_EXT_DT_BIT_SC_BIT_HH__

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,208 @@
/*****************************************************************************
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_bv.h -- Arbitrary size bit vector class.
Original Author: Gene Bushuyev, Synopsys, Inc.
*****************************************************************************/
/*****************************************************************************
MODIFICATION LOG - modifiers, enter your name, affiliation, date and
changes you are making here.
Name, Affiliation, Date:
Description of Modification:
*****************************************************************************/
// $Log: sc_bv.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:53 acg
// Andy Goodrich: added $Log command so that CVS comments are reproduced in
// the source.
//
#ifndef __SYSTEMC_EXT_DT_BIT_SC_BV_HH__
#define __SYSTEMC_EXT_DT_BIT_SC_BV_HH__
#include "sc_bv_base.hh"
namespace sc_dt
{
// classes defined in this module
template <int W>
class sc_bv;
// ----------------------------------------------------------------------------
// CLASS TEMPLATE : sc_bv<W>
//
// Arbitrary size bit vector class.
// ----------------------------------------------------------------------------
template <int W>
class sc_bv : public sc_bv_base
{
public:
// constructors
sc_bv() :sc_bv_base(W) {}
explicit sc_bv(bool init_value) : sc_bv_base(init_value, W) {}
explicit sc_bv(char init_value) : sc_bv_base((init_value != '0'), W) {}
sc_bv(const char *a) : sc_bv_base(W) { sc_bv_base::operator = (a); }
sc_bv(const bool *a) : sc_bv_base(W) { sc_bv_base::operator = (a); }
sc_bv(const sc_logic *a) : sc_bv_base(W) { sc_bv_base::operator = (a); }
sc_bv(const sc_unsigned &a) : sc_bv_base(W) { sc_bv_base::operator = (a); }
sc_bv(const sc_signed &a) : sc_bv_base(W) { sc_bv_base::operator = (a); }
sc_bv(const sc_uint_base &a) : sc_bv_base(W)
{
sc_bv_base::operator = (a);
}
sc_bv(const sc_int_base &a) : sc_bv_base(W) { sc_bv_base::operator = (a); }
sc_bv(unsigned long a) : sc_bv_base(W) { sc_bv_base::operator = (a); }
sc_bv(long a) : sc_bv_base(W) { sc_bv_base::operator = (a); }
sc_bv(unsigned int a) : sc_bv_base(W) { sc_bv_base::operator = (a); }
sc_bv(int a) : sc_bv_base(W) { sc_bv_base::operator = (a); }
sc_bv(uint64 a) : sc_bv_base(W) { sc_bv_base::operator = (a); }
sc_bv(int64 a) : sc_bv_base(W) { sc_bv_base::operator = (a); }
template <class X>
sc_bv(const sc_proxy<X> &a) : sc_bv_base(W) { sc_bv_base::operator = (a); }
sc_bv(const sc_bv<W> &a) : sc_bv_base(a) {}
// assignment operators
template <class X>
sc_bv<W> &
operator = (const sc_proxy<X> &a)
{
sc_bv_base::operator = (a);
return *this;
}
sc_bv<W> &
operator = (const sc_bv<W> &a)
{
sc_bv_base::operator = (a);
return *this;
}
sc_bv<W> &
operator = (const char *a)
{
sc_bv_base::operator = (a);
return *this;
}
sc_bv<W> &
operator = (const bool *a)
{
sc_bv_base::operator = (a);
return *this;
}
sc_bv<W> &
operator = (const sc_logic *a)
{
sc_bv_base::operator = (a);
return *this;
}
sc_bv<W> &
operator = (const sc_unsigned &a)
{
sc_bv_base::operator = (a);
return *this;
}
sc_bv<W> &
operator = (const sc_signed &a)
{
sc_bv_base::operator = (a);
return *this;
}
sc_bv<W> &
operator = (const sc_uint_base &a)
{
sc_bv_base::operator = (a);
return *this;
}
sc_bv<W> &
operator = (const sc_int_base &a)
{
sc_bv_base::operator = (a);
return *this;
}
sc_bv<W> &
operator = (unsigned long a)
{
sc_bv_base::operator = (a);
return *this;
}
sc_bv<W> &
operator = (long a)
{
sc_bv_base::operator = (a);
return *this;
}
sc_bv<W> &
operator = (unsigned int a)
{
sc_bv_base::operator = (a);
return *this;
}
sc_bv<W> &
operator = (int a)
{
sc_bv_base::operator = (a);
return *this;
}
sc_bv<W> &
operator = (uint64 a)
{
sc_bv_base::operator = (a);
return *this;
}
sc_bv<W> &
operator = (int64 a)
{
sc_bv_base::operator = (a);
return *this;
}
};
} // namespace sc_dt
#endif // __SYSTEMC_EXT_DT_BIT_SC_BV_HH__

View File

@@ -0,0 +1,282 @@
/*****************************************************************************
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_bv_base.h -- Arbitrary size bit vector class.
Original Author: Gene Bushuyev, Synopsys, Inc.
*****************************************************************************/
/*****************************************************************************
MODIFICATION LOG - modifiers, enter your name, affiliation, date and
changes you are making here.
Name, Affiliation, Date:
Description of Modification:
*****************************************************************************/
// $Log: sc_bv_base.h,v $
// Revision 1.3 2011/08/26 22:32:00 acg
// Torsten Maehne: added parentheses to make opearator ordering more obvious.
//
// Revision 1.2 2011/08/15 16:43:24 acg
// Torsten Maehne: changes to remove unused argument warnings.
//
// Revision 1.1.1.1 2006/12/15 20:20:04 acg
// SystemC 2.3
//
// Revision 1.3 2006/01/13 18:53:53 acg
// Andy Goodrich: added $Log command so that CVS comments are reproduced in
// the source.
//
#ifndef __SYSTEMC_EXT_DT_BIT_SC_BV_BASE_HH__
#define __SYSTEMC_EXT_DT_BIT_SC_BV_BASE_HH__
#include "../int/sc_length_param.hh"
#include "sc_bit_proxies.hh"
#include "sc_proxy.hh"
namespace sc_dt
{
// classes defined in this module
class sc_bv_base;
// ----------------------------------------------------------------------------
// CLASS : sc_bv_base
//
// Arbitrary size bit vector base class.
// ----------------------------------------------------------------------------
class sc_bv_base : public sc_proxy<sc_bv_base>
{
friend class sc_lv_base;
void init(int length_, bool init_value=false);
void assign_from_string(const std::string &);
public:
// typedefs
typedef sc_proxy<sc_bv_base> base_type;
typedef base_type::value_type value_type;
// constructors
explicit sc_bv_base(int length_=sc_length_param().len()) :
m_len(0), m_size(0), m_data(0)
{
init(length_);
}
explicit sc_bv_base(bool a, int length_=sc_length_param().len()) :
m_len(0), m_size(0), m_data(0)
{
init(length_, a);
}
sc_bv_base(const char *a);
sc_bv_base(const char *a, int length_);
template <class X>
sc_bv_base(const sc_proxy<X> &a) : m_len(0), m_size(0), m_data(0)
{
init(a.back_cast().length());
base_type::assign_(a);
}
sc_bv_base(const sc_bv_base &a);
// destructor
virtual ~sc_bv_base() { delete [] m_data; }
// assignment operators
template <class X>
sc_bv_base &
operator = (const sc_proxy<X> &a)
{
assign_p_(*this, a);
return *this;
}
sc_bv_base &
operator = (const sc_bv_base &a)
{
assign_p_(*this, a);
return *this;
}
sc_bv_base &operator = (const char *a);
sc_bv_base &
operator = (const bool *a)
{
base_type::assign_(a);
return *this;
}
sc_bv_base &
operator = (const sc_logic *a)
{
base_type::assign_(a);
return *this;
}
sc_bv_base &
operator = (const sc_unsigned &a)
{
base_type::assign_(a);
return *this;
}
sc_bv_base &
operator = (const sc_signed &a)
{
base_type::assign_(a);
return *this;
}
sc_bv_base &
operator = (const sc_uint_base &a)
{
base_type::assign_(a);
return *this;
}
sc_bv_base &
operator = (const sc_int_base &a)
{
base_type::assign_(a);
return *this;
}
sc_bv_base &
operator = (unsigned long a)
{
base_type::assign_(a);
return *this;
}
sc_bv_base &
operator = (long a)
{
base_type::assign_(a);
return *this;
}
sc_bv_base &
operator = (unsigned int a)
{
base_type::assign_(a);
return *this;
}
sc_bv_base &
operator = (int a)
{
base_type::assign_(a);
return *this;
}
sc_bv_base &
operator = (uint64 a)
{
base_type::assign_(a);
return *this;
}
sc_bv_base &
operator = (int64 a)
{
base_type::assign_(a);
return *this;
}
// common methods
int length() const { return m_len; }
int size() const { return m_size; }
value_type get_bit(int i) const;
void set_bit(int i, value_type value);
sc_digit get_word(int i) const { return m_data[i]; }
void set_word(int i, sc_digit w) { m_data[i] = w; }
sc_digit get_cword(int /*i*/) const { return SC_DIGIT_ZERO; }
void set_cword(int i, sc_digit w);
void clean_tail();
// other methods
bool is_01() const { return true; }
protected:
int m_len; // length in bits
int m_size; // size of data array
sc_digit *m_data; // data array
};
// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
// common methods
inline sc_bv_base::value_type
sc_bv_base::get_bit(int i) const
{
int wi = i / SC_DIGIT_SIZE;
int bi = i % SC_DIGIT_SIZE;
return value_type((m_data[wi] >> bi) & SC_DIGIT_ONE);
}
inline void
sc_bv_base::set_bit(int i, value_type value)
{
int wi = i / SC_DIGIT_SIZE;
int bi = i % SC_DIGIT_SIZE;
sc_digit mask = SC_DIGIT_ONE << bi;
m_data[wi] |= mask; // set bit to 1
m_data[wi] &= value << bi | ~mask;
}
inline void
sc_bv_base::set_cword(int /*i*/, sc_digit w)
{
if (w) {
SC_REPORT_WARNING("sc_bv cannot contain values X and Z", 0);
}
}
inline void
sc_bv_base::clean_tail()
{
int wi = m_size - 1;
int bi = m_len % SC_DIGIT_SIZE;
if (bi != 0)
m_data[wi] &= ~SC_DIGIT_ZERO >> (SC_DIGIT_SIZE - bi);
}
} // namespace sc_dt
#endif // __SYSTEMC_EXT_DT_BIT_SC_BV_BASE_HH__

View File

@@ -0,0 +1,381 @@
/*****************************************************************************
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_logic.h -- C++ implementation of logic type. Behaves
pretty much the same way as HDLs except with 4 values.
Original Author: Stan Y. Liao, Synopsys, Inc.
*****************************************************************************/
/*****************************************************************************
MODIFICATION LOG - modifiers, enter your name, affiliation, date and
changes you are making here.
Name, Affiliation, Date:
Description of Modification:
*****************************************************************************/
// $Log: sc_logic.h,v $
// Revision 1.3 2011/08/07 18:54:19 acg
// Philipp A. Hartmann: remove friend function declarations that implement
// code, and clean up how bit and logic operators are defined in general.
//
// Revision 1.2 2011/01/25 20:50:37 acg
// Andy Goodrich: changes for IEEE 1666 2011.
//
// Revision 1.1.1.1 2006/12/15 20:20:04 acg
// SystemC 2.3
//
// Revision 1.5 2006/12/02 21:00:57 acg
// Andy Goodrich: fixes for concatenation support.
//
// Revision 1.4 2006/05/08 17:49:59 acg
// Andy Goodrich: Added David Long's declarations for friend operators,
// functions, and methods, to keep the Microsoft compiler happy.
//
// Revision 1.3 2006/01/13 18:53:53 acg
// Andy Goodrich: added $Log command so that CVS comments are reproduced in
// the source.
//
#ifndef __SYSTEMC_EXT_DT_BIT_SC_LOGIC_HH__
#define __SYSTEMC_EXT_DT_BIT_SC_LOGIC_HH__
#include <cstdio>
#include <iostream>
#include "../sc_mempool.hh"
#include "sc_bit.hh"
namespace sc_dt
{
// classes defined in this module
class sc_logic;
// ----------------------------------------------------------------------------
// ENUM : sc_logic_value_t
//
// Enumeration of values for sc_logic.
// ----------------------------------------------------------------------------
enum sc_logic_value_t
{
Log_0 = 0,
Log_1,
Log_Z,
Log_X
};
// ----------------------------------------------------------------------------
// CLASS : sc_logic
//
// Four-valued logic type.
// ----------------------------------------------------------------------------
class sc_logic
{
private:
// support methods
static void invalid_value(sc_logic_value_t);
static void invalid_value(char);
static void invalid_value(int);
static sc_logic_value_t
to_value(sc_logic_value_t v)
{
if (v < Log_0 || v > Log_X) {
invalid_value(v);
// may continue, if suppressed
v = Log_X;
}
return v;
}
static sc_logic_value_t to_value(bool b) { return (b ? Log_1 : Log_0); }
static sc_logic_value_t
to_value(char c)
{
unsigned int index = (int)c;
if (index > 127) {
invalid_value(c);
// may continue, if suppressed
index = 127; // aka Log_X
}
return char_to_logic[index];
}
static sc_logic_value_t
to_value(int i)
{
if (i < Log_0 || i > Log_X) {
invalid_value(i);
// may continue, if suppressed
i = Log_X;
}
return sc_logic_value_t(i);
}
void invalid_01() const;
public:
// conversion tables
static const sc_logic_value_t char_to_logic[128];
static const char logic_to_char[4];
static const sc_logic_value_t and_table[4][4];
static const sc_logic_value_t or_table[4][4];
static const sc_logic_value_t xor_table[4][4];
static const sc_logic_value_t not_table[4];
// constructors
sc_logic() : m_val(Log_X) {}
sc_logic(const sc_logic &a) : m_val(a.m_val) {}
sc_logic(sc_logic_value_t v) : m_val(to_value(v)) {}
explicit sc_logic(bool a) : m_val(to_value(a)) {}
explicit sc_logic(char a) : m_val(to_value(a)) {}
explicit sc_logic(int a) : m_val(to_value(a)) {}
explicit sc_logic(const sc_bit &a) : m_val(to_value(a.to_bool())) {}
// destructor
~sc_logic() {}
// (bitwise) assignment operators
#define DEFN_ASN_OP_T(op,tp) \
sc_logic & \
operator op (tp v) \
{ \
*this op sc_logic(v); \
return *this; \
}
#define DEFN_ASN_OP(op) \
DEFN_ASN_OP_T(op, sc_logic_value_t) \
DEFN_ASN_OP_T(op, bool) \
DEFN_ASN_OP_T(op, char) \
DEFN_ASN_OP_T(op, int) \
DEFN_ASN_OP_T(op, const sc_bit &)
sc_logic &
operator = (const sc_logic &a)
{
m_val = a.m_val;
return *this;
}
sc_logic &
operator &= (const sc_logic &b)
{
m_val = and_table[m_val][b.m_val];
return *this;
}
sc_logic &
operator |= (const sc_logic &b)
{
m_val = or_table[m_val][b.m_val];
return *this;
}
sc_logic &
operator ^= (const sc_logic &b)
{
m_val = xor_table[m_val][b.m_val];
return *this;
}
DEFN_ASN_OP(=)
DEFN_ASN_OP(&=)
DEFN_ASN_OP(|=)
DEFN_ASN_OP(^=)
#undef DEFN_ASN_OP_T
#undef DEFN_ASN_OP
// bitwise operators and functions
friend const sc_logic operator & (const sc_logic &, const sc_logic &);
friend const sc_logic operator | (const sc_logic &, const sc_logic &);
friend const sc_logic operator ^ (const sc_logic &, const sc_logic &);
// relational operators
friend bool operator == (const sc_logic &, const sc_logic &);
friend bool operator != (const sc_logic &, const sc_logic &);
// bitwise complement
const sc_logic operator ~ () const { return sc_logic(not_table[m_val]); }
sc_logic &
b_not()
{
m_val = not_table[m_val];
return *this;
}
// explicit conversions
sc_logic_value_t value() const { return m_val; }
bool is_01() const { return ((int)m_val == Log_0 || (int)m_val == Log_1); }
bool
to_bool() const
{
if (!is_01()) {
invalid_01();
}
return ((int)m_val != Log_0);
}
char to_char() const { return logic_to_char[m_val]; }
// other methods
void print(::std::ostream &os=::std::cout) const { os << to_char(); }
void scan(::std::istream &is=::std::cin);
// memory (de)allocation
// placement new
static void *operator new (std::size_t, void *p) { return p; }
static void *
operator new (std::size_t sz)
{
return sc_core::sc_mempool::allocate(sz);
}
static void
operator delete (void *p, std::size_t sz)
{
sc_core::sc_mempool::release(p, sz);
}
static void *
operator new [] (std::size_t sz)
{
return sc_core::sc_mempool::allocate(sz);
}
static void
operator delete [] (void *p, std::size_t sz)
{
sc_core::sc_mempool::release(p, sz);
}
private:
sc_logic_value_t m_val;
private:
// Disabled
explicit sc_logic(const char *);
sc_logic &operator = (const char *);
};
// ----------------------------------------------------------------------------
// bitwise operators
inline const sc_logic
operator & (const sc_logic &a, const sc_logic &b)
{
return sc_logic(sc_logic::and_table[a.m_val][b.m_val]);
}
inline const sc_logic
operator | (const sc_logic &a, const sc_logic &b)
{
return sc_logic(sc_logic::or_table[a.m_val][b.m_val]);
}
inline const sc_logic
operator ^ (const sc_logic &a, const sc_logic &b)
{
return sc_logic(sc_logic::xor_table[a.m_val][b.m_val]);
}
#define DEFN_BIN_OP_T(ret,op,tp) \
inline ret \
operator op (const sc_logic &a, tp b) \
{ \
return (a op sc_logic(b)); \
} \
inline ret \
operator op (tp a, const sc_logic &b) \
{ \
return (sc_logic(a) op b); \
}
#define DEFN_BIN_OP(ret, op) \
DEFN_BIN_OP_T(ret, op, sc_logic_value_t) \
DEFN_BIN_OP_T(ret, op, bool) \
DEFN_BIN_OP_T(ret, op, char) \
DEFN_BIN_OP_T(ret, op, int)
DEFN_BIN_OP(const sc_logic, &)
DEFN_BIN_OP(const sc_logic, |)
DEFN_BIN_OP(const sc_logic, ^)
// relational operators and functions
inline bool
operator == (const sc_logic &a, const sc_logic &b)
{
return ((int)a.m_val == b.m_val);
}
inline bool
operator != (const sc_logic &a, const sc_logic &b)
{
return ((int)a.m_val != b.m_val);
}
DEFN_BIN_OP(bool, ==)
DEFN_BIN_OP(bool, !=)
#undef DEFN_BIN_OP_T
#undef DEFN_BIN_OP
// ----------------------------------------------------------------------------
inline ::std::ostream &
operator << (::std::ostream &os, const sc_logic &a)
{
a.print(os);
return os;
}
inline ::std::istream &
operator >> (::std::istream &is, sc_logic &a)
{
a.scan(is);
return is;
}
extern const sc_logic SC_LOGIC_0;
extern const sc_logic SC_LOGIC_1;
extern const sc_logic SC_LOGIC_Z;
extern const sc_logic SC_LOGIC_X;
// #ifdef SC_DT_DEPRECATED
extern const sc_logic sc_logic_0;
extern const sc_logic sc_logic_1;
extern const sc_logic sc_logic_Z;
extern const sc_logic sc_logic_X;
// #endif
} // namespace sc_dt
#endif // __SYSTEMC_EXT_DT_BIT_SC_LOGIC_HH__

View File

@@ -0,0 +1,205 @@
/*****************************************************************************
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_lv.h -- Arbitrary size logic vector class.
Original Author: Gene Bushuyev, Synopsys, Inc.
*****************************************************************************/
/*****************************************************************************
MODIFICATION LOG - modifiers, enter your name, affiliation, date and
changes you are making here.
Name, Affiliation, Date:
Description of Modification:
*****************************************************************************/
// $Log: sc_lv.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:53 acg
// Andy Goodrich: added $Log command so that CVS comments are reproduced in
// the source.
//
#ifndef __SYSTEMC_EXT_DT_BIT_SC_LV_HH__
#define __SYSTEMC_EXT_DT_BIT_SC_LV_HH__
#include "sc_lv_base.hh"
namespace sc_dt
{
// classes defined in this module
template <int W>
class sc_lv;
// ----------------------------------------------------------------------------
// CLASS TEMPLATE : sc_lv<W>
//
// Arbitrary size logic vector class.
// ----------------------------------------------------------------------------
template <int W>
class sc_lv : public sc_lv_base
{
public:
// constructors
sc_lv() : sc_lv_base(W) {}
explicit sc_lv(const sc_logic &init_value) : sc_lv_base(init_value, W) {}
explicit sc_lv(bool init_value) : sc_lv_base(sc_logic(init_value), W) {}
explicit sc_lv(char init_value) : sc_lv_base(sc_logic(init_value), W) {}
sc_lv(const char *a) : sc_lv_base(W) { sc_lv_base::operator = (a); }
sc_lv(const bool *a) : sc_lv_base(W) { sc_lv_base::operator = (a); }
sc_lv(const sc_logic *a) : sc_lv_base(W) { sc_lv_base::operator = (a); }
sc_lv(const sc_unsigned &a) : sc_lv_base(W) { sc_lv_base::operator = (a); }
sc_lv(const sc_signed &a) : sc_lv_base(W) { sc_lv_base::operator = (a); }
sc_lv(const sc_uint_base &a) : sc_lv_base(W)
{
sc_lv_base::operator = (a);
}
sc_lv(const sc_int_base &a) : sc_lv_base(W) { sc_lv_base::operator = (a); }
sc_lv(unsigned long a) : sc_lv_base(W) { sc_lv_base::operator = (a); }
sc_lv(long a) : sc_lv_base(W) { sc_lv_base::operator = (a); }
sc_lv(unsigned int a) : sc_lv_base(W) { sc_lv_base::operator = (a); }
sc_lv(int a) : sc_lv_base(W) { sc_lv_base::operator = (a); }
sc_lv(uint64 a) : sc_lv_base(W) { sc_lv_base::operator = (a); }
sc_lv(int64 a) : sc_lv_base(W) { sc_lv_base::operator = (a); }
template <class X>
sc_lv(const sc_proxy<X> &a) : sc_lv_base(W) { sc_lv_base::operator = (a); }
sc_lv(const sc_lv<W> &a) : sc_lv_base(a) {}
// assignment operators
template <class X>
sc_lv<W> &
operator = (const sc_proxy<X> &a)
{
sc_lv_base::operator = (a);
return *this;
}
sc_lv<W> &
operator = (const sc_lv<W> &a)
{
sc_lv_base::operator = (a);
return *this;
}
sc_lv<W> &
operator = (const char *a)
{
sc_lv_base::operator = (a);
return *this;
}
sc_lv<W> &
operator = (const bool *a)
{
sc_lv_base::operator = (a);
return *this;
}
sc_lv<W> &
operator = (const sc_logic *a)
{
sc_lv_base::operator = (a);
return *this;
}
sc_lv<W> &
operator = (const sc_unsigned &a)
{
sc_lv_base::operator = (a);
return *this;
}
sc_lv<W> &
operator = (const sc_signed &a)
{
sc_lv_base::operator = (a);
return *this;
}
sc_lv<W> &
operator = (const sc_uint_base &a)
{
sc_lv_base::operator = (a);
return *this;
}
sc_lv<W> &
operator = (const sc_int_base &a)
{
sc_lv_base::operator = (a);
return *this;
}
sc_lv<W> &
operator = (unsigned long a)
{
sc_lv_base::operator = (a);
return *this;
}
sc_lv<W> &
operator = (long a)
{
sc_lv_base::operator = (a);
return *this;
}
sc_lv<W> &
operator = (unsigned int a)
{
sc_lv_base::operator = (a);
return *this;
}
sc_lv<W> &
operator = (int a)
{
sc_lv_base::operator = (a);
return *this;
}
sc_lv<W> &
operator = (uint64 a)
{
sc_lv_base::operator = (a);
return *this;
}
sc_lv<W> &
operator = (int64 a)
{
sc_lv_base::operator = (a);
return *this;
}
};
} // namespace sc_dt
#endif // __SYSTEMC_EXT_DT_BIT_SC_LV_HH__

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,53 @@
/*
* Copyright 2018 Google, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: Gabe Black
*/
#ifndef __SYSTEMC_EXT_CORE_DT_FX__FX_HH__
#define __SYSTEMC_EXT_CORE_DT_FX__FX_HH__
#include "sc_context.hh"
#include "sc_fix.hh"
#include "sc_fixed.hh"
#include "sc_fxcast_switch.hh"
#include "sc_fxdefs.hh"
#include "sc_fxnum.hh"
#include "sc_fxnum_observer.hh"
#include "sc_fxtype_params.hh"
#include "sc_fxval.hh"
#include "sc_fxval_observer.hh"
#include "sc_ufix.hh"
#include "sc_ufixed.hh"
#include "scfx_ieee.hh"
#include "scfx_mant.hh"
#include "scfx_other_defs.hh"
#include "scfx_params.hh"
#include "scfx_pow10.hh"
#include "scfx_rep.hh"
#include "scfx_utils.hh"
#endif //__SYSTEMC_EXT_CORE_DT_FX__FX_HH__

View File

@@ -0,0 +1,76 @@
/*
* Copyright 2018 Google, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: Gabe Black
*/
#ifndef __SYSTEMC_EXT_DT_FX__USING_HH__
#define __SYSTEMC_EXT_DT_FX__USING_HH__
#include "_fx.hh"
using sc_dt::sc_fxnum;
using sc_dt::sc_fxnum_bitref;
using sc_dt::sc_fxnum_fast;
using sc_dt::sc_fix;
using sc_dt::sc_fix_fast;
using sc_dt::sc_ufix;
using sc_dt::sc_ufix_fast;
using sc_dt::sc_fixed;
using sc_dt::sc_fixed_fast;
using sc_dt::sc_ufixed;
using sc_dt::sc_ufixed_fast;
using sc_dt::sc_fxval;
using sc_dt::sc_fxval_fast;
using sc_dt::sc_fxcast_switch;
using sc_dt::sc_fxcast_context;
using sc_dt::sc_fxtype_params;
using sc_dt::sc_fxtype_context;
using sc_dt::sc_q_mode;
using sc_dt::SC_RND;
using sc_dt::SC_RND_ZERO;
using sc_dt::SC_RND_MIN_INF;
using sc_dt::SC_RND_INF;
using sc_dt::SC_RND_CONV;
using sc_dt::SC_TRN;
using sc_dt::SC_TRN_ZERO;
using sc_dt::sc_o_mode;
using sc_dt::SC_SAT;
using sc_dt::SC_SAT_ZERO;
using sc_dt::SC_SAT_SYM;
using sc_dt::SC_WRAP;
using sc_dt::SC_WRAP_SM;
using sc_dt::sc_switch;
using sc_dt::SC_OFF;
using sc_dt::SC_ON;
using sc_dt::sc_fmt;
using sc_dt::SC_F;
using sc_dt::SC_E;
using sc_dt::sc_context_begin;
using sc_dt::SC_NOW;
using sc_dt::SC_LATER;
#endif //__SYSTEMC_EXT_DT_FX__USING_HH__

View File

@@ -0,0 +1,281 @@
/*****************************************************************************
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_context.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_context.h,v $
// Revision 1.2 2011/08/24 22:05:43 acg
// Torsten Maehne: initialization changes to remove warnings.
//
// Revision 1.1.1.1 2006/12/15 20:20:04 acg
// SystemC 2.3
//
// Revision 1.5 2006/05/26 20:36:52 acg
// Andy Goodrich: added a using for sc_core::default_ptr_hash_fn to keep HP
// aCC happy.
//
// Revision 1.4 2006/03/21 00:00:31 acg
// Andy Goodrich: changed name of sc_get_current_process_base() to be
// sc_get_current_process_b() since its returning an sc_process_b instance.
//
// 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_CONTEXT_HH__
#define __SYSTEMC_EXT_DT_FX_SC_CONTEXT_HH__
#include <map>
#include "../../core/sc_process_handle.hh"
#include "../../utils/sc_report_handler.hh"
namespace sc_dt
{
// classes defined in this module
class sc_without_context;
template <class T>
class sc_global;
template <class T>
class sc_context;
// ----------------------------------------------------------------------------
// CLASS : sc_without_context
//
// Empty class that is used for its type only.
// ----------------------------------------------------------------------------
class sc_without_context {};
// ----------------------------------------------------------------------------
// TEMPLATE CLASS : sc_global
//
// Template global variable class; singleton; co-routine safe.
// ----------------------------------------------------------------------------
template <class T>
class sc_global
{
sc_global();
void update();
public:
static sc_global<T>* instance();
const T*& value_ptr();
private:
static sc_global<T> *m_instance;
std::map<void *, const T *> m_map;
void *m_proc; // context (current process or NULL)
const T *m_value_ptr;
};
// ----------------------------------------------------------------------------
// ENUM : sc_context_begin
//
// Enumeration of context begin options.
// ----------------------------------------------------------------------------
enum sc_context_begin
{
SC_NOW,
SC_LATER
};
// ----------------------------------------------------------------------------
// CLASS : sc_context
//
// Template context class; co-routine safe.
// ----------------------------------------------------------------------------
template <class T>
class sc_context
{
// disabled
sc_context(const sc_context<T> &);
void *operator new(std::size_t);
public:
explicit sc_context(const T &, sc_context_begin=SC_NOW);
~sc_context();
void begin();
void end();
static const T &default_value();
const T &value() const;
private:
sc_context &operator = (const sc_context &) /* = delete */;
const T m_value;
const T *&m_def_value_ptr;
const T *m_old_value_ptr;
};
// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
// ----------------------------------------------------------------------------
// TEMPLATE CLASS : sc_global
//
// Template global variable class; singleton; co-routine safe.
// ----------------------------------------------------------------------------
template <class T>
sc_global<T> *sc_global<T>::m_instance = 0;
template <class T>
inline sc_global<T>::sc_global() : m_map(),
// use &m_instance as unique "non-process" key (NULL denotes 'sc_main'
// context)
m_proc(&m_instance), m_value_ptr(0)
{}
template <class T>
inline void
sc_global<T>::update()
{
void *p = (::sc_gem5::Process *)sc_core::sc_get_current_process_handle();
if (p != m_proc) {
const T *vp = m_map[p];
if (vp == 0) {
vp = new T(sc_without_context());
m_map.emplace(p, vp);
}
m_proc = p;
m_value_ptr = vp;
}
}
template <class T>
inline sc_global<T> *
sc_global<T>::instance()
{
if (m_instance == 0) {
m_instance = new sc_global<T>;
}
return m_instance;
}
template <class T>
inline const T *&
sc_global<T>::value_ptr()
{
update();
return m_value_ptr;
}
// ----------------------------------------------------------------------------
// CLASS : sc_context
//
// Template context class; co-routine safe.
// ----------------------------------------------------------------------------
template <class T>
inline sc_context<T>::sc_context(const T &value_, sc_context_begin begin_) :
m_value(value_),
m_def_value_ptr(sc_global<T>::instance()->value_ptr()),
m_old_value_ptr(0)
{
if (begin_ == SC_NOW) {
m_old_value_ptr = m_def_value_ptr;
m_def_value_ptr = &m_value;
}
}
template <class T>
inline sc_context<T>::~sc_context()
{
if (m_old_value_ptr != 0) {
m_def_value_ptr = m_old_value_ptr;
m_old_value_ptr = 0;
}
}
template <class T>
inline void
sc_context<T>::begin()
{
if (m_old_value_ptr == 0) {
m_old_value_ptr = m_def_value_ptr;
m_def_value_ptr = &m_value;
} else {
SC_REPORT_ERROR("context begin failed", 0);
}
}
template <class T>
inline void
sc_context<T>::end()
{
if (m_old_value_ptr != 0) {
m_def_value_ptr = m_old_value_ptr;
m_old_value_ptr = 0;
} else {
SC_REPORT_ERROR("context end failed", 0);
}
}
template <class T>
inline const T &
sc_context<T>::default_value()
{
return *sc_global<T>::instance()->value_ptr();
}
template <class T>
inline const T &
sc_context<T>::value() const
{
return m_value;
}
} // namespace sc_dt
#endif // __SYSTEMC_EXT_DT_FX_SC_CONTEXT_HH__

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,586 @@
/*****************************************************************************
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_fixed.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_fixed.h,v $
// Revision 1.2 2011/01/19 18:57:40 acg
// Andy Goodrich: changes for IEEE_1666_2011.
//
// 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_FIXED_HH__
#define __SYSTEMC_EXT_DT_FX_SC_FIXED_HH__
#include "sc_fix.hh"
namespace sc_dt
{
// classes defined in this module
template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
class sc_fixed;
template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
class sc_fixed_fast;
// ----------------------------------------------------------------------------
// TEMPLATE CLASS : sc_fixed
//
// "Constrained" signed fixed-point class; arbitrary precision.
// ----------------------------------------------------------------------------
template <int W, int I,
sc_q_mode Q=SC_DEFAULT_Q_MODE_,
sc_o_mode O=SC_DEFAULT_O_MODE_, int N=SC_DEFAULT_N_BITS_>
class sc_fixed : public sc_fix
{
public:
// constructors
explicit sc_fixed(sc_fxnum_observer * =0);
explicit sc_fixed(const sc_fxcast_switch &, sc_fxnum_observer * =0);
#define DECL_CTORS_T_A(tp) \
sc_fixed(tp, sc_fxnum_observer * =0); \
sc_fixed(tp, const sc_fxcast_switch &, sc_fxnum_observer * =0);
#define DECL_CTORS_T_B(tp) \
explicit sc_fixed(tp, sc_fxnum_observer * =0); \
sc_fixed(tp, const sc_fxcast_switch &, sc_fxnum_observer * =0);
DECL_CTORS_T_A(int)
DECL_CTORS_T_A(unsigned int)
DECL_CTORS_T_A(long)
DECL_CTORS_T_A(unsigned long)
DECL_CTORS_T_A(float)
DECL_CTORS_T_A(double)
DECL_CTORS_T_A(const char *)
DECL_CTORS_T_A(const sc_fxval &)
DECL_CTORS_T_A(const sc_fxval_fast &)
DECL_CTORS_T_A(const sc_fxnum &)
DECL_CTORS_T_A(const sc_fxnum_fast &)
DECL_CTORS_T_B(int64)
DECL_CTORS_T_B(uint64)
DECL_CTORS_T_B(const sc_int_base&)
DECL_CTORS_T_B(const sc_uint_base&)
DECL_CTORS_T_B(const sc_signed&)
DECL_CTORS_T_B(const sc_unsigned&)
#undef DECL_CTORS_T_A
#undef DECL_CTORS_T_B
// copy constructor
sc_fixed(const sc_fixed<W, I, Q, O, N> &);
// assignment operators
sc_fixed &operator = (const sc_fixed<W, I, Q, O, N> &);
#define DECL_ASN_OP_T(op, tp) sc_fixed &operator op (tp);
#define DECL_ASN_OP_OTHER(op) \
DECL_ASN_OP_T(op, int64) \
DECL_ASN_OP_T(op, uint64) \
DECL_ASN_OP_T(op, const sc_int_base&) \
DECL_ASN_OP_T(op, const sc_uint_base&) \
DECL_ASN_OP_T(op, const sc_signed&) \
DECL_ASN_OP_T(op, const sc_unsigned&)
#define DECL_ASN_OP(op) \
DECL_ASN_OP_T(op, int) \
DECL_ASN_OP_T(op, unsigned int) \
DECL_ASN_OP_T(op, long) \
DECL_ASN_OP_T(op, unsigned long) \
DECL_ASN_OP_T(op, float) \
DECL_ASN_OP_T(op, double) \
DECL_ASN_OP_T(op, const char *) \
DECL_ASN_OP_T(op, const sc_fxval &) \
DECL_ASN_OP_T(op, const sc_fxval_fast &) \
DECL_ASN_OP_T(op, const sc_fxnum &) \
DECL_ASN_OP_T(op, const sc_fxnum_fast &) \
DECL_ASN_OP_OTHER(op)
DECL_ASN_OP(=)
DECL_ASN_OP(*=)
DECL_ASN_OP(/=)
DECL_ASN_OP(+=)
DECL_ASN_OP(-=)
DECL_ASN_OP_T(<<=, int)
DECL_ASN_OP_T(>>=, int)
DECL_ASN_OP_T(&=, const sc_fix &)
DECL_ASN_OP_T(&=, const sc_fix_fast &)
DECL_ASN_OP_T(|=, const sc_fix &)
DECL_ASN_OP_T(|=, const sc_fix_fast &)
DECL_ASN_OP_T(^=, const sc_fix &)
DECL_ASN_OP_T(^=, const sc_fix_fast &)
#undef DECL_ASN_OP_T
#undef DECL_ASN_OP_OTHER
#undef DECL_ASN_OP
// auto-increment and auto-decrement
const sc_fxval operator ++ (int);
const sc_fxval operator -- (int);
sc_fixed & operator ++ ();
sc_fixed & operator -- ();
};
// ----------------------------------------------------------------------------
// TEMPLATE CLASS : sc_fixed_fast
//
// "Constrained" signed fixed-point class; limited precision.
// ----------------------------------------------------------------------------
template <int W, int I,
sc_q_mode Q=SC_DEFAULT_Q_MODE_,
sc_o_mode O=SC_DEFAULT_O_MODE_, int N=SC_DEFAULT_N_BITS_>
class sc_fixed_fast : public sc_fix_fast
{
public:
// constructors
explicit sc_fixed_fast(sc_fxnum_fast_observer * =0);
explicit sc_fixed_fast(const sc_fxcast_switch &,
sc_fxnum_fast_observer * =0);
#define DECL_CTORS_T_A(tp) \
sc_fixed_fast(tp, sc_fxnum_fast_observer * =0); \
sc_fixed_fast(tp, const sc_fxcast_switch &, \
sc_fxnum_fast_observer * =0);
#define DECL_CTORS_T_B(tp) \
explicit sc_fixed_fast(tp, sc_fxnum_fast_observer * =0); \
sc_fixed_fast(tp, const sc_fxcast_switch &, \
sc_fxnum_fast_observer * =0);
DECL_CTORS_T_A(int)
DECL_CTORS_T_A(unsigned int)
DECL_CTORS_T_A(long)
DECL_CTORS_T_A(unsigned long)
DECL_CTORS_T_A(float)
DECL_CTORS_T_A(double)
DECL_CTORS_T_A(const char *)
DECL_CTORS_T_A(const sc_fxval &)
DECL_CTORS_T_A(const sc_fxval_fast &)
DECL_CTORS_T_A(const sc_fxnum &)
DECL_CTORS_T_A(const sc_fxnum_fast &)
DECL_CTORS_T_B(int64)
DECL_CTORS_T_B(uint64)
DECL_CTORS_T_B(const sc_int_base &)
DECL_CTORS_T_B(const sc_uint_base &)
DECL_CTORS_T_B(const sc_signed &)
DECL_CTORS_T_B(const sc_unsigned &)
#undef DECL_CTORS_T_A
#undef DECL_CTORS_T_B
// copy constructor
sc_fixed_fast(const sc_fixed_fast<W, I, Q, O, N> &);
// assignment operators
sc_fixed_fast &operator = (const sc_fixed_fast<W, I, Q, O, N> &);
#define DECL_ASN_OP_T(op, tp) sc_fixed_fast &operator op (tp);
#define DECL_ASN_OP_OTHER(op) \
DECL_ASN_OP_T(op, int64) \
DECL_ASN_OP_T(op, uint64) \
DECL_ASN_OP_T(op, const sc_int_base &) \
DECL_ASN_OP_T(op, const sc_uint_base &) \
DECL_ASN_OP_T(op, const sc_signed &) \
DECL_ASN_OP_T(op, const sc_unsigned &)
#define DECL_ASN_OP(op) \
DECL_ASN_OP_T(op, int) \
DECL_ASN_OP_T(op, unsigned int) \
DECL_ASN_OP_T(op, long) \
DECL_ASN_OP_T(op, unsigned long) \
DECL_ASN_OP_T(op, float) \
DECL_ASN_OP_T(op, double) \
DECL_ASN_OP_T(op, const char *) \
DECL_ASN_OP_T(op, const sc_fxval &) \
DECL_ASN_OP_T(op, const sc_fxval_fast &) \
DECL_ASN_OP_T(op, const sc_fxnum &) \
DECL_ASN_OP_T(op, const sc_fxnum_fast &) \
DECL_ASN_OP_OTHER(op)
DECL_ASN_OP(=)
DECL_ASN_OP(*=)
DECL_ASN_OP(/=)
DECL_ASN_OP(+=)
DECL_ASN_OP(-=)
DECL_ASN_OP_T(<<=, int)
DECL_ASN_OP_T(>>=, int)
DECL_ASN_OP_T(&=, const sc_fix &)
DECL_ASN_OP_T(&=, const sc_fix_fast &)
DECL_ASN_OP_T(|=, const sc_fix &)
DECL_ASN_OP_T(|=, const sc_fix_fast &)
DECL_ASN_OP_T(^=, const sc_fix &)
DECL_ASN_OP_T(^=, const sc_fix_fast &)
#undef DECL_ASN_OP_T
#undef DECL_ASN_OP_OTHER
#undef DECL_ASN_OP
// auto-increment and auto-decrement
const sc_fxval_fast operator ++ (int);
const sc_fxval_fast operator -- (int);
sc_fixed_fast& operator ++ ();
sc_fixed_fast& operator -- ();
};
// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
// ----------------------------------------------------------------------------
// TEMPLATE CLASS : sc_fixed
//
// "Constrained" signed fixed-point class; arbitrary precision.
// ----------------------------------------------------------------------------
template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline sc_fixed<W, I, Q, O, N>::sc_fixed(sc_fxnum_observer *observer_) :
sc_fix(W, I, Q, O, N, observer_)
{}
template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline sc_fixed<W, I, Q, O, N>::sc_fixed(
const sc_fxcast_switch &cast_sw, sc_fxnum_observer *observer_) :
sc_fix(W, I, Q, O, N, cast_sw, observer_)
{}
#define DEFN_CTORS_T(tp) \
template <int W, int I, sc_q_mode Q, sc_o_mode O, int N> \
inline sc_fixed<W, I, Q, O, N>::sc_fixed( \
tp a, sc_fxnum_observer* observer_) : \
sc_fix(a, W, I, Q, O, N, observer_) \
{} \
\
template <int W, int I, sc_q_mode Q, sc_o_mode O, int N> \
inline sc_fixed<W, I, Q, O, N>::sc_fixed( \
tp a, const sc_fxcast_switch &cast_sw, \
sc_fxnum_observer *observer_) : \
sc_fix(a, W, I, Q, O, N, cast_sw, observer_) \
{}
DEFN_CTORS_T(int)
DEFN_CTORS_T(unsigned int)
DEFN_CTORS_T(long)
DEFN_CTORS_T(unsigned long)
DEFN_CTORS_T(float)
DEFN_CTORS_T(double)
DEFN_CTORS_T(const char *)
DEFN_CTORS_T(const sc_fxval &)
DEFN_CTORS_T(const sc_fxval_fast &)
DEFN_CTORS_T(const sc_fxnum &)
DEFN_CTORS_T(const sc_fxnum_fast &)
DEFN_CTORS_T(int64)
DEFN_CTORS_T(uint64)
DEFN_CTORS_T(const sc_int_base &)
DEFN_CTORS_T(const sc_uint_base &)
DEFN_CTORS_T(const sc_signed &)
DEFN_CTORS_T(const sc_unsigned &)
#undef DEFN_CTORS_T
// copy constructor
template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline sc_fixed<W, I, Q, O, N>::sc_fixed(const sc_fixed<W, I, Q, O, N> &a) :
sc_fix(a, W, I, Q, O, N)
{}
// assignment operators
template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline sc_fixed<W, I, Q, O, N> &
sc_fixed<W, I, Q, O, N>::operator = (const sc_fixed<W, I, Q, O, N> &a)
{
sc_fix::operator = (a);
return *this;
}
#define DEFN_ASN_OP_T(op, tp) \
template <int W, int I, sc_q_mode Q, sc_o_mode O, int N> \
inline sc_fixed<W, I, Q, O, N> & \
sc_fixed<W, I, Q, O, N>::operator op (tp a) \
{ \
sc_fix::operator op (a); \
return *this; \
}
#define DEFN_ASN_OP_OTHER(op) \
DEFN_ASN_OP_T(op, int64) \
DEFN_ASN_OP_T(op, uint64) \
DEFN_ASN_OP_T(op, const sc_int_base &) \
DEFN_ASN_OP_T(op, const sc_uint_base &) \
DEFN_ASN_OP_T(op, const sc_signed &) \
DEFN_ASN_OP_T(op, const sc_unsigned &)
#define DEFN_ASN_OP(op) \
DEFN_ASN_OP_T(op, int) \
DEFN_ASN_OP_T(op, unsigned int) \
DEFN_ASN_OP_T(op, long) \
DEFN_ASN_OP_T(op, unsigned long) \
DEFN_ASN_OP_T(op, float) \
DEFN_ASN_OP_T(op, double) \
DEFN_ASN_OP_T(op, const char *) \
DEFN_ASN_OP_T(op, const sc_fxval &) \
DEFN_ASN_OP_T(op, const sc_fxval_fast &) \
DEFN_ASN_OP_T(op, const sc_fxnum &) \
DEFN_ASN_OP_T(op, const sc_fxnum_fast &) \
DEFN_ASN_OP_OTHER(op)
DEFN_ASN_OP(=)
DEFN_ASN_OP(*=)
DEFN_ASN_OP(/=)
DEFN_ASN_OP(+=)
DEFN_ASN_OP(-=)
DEFN_ASN_OP_T(<<=, int)
DEFN_ASN_OP_T(>>=, int)
DEFN_ASN_OP_T(&=, const sc_fix &)
DEFN_ASN_OP_T(&=, const sc_fix_fast &)
DEFN_ASN_OP_T(|=, const sc_fix &)
DEFN_ASN_OP_T(|=, const sc_fix_fast &)
DEFN_ASN_OP_T(^=, const sc_fix &)
DEFN_ASN_OP_T(^=, const sc_fix_fast &)
#undef DEFN_ASN_OP_T
#undef DEFN_ASN_OP_OTHER
#undef DEFN_ASN_OP
// auto-increment and auto-decrement
template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline const sc_fxval
sc_fixed<W, I, Q, O, N>::operator ++ (int)
{
return sc_fxval(sc_fix::operator ++ (0));
}
template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline const sc_fxval
sc_fixed<W, I, Q, O, N>::operator -- (int)
{
return sc_fxval(sc_fix::operator -- (0));
}
template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline sc_fixed<W, I, Q, O, N> &
sc_fixed<W, I, Q, O, N>::operator ++ ()
{
sc_fix::operator ++ ();
return *this;
}
template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline sc_fixed<W, I, Q, O, N> &
sc_fixed<W, I, Q, O, N>::operator -- ()
{
sc_fix::operator -- ();
return *this;
}
// ----------------------------------------------------------------------------
// TEMPLATE CLASS : sc_fixed_fast
//
// "Constrained" signed fixed-point class; limited precision.
// ----------------------------------------------------------------------------
template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline sc_fixed_fast<W, I, Q, O, N>::sc_fixed_fast(
sc_fxnum_fast_observer *observer_) :
sc_fix_fast(W, I, Q, O, N, observer_)
{}
template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline sc_fixed_fast<W, I, Q, O, N>::sc_fixed_fast(
const sc_fxcast_switch &cast_sw, sc_fxnum_fast_observer *observer_) :
sc_fix_fast(W, I, Q, O, N, cast_sw, observer_)
{}
#define DEFN_CTORS_T(tp) \
template <int W, int I, sc_q_mode Q, sc_o_mode O, int N> \
inline sc_fixed_fast<W, I, Q, O, N>::sc_fixed_fast( \
tp a, sc_fxnum_fast_observer *observer_) : \
sc_fix_fast(a, W, I, Q, O, N, observer_) \
{} \
\
template <int W, int I, sc_q_mode Q, sc_o_mode O, int N> \
inline sc_fixed_fast<W, I, Q, O, N>::sc_fixed_fast( \
tp a, const sc_fxcast_switch &cast_sw, \
sc_fxnum_fast_observer *observer_) : \
sc_fix_fast(a, W, I, Q, O, N, cast_sw, observer_) \
{}
DEFN_CTORS_T(int)
DEFN_CTORS_T(unsigned int)
DEFN_CTORS_T(long)
DEFN_CTORS_T(unsigned long)
DEFN_CTORS_T(float)
DEFN_CTORS_T(double)
DEFN_CTORS_T(const char *)
DEFN_CTORS_T(const sc_fxval &)
DEFN_CTORS_T(const sc_fxval_fast &)
DEFN_CTORS_T(const sc_fxnum &)
DEFN_CTORS_T(const sc_fxnum_fast &)
DEFN_CTORS_T(int64)
DEFN_CTORS_T(uint64)
DEFN_CTORS_T(const sc_int_base &)
DEFN_CTORS_T(const sc_uint_base &)
DEFN_CTORS_T(const sc_signed &)
DEFN_CTORS_T(const sc_unsigned &)
#undef DEFN_CTORS_T
// copy constructor
template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline sc_fixed_fast<W, I, Q, O, N>::sc_fixed_fast(
const sc_fixed_fast<W, I, Q, O, N> &a) : sc_fix_fast(a, W, I, Q, O, N)
{}
// assignment operators
template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline sc_fixed_fast<W, I, Q, O, N> &
sc_fixed_fast<W, I, Q, O, N>::operator = (
const sc_fixed_fast<W, I, Q, O, N> &a)
{
sc_fix_fast::operator = (a);
return *this;
}
#define DEFN_ASN_OP_T(op, tp) \
template <int W, int I, sc_q_mode Q, sc_o_mode O, int N> \
inline sc_fixed_fast<W, I, Q, O, N> & \
sc_fixed_fast<W, I, Q, O, N>::operator op (tp a) \
{ \
sc_fix_fast::operator op (a); \
return *this; \
}
#define DEFN_ASN_OP_OTHER(op) \
DEFN_ASN_OP_T(op, int64) \
DEFN_ASN_OP_T(op, uint64) \
DEFN_ASN_OP_T(op, const sc_int_base &) \
DEFN_ASN_OP_T(op, const sc_uint_base &) \
DEFN_ASN_OP_T(op, const sc_signed &) \
DEFN_ASN_OP_T(op, const sc_unsigned &)
#define DEFN_ASN_OP(op) \
DEFN_ASN_OP_T(op, int) \
DEFN_ASN_OP_T(op, unsigned int) \
DEFN_ASN_OP_T(op, long) \
DEFN_ASN_OP_T(op, unsigned long) \
DEFN_ASN_OP_T(op, float) \
DEFN_ASN_OP_T(op, double) \
DEFN_ASN_OP_T(op, const char *) \
DEFN_ASN_OP_T(op, const sc_fxval &) \
DEFN_ASN_OP_T(op, const sc_fxval_fast &) \
DEFN_ASN_OP_T(op, const sc_fxnum &) \
DEFN_ASN_OP_T(op, const sc_fxnum_fast &) \
DEFN_ASN_OP_OTHER(op)
DEFN_ASN_OP(=)
DEFN_ASN_OP(*=)
DEFN_ASN_OP(/=)
DEFN_ASN_OP(+=)
DEFN_ASN_OP(-=)
DEFN_ASN_OP_T(<<=, int)
DEFN_ASN_OP_T(>>=, int)
DEFN_ASN_OP_T(&=, const sc_fix &)
DEFN_ASN_OP_T(&=, const sc_fix_fast &)
DEFN_ASN_OP_T(|=, const sc_fix &)
DEFN_ASN_OP_T(|=, const sc_fix_fast &)
DEFN_ASN_OP_T(^=, const sc_fix &)
DEFN_ASN_OP_T(^=, const sc_fix_fast &)
#undef DEFN_ASN_OP_T
#undef DEFN_ASN_OP_OTHER
#undef DEFN_ASN_OP
// auto-increment and auto-decrement
template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline const sc_fxval_fast
sc_fixed_fast<W, I, Q, O, N>::operator ++ (int)
{
return sc_fxval_fast(sc_fix_fast::operator ++ (0));
}
template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline const sc_fxval_fast
sc_fixed_fast<W, I, Q, O, N>::operator -- (int)
{
return sc_fxval_fast(sc_fix_fast::operator -- (0));
}
template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline sc_fixed_fast<W, I, Q, O, N> &
sc_fixed_fast<W, I, Q, O, N>::operator ++ ()
{
sc_fix_fast::operator ++ ();
return *this;
}
template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline sc_fixed_fast<W, I, Q, O, N> &
sc_fixed_fast<W, I, Q, O, N>::operator -- ()
{
sc_fix_fast::operator -- ();
return *this;
}
} // namespace sc_dt
#endif // __SYSTEMC_EXT_DT_FX_SC_FIXED_HH__

View File

@@ -0,0 +1,159 @@
/*****************************************************************************
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_fxcast_switch.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_fxcast_switch.h,v $
// Revision 1.2 2011/08/24 22:05:43 acg
// Torsten Maehne: initialization changes to remove warnings.
//
// 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_FXCAST_SWITCH_HH__
#define __SYSTEMC_EXT_DT_FX_SC_FXCAST_SWITCH_HH__
#include <iostream>
#include "sc_context.hh"
#include "sc_fxdefs.hh"
namespace sc_dt
{
// classes defined in this module
class sc_fxcast_switch;
// ----------------------------------------------------------------------------
// CLASS : sc_fxcast_switch
//
// Fixed-point cast switch class.
// ----------------------------------------------------------------------------
class sc_fxcast_switch
{
public:
sc_fxcast_switch();
sc_fxcast_switch(sc_switch);
sc_fxcast_switch(const sc_fxcast_switch &);
explicit sc_fxcast_switch(sc_without_context);
sc_fxcast_switch &operator = (const sc_fxcast_switch &);
friend bool operator == (const sc_fxcast_switch &,
const sc_fxcast_switch &);
friend bool operator != (const sc_fxcast_switch &,
const sc_fxcast_switch &);
const std::string to_string() const;
void print(::std::ostream & =::std::cout) const;
void dump(::std::ostream & =::std::cout) const;
private:
sc_switch m_sw;
};
} // namespace sc_dt
// ----------------------------------------------------------------------------
// TYPEDEF : sc_fxcast_context
//
// Context type for the fixed-point cast switch parameter.
// ----------------------------------------------------------------------------
namespace sc_dt
{
extern template class sc_global<sc_fxcast_switch>;
extern template class sc_context<sc_fxcast_switch>;
typedef sc_context<sc_fxcast_switch> sc_fxcast_context;
// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
inline sc_fxcast_switch::sc_fxcast_switch() : m_sw()
{
*this = sc_fxcast_context::default_value();
}
inline sc_fxcast_switch::sc_fxcast_switch(sc_switch sw_) : m_sw( sw_ ) {}
inline sc_fxcast_switch::sc_fxcast_switch(const sc_fxcast_switch &a) :
m_sw(a.m_sw)
{}
inline sc_fxcast_switch::sc_fxcast_switch(sc_without_context) :
m_sw(SC_DEFAULT_CAST_SWITCH_)
{}
inline sc_fxcast_switch &
sc_fxcast_switch::operator = (const sc_fxcast_switch &a)
{
if (&a != this) {
m_sw = a.m_sw;
}
return *this;
}
inline bool
operator == (const sc_fxcast_switch &a, const sc_fxcast_switch &b)
{
return (a.m_sw == b.m_sw);
}
inline bool
operator != (const sc_fxcast_switch &a, const sc_fxcast_switch &b)
{
return (a.m_sw != b.m_sw);
}
inline ::std::ostream &
operator << (::std::ostream &os, const sc_fxcast_switch &a)
{
a.print(os);
return os;
}
} // namespace sc_dt
#endif // __SYSTEMC_EXT_DT_FX_SC_FXCAST_SWITCH_HH__

View File

@@ -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__

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,175 @@
/*****************************************************************************
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_fxnum_observer.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_fxnum_observer.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:58 acg
// Andy Goodrich: added $Log command so that CVS comments are reproduced in
// the source.
//
#ifndef __SYSTEMC_EXT_DT_FX_SC_FXNUM_OBSERVER_HH__
#define __SYSTEMC_EXT_DT_FX_SC_FXNUM_OBSERVER_HH__
#include "sc_fxdefs.hh"
namespace sc_dt
{
// classes defined in this module
class sc_fxnum_observer;
class sc_fxnum_fast_observer;
// forward class declarations
class sc_fxnum;
class sc_fxnum_fast;
#ifdef SC_ENABLE_OBSERVERS
#define SC_FXNUM_OBSERVER_CONSTRUCT_(object) \
SC_OBSERVER_(object, sc_fxnum_observer *, construct)
#define SC_FXNUM_OBSERVER_DESTRUCT_(object) \
SC_OBSERVER_(object, sc_fxnum_observer *, destruct)
#define SC_FXNUM_OBSERVER_READ_(object) \
SC_OBSERVER_(object, sc_fxnum_observer *, read)
#define SC_FXNUM_OBSERVER_WRITE_(object) \
SC_OBSERVER_(object, sc_fxnum_observer *, write)
#define SC_FXNUM_OBSERVER_DEFAULT_ \
SC_OBSERVER_DEFAULT_(sc_fxnum_observer)
#define SC_FXNUM_FAST_OBSERVER_CONSTRUCT_(object) \
SC_OBSERVER_(object, sc_fxnum_fast_observer *, construct)
#define SC_FXNUM_FAST_OBSERVER_DESTRUCT_(object) \
SC_OBSERVER_(object, sc_fxnum_fast_observer *, destruct)
#define SC_FXNUM_FAST_OBSERVER_READ_(object) \
SC_OBSERVER_(object, sc_fxnum_fast_observer *, read)
#define SC_FXNUM_FAST_OBSERVER_WRITE_(object) \
SC_OBSERVER_(object, sc_fxnum_fast_observer *, write)
#define SC_FXNUM_FAST_OBSERVER_DEFAULT_ \
SC_OBSERVER_DEFAULT_(sc_fxnum_fast_observer)
#else
#define SC_FXNUM_OBSERVER_CONSTRUCT_(object)
#define SC_FXNUM_OBSERVER_DESTRUCT_(object)
#define SC_FXNUM_OBSERVER_READ_(object)
#define SC_FXNUM_OBSERVER_WRITE_(object)
#define SC_FXNUM_OBSERVER_DEFAULT_
#define SC_FXNUM_FAST_OBSERVER_CONSTRUCT_(object)
#define SC_FXNUM_FAST_OBSERVER_DESTRUCT_(object)
#define SC_FXNUM_FAST_OBSERVER_READ_(object)
#define SC_FXNUM_FAST_OBSERVER_WRITE_(object)
#define SC_FXNUM_FAST_OBSERVER_DEFAULT_
#endif
// ----------------------------------------------------------------------------
// CLASS : sc_fxnum_observer
//
// Abstract base class for fixed-point types observers; arbitrary precision.
// ----------------------------------------------------------------------------
class sc_fxnum_observer
{
protected:
sc_fxnum_observer() {}
virtual ~sc_fxnum_observer() {}
public:
virtual void construct(const sc_fxnum &);
virtual void destruct(const sc_fxnum &);
virtual void read(const sc_fxnum &);
virtual void write(const sc_fxnum &);
static sc_fxnum_observer *(* default_observer)();
};
// ----------------------------------------------------------------------------
// CLASS : sc_fxnum_fast_observer
//
// Abstract base class for fixed-point types observers; limited precision.
// ----------------------------------------------------------------------------
class sc_fxnum_fast_observer
{
protected:
sc_fxnum_fast_observer() {}
virtual ~sc_fxnum_fast_observer() {}
public:
virtual void construct(const sc_fxnum_fast &);
virtual void destruct(const sc_fxnum_fast &);
virtual void read(const sc_fxnum_fast &);
virtual void write(const sc_fxnum_fast &);
static sc_fxnum_fast_observer *(* default_observer) ();
};
// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
// ----------------------------------------------------------------------------
// CLASS : sc_fxnum_observer
//
// Abstract base class for fixed-point types observers; arbitrary precision.
// ----------------------------------------------------------------------------
inline void sc_fxnum_observer::construct(const sc_fxnum &) {}
inline void sc_fxnum_observer::destruct(const sc_fxnum &) {}
inline void sc_fxnum_observer::read(const sc_fxnum &) {}
inline void sc_fxnum_observer::write(const sc_fxnum &) {}
// ----------------------------------------------------------------------------
// CLASS : sc_fxnum_fast_observer
//
// Abstract base class for fixed-point types observers; limited precision.
// ----------------------------------------------------------------------------
inline void sc_fxnum_fast_observer::construct(const sc_fxnum_fast &) {}
inline void sc_fxnum_fast_observer::destruct(const sc_fxnum_fast &) {}
inline void sc_fxnum_fast_observer::read(const sc_fxnum_fast &) {}
inline void sc_fxnum_fast_observer::write(const sc_fxnum_fast &) {}
} // namespace sc_dt
#endif // __SYSTEMC_EXT_DT_FX_SC_FXNUM_OBSERVER_HH__

View File

@@ -0,0 +1,265 @@
/*****************************************************************************
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_fxtype_params.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_fxtype_params.h,v $
// Revision 1.2 2011/08/24 22:05:43 acg
// Torsten Maehne: initialization changes to remove warnings.
//
// Revision 1.1.1.1 2006/12/15 20:20:04 acg
// SystemC 2.3
//
// Revision 1.3 2006/01/13 18:53:58 acg
// Andy Goodrich: added $Log command so that CVS comments are reproduced in
// the source.
//
#ifndef __SYSTEMC_EXT_DT_FX_SC_FXTYPE_PARAMS_HH__
#define __SYSTEMC_EXT_DT_FX_SC_FXTYPE_PARAMS_HH__
#include <iostream>
#include "sc_context.hh"
#include "sc_fxdefs.hh"
namespace sc_dt
{
// classes defined in this module
class sc_fxtype_params;
// ----------------------------------------------------------------------------
// CLASS : sc_fxtype_params
//
// Fixed-point type parameters class.
// ----------------------------------------------------------------------------
class sc_fxtype_params
{
public:
sc_fxtype_params();
sc_fxtype_params(int, int);
sc_fxtype_params(sc_q_mode, sc_o_mode, int=0);
sc_fxtype_params(int, int, sc_q_mode, sc_o_mode, int=0);
sc_fxtype_params(const sc_fxtype_params &);
sc_fxtype_params(const sc_fxtype_params &, int, int);
sc_fxtype_params(const sc_fxtype_params&, sc_q_mode, sc_o_mode, int=0);
explicit sc_fxtype_params(sc_without_context);
sc_fxtype_params &operator = (const sc_fxtype_params &);
friend bool operator == (const sc_fxtype_params &,
const sc_fxtype_params &);
friend bool operator != (const sc_fxtype_params &,
const sc_fxtype_params &);
int wl() const;
void wl(int);
int iwl() const;
void iwl(int);
sc_q_mode q_mode() const;
void q_mode(sc_q_mode);
sc_o_mode o_mode() const;
void o_mode(sc_o_mode);
int n_bits() const;
void n_bits(int);
const std::string to_string() const;
void print(::std::ostream & =::std::cout) const;
void dump(::std::ostream & =::std::cout) const;
private:
int m_wl;
int m_iwl;
sc_q_mode m_q_mode;
sc_o_mode m_o_mode;
int m_n_bits;
};
} // namespace sc_dt
// ----------------------------------------------------------------------------
// TYPEDEF : sc_fxtype_context
//
// Context type for the fixed-point type parameters.
// ----------------------------------------------------------------------------
// extern template instantiations
namespace sc_dt
{
extern template class sc_global<sc_fxtype_params>;
extern template class sc_context<sc_fxtype_params>;
typedef sc_context<sc_fxtype_params> sc_fxtype_context;
// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
inline sc_fxtype_params::sc_fxtype_params() :
m_wl(), m_iwl(), m_q_mode(), m_o_mode(), m_n_bits()
{
*this = sc_fxtype_context::default_value();
}
inline sc_fxtype_params::sc_fxtype_params(int wl_, int iwl_) :
m_wl(), m_iwl(), m_q_mode(), m_o_mode(), m_n_bits()
{
*this = sc_fxtype_context::default_value();
SC_CHECK_WL_(wl_);
m_wl = wl_;
m_iwl = iwl_;
}
inline sc_fxtype_params::sc_fxtype_params(
sc_q_mode q_mode_, sc_o_mode o_mode_, int n_bits_) :
m_wl(), m_iwl(), m_q_mode(), m_o_mode(), m_n_bits()
{
*this = sc_fxtype_context::default_value();
SC_CHECK_N_BITS_(n_bits_);
m_q_mode = q_mode_;
m_o_mode = o_mode_;
m_n_bits = n_bits_;
}
inline sc_fxtype_params::sc_fxtype_params(
int wl_, int iwl_, sc_q_mode q_mode_, sc_o_mode o_mode_, int n_bits_) :
m_wl(), m_iwl(), m_q_mode(), m_o_mode(), m_n_bits()
{
SC_CHECK_WL_(wl_);
SC_CHECK_N_BITS_(n_bits_);
m_wl = wl_;
m_iwl = iwl_;
m_q_mode = q_mode_;
m_o_mode = o_mode_;
m_n_bits = n_bits_;
}
inline sc_fxtype_params::sc_fxtype_params(const sc_fxtype_params &a) :
m_wl(a.m_wl), m_iwl(a.m_iwl), m_q_mode(a.m_q_mode),
m_o_mode(a.m_o_mode), m_n_bits(a.m_n_bits)
{}
inline sc_fxtype_params::sc_fxtype_params(
const sc_fxtype_params &a, int wl_, int iwl_) :
m_wl(wl_), m_iwl(iwl_), m_q_mode(a.m_q_mode), m_o_mode(a.m_o_mode),
m_n_bits(a.m_n_bits)
{}
inline sc_fxtype_params::sc_fxtype_params(
const sc_fxtype_params &a, sc_q_mode q_mode_, sc_o_mode o_mode_,
int n_bits_) :
m_wl(a.m_wl), m_iwl(a.m_iwl), m_q_mode(q_mode_), m_o_mode(o_mode_),
m_n_bits(n_bits_)
{}
inline sc_fxtype_params::sc_fxtype_params(sc_without_context) :
m_wl(SC_DEFAULT_WL_), m_iwl(SC_DEFAULT_IWL_),
m_q_mode(SC_DEFAULT_Q_MODE_), m_o_mode(SC_DEFAULT_O_MODE_),
m_n_bits(SC_DEFAULT_N_BITS_)
{}
inline sc_fxtype_params &
sc_fxtype_params::operator = (const sc_fxtype_params &a)
{
if (&a != this) {
m_wl = a.m_wl;
m_iwl = a.m_iwl;
m_q_mode = a.m_q_mode;
m_o_mode = a.m_o_mode;
m_n_bits = a.m_n_bits;
}
return *this;
}
inline bool
operator == (const sc_fxtype_params &a, const sc_fxtype_params &b)
{
return (a.m_wl == b.m_wl && a.m_iwl == b.m_iwl &&
a.m_q_mode == b.m_q_mode && a.m_o_mode == b.m_o_mode &&
a.m_n_bits == b.m_n_bits);
}
inline bool
operator != (const sc_fxtype_params &a, const sc_fxtype_params &b)
{
return (a.m_wl != b.m_wl || a.m_iwl != b.m_iwl ||
a.m_q_mode != b.m_q_mode || a.m_o_mode != b.m_o_mode ||
a.m_n_bits != b.m_n_bits );
}
inline int sc_fxtype_params::wl() const { return m_wl; }
inline void
sc_fxtype_params::wl(int wl_)
{
SC_CHECK_WL_(wl_);
m_wl = wl_;
}
inline int sc_fxtype_params::iwl() const { return m_iwl; }
inline void sc_fxtype_params::iwl(int iwl_) { m_iwl = iwl_; }
inline sc_q_mode sc_fxtype_params::q_mode() const { return m_q_mode; }
inline void sc_fxtype_params::q_mode(sc_q_mode q_mode_) { m_q_mode = q_mode_; }
inline sc_o_mode sc_fxtype_params::o_mode() const { return m_o_mode; }
inline void sc_fxtype_params::o_mode(sc_o_mode o_mode_) { m_o_mode = o_mode_; }
inline int sc_fxtype_params::n_bits() const { return m_n_bits; }
inline void
sc_fxtype_params::n_bits(int n_bits_)
{
SC_CHECK_N_BITS_(n_bits_);
m_n_bits = n_bits_;
}
inline ::std::ostream &
operator << (::std::ostream &os, const sc_fxtype_params &a)
{
a.print(os);
return os;
}
} // namespace sc_dt
#endif // __SYSTEMC_EXT_DT_FX_SC_FXTYPE_PARAM_HH__

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,178 @@
/*****************************************************************************
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_fxval_observer.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_fxval_observer.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:58 acg
// Andy Goodrich: added $Log command so that CVS comments are reproduced in
// the source.
//
#ifndef __SYSTEMC_EXT_DT_FX_SC_FXVAL_OBSERVER_HH__
#define __SYSTEMC_EXT_DT_FX_SC_FXVAL_OBSERVER_HH__
#include "sc_fxdefs.hh"
namespace sc_dt
{
// classes defined in this module
class sc_fxval_observer;
class sc_fxval_fast_observer;
// forward class declarations
class sc_fxval;
class sc_fxval_fast;
#ifdef SC_ENABLE_OBSERVERS
#define SC_FXVAL_OBSERVER_CONSTRUCT_(object) \
SC_OBSERVER_(object, sc_fxval_observer *, construct)
#define SC_FXVAL_OBSERVER_DESTRUCT_(object) \
SC_OBSERVER_(object, sc_fxval_observer *, destruct)
#define SC_FXVAL_OBSERVER_READ_(object) \
SC_OBSERVER_(object, sc_fxval_observer *, read)
#define SC_FXVAL_OBSERVER_WRITE_(object) \
SC_OBSERVER_(object, sc_fxval_observer *, write)
#define SC_FXVAL_OBSERVER_DEFAULT_ \
SC_OBSERVER_DEFAULT_(sc_fxval_observer)
#define SC_FXVAL_FAST_OBSERVER_CONSTRUCT_(object) \
SC_OBSERVER_(object, sc_fxval_fast_observer *, construct)
#define SC_FXVAL_FAST_OBSERVER_DESTRUCT_(object) \
SC_OBSERVER_(object, sc_fxval_fast_observer *, destruct)
#define SC_FXVAL_FAST_OBSERVER_READ_(object) \
SC_OBSERVER_(object, sc_fxval_fast_observer *, read)
#define SC_FXVAL_FAST_OBSERVER_WRITE_(object) \
SC_OBSERVER_(object, sc_fxval_fast_observer *, write)
#define SC_FXVAL_FAST_OBSERVER_DEFAULT_ \
SC_OBSERVER_DEFAULT_(sc_fxval_fast_observer)
#else
#define SC_FXVAL_OBSERVER_CONSTRUCT_(object)
#define SC_FXVAL_OBSERVER_DESTRUCT_(object)
#define SC_FXVAL_OBSERVER_READ_(object)
#define SC_FXVAL_OBSERVER_WRITE_(object)
#define SC_FXVAL_OBSERVER_DEFAULT_
#define SC_FXVAL_FAST_OBSERVER_CONSTRUCT_(object)
#define SC_FXVAL_FAST_OBSERVER_DESTRUCT_(object)
#define SC_FXVAL_FAST_OBSERVER_READ_(object)
#define SC_FXVAL_FAST_OBSERVER_WRITE_(object)
#define SC_FXVAL_FAST_OBSERVER_DEFAULT_
#endif
// ----------------------------------------------------------------------------
// CLASS : sc_fxval_observer
//
// Abstract base class for fixed-point value type observers;
// arbitrary precision.
// ----------------------------------------------------------------------------
class sc_fxval_observer
{
protected:
sc_fxval_observer() {}
virtual ~sc_fxval_observer() {}
public:
virtual void construct(const sc_fxval &);
virtual void destruct(const sc_fxval &);
virtual void read(const sc_fxval &);
virtual void write(const sc_fxval &);
static sc_fxval_observer *(*default_observer) ();
};
// ----------------------------------------------------------------------------
// CLASS : sc_fxval_fast_observer
//
// Abstract base class for fixed-point value type observers;
// limited precision.
// ----------------------------------------------------------------------------
class sc_fxval_fast_observer
{
protected:
sc_fxval_fast_observer() {}
virtual ~sc_fxval_fast_observer() {}
public:
virtual void construct(const sc_fxval_fast &);
virtual void destruct(const sc_fxval_fast &);
virtual void read(const sc_fxval_fast &);
virtual void write(const sc_fxval_fast &);
static sc_fxval_fast_observer *(*default_observer) ();
};
// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
// ----------------------------------------------------------------------------
// CLASS : sc_fxval_observer
//
// Abstract base class for fixed-point value type observers;
// arbitrary precision.
// ----------------------------------------------------------------------------
inline void sc_fxval_observer::construct(const sc_fxval &) {}
inline void sc_fxval_observer::destruct(const sc_fxval &) {}
inline void sc_fxval_observer::read(const sc_fxval &) {}
inline void sc_fxval_observer::write(const sc_fxval &) {}
// ----------------------------------------------------------------------------
// CLASS : sc_fxval_fast_observer
//
// Abstract base class for fixed-point value type observers;
// limited precision.
// ----------------------------------------------------------------------------
inline void sc_fxval_fast_observer::construct(const sc_fxval_fast &) {}
inline void sc_fxval_fast_observer::destruct(const sc_fxval_fast &) {}
inline void sc_fxval_fast_observer::read(const sc_fxval_fast &) {}
inline void sc_fxval_fast_observer::write(const sc_fxval_fast &) {}
} // namespace sc_dt
#endif // __SYSTEMC_EXT_DT_FX_SC_FXVAL_OBSERVER_HH__

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,585 @@
/*****************************************************************************
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_ufixed.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_ufixed.h,v $
// Revision 1.2 2011/01/19 18:57:40 acg
// Andy Goodrich: changes for IEEE_1666_2011.
//
// Revision 1.1.1.1 2006/12/15 20:20:04 acg
// SystemC 2.3
//
// Revision 1.3 2006/01/13 18:53:58 acg
// Andy Goodrich: added $Log command so that CVS comments are reproduced in
// the source.
//
#ifndef __SYSTEMC_EXT_DT_FX_SC_UFIXED_HH__
#define __SYSTEMC_EXT_DT_FX_SC_UFIXED_HH__
#include "sc_ufix.hh"
namespace sc_dt
{
// classes defined in this module
template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
class sc_ufixed;
template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
class sc_ufixed_fast;
// ----------------------------------------------------------------------------
// TEMPLATE CLASS : sc_ufixed
//
// "Constrained" unsigned fixed-point class; arbitrary precision.
// ----------------------------------------------------------------------------
template <int W, int I,
sc_q_mode Q=SC_DEFAULT_Q_MODE_,
sc_o_mode O=SC_DEFAULT_O_MODE_, int N=SC_DEFAULT_N_BITS_>
class sc_ufixed : public sc_ufix
{
public:
// constructors
explicit sc_ufixed(sc_fxnum_observer * =0);
explicit sc_ufixed(const sc_fxcast_switch &, sc_fxnum_observer * =0);
#define DECL_CTORS_T_A(tp) \
sc_ufixed(tp, sc_fxnum_observer * =0); \
sc_ufixed(tp, const sc_fxcast_switch &, sc_fxnum_observer * =0);
#define DECL_CTORS_T_B(tp) \
explicit sc_ufixed(tp, sc_fxnum_observer * =0); \
sc_ufixed(tp, const sc_fxcast_switch &, sc_fxnum_observer * =0);
DECL_CTORS_T_A(int)
DECL_CTORS_T_A(unsigned int)
DECL_CTORS_T_A(long)
DECL_CTORS_T_A(unsigned long)
DECL_CTORS_T_A(float)
DECL_CTORS_T_A(double)
DECL_CTORS_T_A(const char *)
DECL_CTORS_T_A(const sc_fxval &)
DECL_CTORS_T_A(const sc_fxval_fast &)
DECL_CTORS_T_A(const sc_fxnum &)
DECL_CTORS_T_A(const sc_fxnum_fast &)
DECL_CTORS_T_B(int64)
DECL_CTORS_T_B(uint64)
DECL_CTORS_T_B(const sc_int_base &)
DECL_CTORS_T_B(const sc_uint_base &)
DECL_CTORS_T_B(const sc_signed &)
DECL_CTORS_T_B(const sc_unsigned &)
#undef DECL_CTORS_T_A
#undef DECL_CTORS_T_B
// copy constructor
sc_ufixed(const sc_ufixed<W, I, Q, O, N> &);
// assignment operators
sc_ufixed &operator = (const sc_ufixed<W, I, Q, O, N> &);
#define DECL_ASN_OP_T(op,tp) sc_ufixed &operator op (tp);
#define DECL_ASN_OP_OTHER(op) \
DECL_ASN_OP_T(op, int64) \
DECL_ASN_OP_T(op, uint64) \
DECL_ASN_OP_T(op, const sc_int_base &) \
DECL_ASN_OP_T(op, const sc_uint_base &) \
DECL_ASN_OP_T(op, const sc_signed &) \
DECL_ASN_OP_T(op, const sc_unsigned &)
#define DECL_ASN_OP(op) \
DECL_ASN_OP_T(op, int) \
DECL_ASN_OP_T(op, unsigned int) \
DECL_ASN_OP_T(op, long) \
DECL_ASN_OP_T(op, unsigned long) \
DECL_ASN_OP_T(op, float) \
DECL_ASN_OP_T(op, double) \
DECL_ASN_OP_T(op, const char *) \
DECL_ASN_OP_T(op, const sc_fxval &) \
DECL_ASN_OP_T(op, const sc_fxval_fast &) \
DECL_ASN_OP_T(op, const sc_fxnum &) \
DECL_ASN_OP_T(op, const sc_fxnum_fast &) \
DECL_ASN_OP_OTHER(op)
DECL_ASN_OP(=)
DECL_ASN_OP(*=)
DECL_ASN_OP(/=)
DECL_ASN_OP(+=)
DECL_ASN_OP(-=)
DECL_ASN_OP_T(<<=, int)
DECL_ASN_OP_T(>>=, int)
DECL_ASN_OP_T(&=, const sc_ufix &)
DECL_ASN_OP_T(&=, const sc_ufix_fast &)
DECL_ASN_OP_T(|=, const sc_ufix &)
DECL_ASN_OP_T(|=, const sc_ufix_fast &)
DECL_ASN_OP_T(^=, const sc_ufix &)
DECL_ASN_OP_T(^=, const sc_ufix_fast &)
#undef DECL_ASN_OP_T
#undef DECL_ASN_OP_OTHER
#undef DECL_ASN_OP
// auto-increment and auto-decrement
const sc_fxval operator ++ (int);
const sc_fxval operator -- (int);
sc_ufixed &operator ++ ();
sc_ufixed &operator -- ();
};
// ----------------------------------------------------------------------------
// TEMPLATE CLASS : sc_ufixed_fast
//
// "Constrained" unsigned fixed-point class; limited precision.
// ----------------------------------------------------------------------------
template <int W, int I,
sc_q_mode Q=SC_DEFAULT_Q_MODE_,
sc_o_mode O=SC_DEFAULT_O_MODE_, int N=SC_DEFAULT_N_BITS_>
class sc_ufixed_fast : public sc_ufix_fast
{
public:
// constructors
explicit sc_ufixed_fast(sc_fxnum_fast_observer * =0);
explicit sc_ufixed_fast(const sc_fxcast_switch &,
sc_fxnum_fast_observer * =0);
#define DECL_CTORS_T_A(tp) \
sc_ufixed_fast(tp, sc_fxnum_fast_observer * =0); \
sc_ufixed_fast(tp, const sc_fxcast_switch &, sc_fxnum_fast_observer * =0);
#define DECL_CTORS_T_B(tp) \
explicit sc_ufixed_fast(tp, sc_fxnum_fast_observer * =0); \
sc_ufixed_fast(tp, const sc_fxcast_switch &, sc_fxnum_fast_observer * =0);
DECL_CTORS_T_A(int)
DECL_CTORS_T_A(unsigned int)
DECL_CTORS_T_A(long)
DECL_CTORS_T_A(unsigned long)
DECL_CTORS_T_A(float)
DECL_CTORS_T_A(double)
DECL_CTORS_T_A(const char *)
DECL_CTORS_T_A(const sc_fxval &)
DECL_CTORS_T_A(const sc_fxval_fast &)
DECL_CTORS_T_A(const sc_fxnum &)
DECL_CTORS_T_A(const sc_fxnum_fast &)
DECL_CTORS_T_B(int64)
DECL_CTORS_T_B(uint64)
DECL_CTORS_T_B(const sc_int_base &)
DECL_CTORS_T_B(const sc_uint_base &)
DECL_CTORS_T_B(const sc_signed &)
DECL_CTORS_T_B(const sc_unsigned &)
#undef DECL_CTORS_T_A
#undef DECL_CTORS_T_B
// copy constructor
sc_ufixed_fast(const sc_ufixed_fast<W, I, Q, O, N> &);
// assignment operators
sc_ufixed_fast &operator = (const sc_ufixed_fast<W, I, Q, O, N> &);
#define DECL_ASN_OP_T(op,tp) sc_ufixed_fast &operator op (tp);
#define DECL_ASN_OP_OTHER(op) \
DECL_ASN_OP_T(op, int64) \
DECL_ASN_OP_T(op, uint64) \
DECL_ASN_OP_T(op, const sc_int_base &) \
DECL_ASN_OP_T(op, const sc_uint_base &) \
DECL_ASN_OP_T(op, const sc_signed &) \
DECL_ASN_OP_T(op, const sc_unsigned &)
#define DECL_ASN_OP(op) \
DECL_ASN_OP_T(op, int) \
DECL_ASN_OP_T(op, unsigned int) \
DECL_ASN_OP_T(op, long) \
DECL_ASN_OP_T(op, unsigned long) \
DECL_ASN_OP_T(op, float) \
DECL_ASN_OP_T(op, double) \
DECL_ASN_OP_T(op, const char *) \
DECL_ASN_OP_T(op, const sc_fxval &) \
DECL_ASN_OP_T(op, const sc_fxval_fast &) \
DECL_ASN_OP_T(op, const sc_fxnum &) \
DECL_ASN_OP_T(op, const sc_fxnum_fast &) \
DECL_ASN_OP_OTHER(op)
DECL_ASN_OP(=)
DECL_ASN_OP(*=)
DECL_ASN_OP(/=)
DECL_ASN_OP(+=)
DECL_ASN_OP(-=)
DECL_ASN_OP_T(<<=, int)
DECL_ASN_OP_T(>>=, int)
DECL_ASN_OP_T(&=, const sc_ufix &)
DECL_ASN_OP_T(&=, const sc_ufix_fast &)
DECL_ASN_OP_T(|=, const sc_ufix &)
DECL_ASN_OP_T(|=, const sc_ufix_fast &)
DECL_ASN_OP_T(^=, const sc_ufix &)
DECL_ASN_OP_T(^=, const sc_ufix_fast &)
#undef DECL_ASN_OP_T
#undef DECL_ASN_OP_OTHER
#undef DECL_ASN_OP
// auto-increment and auto-decrement
const sc_fxval_fast operator ++ (int);
const sc_fxval_fast operator -- (int);
sc_ufixed_fast& operator ++ ();
sc_ufixed_fast& operator -- ();
};
// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
// ----------------------------------------------------------------------------
// TEMPLATE CLASS : sc_ufixed
//
// "Constrained" unsigned fixed-point class; arbitrary precision.
// ----------------------------------------------------------------------------
template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline sc_ufixed<W, I, Q, O, N>::sc_ufixed(sc_fxnum_observer *observer_) :
sc_ufix(W, I, Q, O, N, observer_)
{}
template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline sc_ufixed<W, I, Q, O, N>::sc_ufixed(const sc_fxcast_switch &cast_sw,
sc_fxnum_observer *observer_) :
sc_ufix(W, I, Q, O, N, cast_sw, observer_)
{}
#define DEFN_CTORS_T(tp) \
template<int W, int I, sc_q_mode Q, sc_o_mode O, int N> \
inline sc_ufixed<W, I, Q, O, N>::sc_ufixed( \
tp a, sc_fxnum_observer *observer_) :\
sc_ufix(a, W, I, Q, O, N, observer_) \
{} \
\
template<int W, int I, sc_q_mode Q, sc_o_mode O, int N> \
inline sc_ufixed<W, I, Q, O, N>::sc_ufixed( \
tp a, const sc_fxcast_switch &cast_sw, \
sc_fxnum_observer *observer_) : \
sc_ufix(a, W, I, Q, O, N, cast_sw, observer_) \
{}
DEFN_CTORS_T(int)
DEFN_CTORS_T(unsigned int)
DEFN_CTORS_T(long)
DEFN_CTORS_T(unsigned long)
DEFN_CTORS_T(float)
DEFN_CTORS_T(double)
DEFN_CTORS_T(const char *)
DEFN_CTORS_T(const sc_fxval &)
DEFN_CTORS_T(const sc_fxval_fast &)
DEFN_CTORS_T(const sc_fxnum &)
DEFN_CTORS_T(const sc_fxnum_fast &)
DEFN_CTORS_T(int64)
DEFN_CTORS_T(uint64)
DEFN_CTORS_T(const sc_int_base &)
DEFN_CTORS_T(const sc_uint_base &)
DEFN_CTORS_T(const sc_signed &)
DEFN_CTORS_T(const sc_unsigned &)
#undef DEFN_CTORS_T
// copy constructor
template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline sc_ufixed<W, I, Q, O, N>::sc_ufixed(const sc_ufixed<W, I, Q, O, N> &a) :
sc_ufix(a, W, I, Q, O, N)
{}
// assignment operators
template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline sc_ufixed<W, I, Q, O, N> &
sc_ufixed<W, I, Q, O, N>::operator = (const sc_ufixed<W, I, Q, O, N> &a)
{
sc_ufix::operator = (a);
return *this;
}
#define DEFN_ASN_OP_T(op,tp) \
template<int W, int I, sc_q_mode Q, sc_o_mode O, int N> \
inline sc_ufixed<W, I, Q, O, N> & \
sc_ufixed<W, I, Q, O, N>::operator op (tp a) \
{ \
sc_ufix::operator op (a); \
return *this; \
}
#define DEFN_ASN_OP_OTHER(op) \
DEFN_ASN_OP_T(op, int64) \
DEFN_ASN_OP_T(op, uint64) \
DEFN_ASN_OP_T(op, const sc_int_base &) \
DEFN_ASN_OP_T(op, const sc_uint_base &) \
DEFN_ASN_OP_T(op, const sc_signed &) \
DEFN_ASN_OP_T(op, const sc_unsigned &)
#define DEFN_ASN_OP(op) \
DEFN_ASN_OP_T(op, int) \
DEFN_ASN_OP_T(op, unsigned int) \
DEFN_ASN_OP_T(op, long) \
DEFN_ASN_OP_T(op, unsigned long) \
DEFN_ASN_OP_T(op, float) \
DEFN_ASN_OP_T(op, double) \
DEFN_ASN_OP_T(op, const char *) \
DEFN_ASN_OP_T(op, const sc_fxval &) \
DEFN_ASN_OP_T(op, const sc_fxval_fast &) \
DEFN_ASN_OP_T(op, const sc_fxnum &) \
DEFN_ASN_OP_T(op, const sc_fxnum_fast &) \
DEFN_ASN_OP_OTHER(op)
DEFN_ASN_OP(=)
DEFN_ASN_OP(*=)
DEFN_ASN_OP(/=)
DEFN_ASN_OP(+=)
DEFN_ASN_OP(-=)
DEFN_ASN_OP_T(<<=, int)
DEFN_ASN_OP_T(>>=, int)
DEFN_ASN_OP_T(&=, const sc_ufix &)
DEFN_ASN_OP_T(&=, const sc_ufix_fast &)
DEFN_ASN_OP_T(|=, const sc_ufix &)
DEFN_ASN_OP_T(|=, const sc_ufix_fast &)
DEFN_ASN_OP_T(^=, const sc_ufix &)
DEFN_ASN_OP_T(^=, const sc_ufix_fast &)
#undef DEFN_ASN_OP_T
#undef DEFN_ASN_OP_OTHER
#undef DEFN_ASN_OP
// auto-increment and auto-decrement
template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline const sc_fxval
sc_ufixed<W, I, Q, O, N>::operator ++ (int)
{
return sc_fxval(sc_ufix::operator ++ (0));
}
template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline const sc_fxval
sc_ufixed<W, I, Q, O, N>::operator -- (int)
{
return sc_fxval(sc_ufix::operator -- (0));
}
template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline sc_ufixed<W, I, Q, O, N> &
sc_ufixed<W, I, Q, O, N>::operator ++ ()
{
sc_ufix::operator ++ ();
return *this;
}
template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline sc_ufixed<W, I, Q, O, N> &
sc_ufixed<W, I, Q, O, N>::operator -- ()
{
sc_ufix::operator -- ();
return *this;
}
// ----------------------------------------------------------------------------
// TEMPLATE CLASS : sc_ufixed_fast
//
// "Constrained" unsigned fixed-point class; limited precision.
// ----------------------------------------------------------------------------
template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline sc_ufixed_fast<W, I, Q, O, N>::sc_ufixed_fast(
sc_fxnum_fast_observer *observer_) :
sc_ufix_fast(W, I, Q, O, N, observer_)
{}
template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline sc_ufixed_fast<W, I, Q, O, N>::sc_ufixed_fast(
const sc_fxcast_switch &cast_sw,
sc_fxnum_fast_observer *observer_) :
sc_ufix_fast(W, I, Q, O, N, cast_sw, observer_)
{}
#define DEFN_CTORS_T(tp) \
template<int W, int I, sc_q_mode Q, sc_o_mode O, int N> \
inline sc_ufixed_fast<W, I, Q, O, N>::sc_ufixed_fast( \
tp a, sc_fxnum_fast_observer *observer_ ) : \
sc_ufix_fast(a, W, I, Q, O, N, observer_) \
{} \
\
template<int W, int I, sc_q_mode Q, sc_o_mode O, int N> \
inline sc_ufixed_fast<W, I, Q, O, N>::sc_ufixed_fast( \
tp a, const sc_fxcast_switch &cast_sw, \
sc_fxnum_fast_observer *observer_) : \
sc_ufix_fast(a, W, I, Q, O, N, cast_sw, observer_) \
{}
DEFN_CTORS_T(int)
DEFN_CTORS_T(unsigned int)
DEFN_CTORS_T(long)
DEFN_CTORS_T(unsigned long)
DEFN_CTORS_T(float)
DEFN_CTORS_T(double)
DEFN_CTORS_T(const char *)
DEFN_CTORS_T(const sc_fxval &)
DEFN_CTORS_T(const sc_fxval_fast &)
DEFN_CTORS_T(const sc_fxnum &)
DEFN_CTORS_T(const sc_fxnum_fast &)
DEFN_CTORS_T(int64)
DEFN_CTORS_T(uint64)
DEFN_CTORS_T(const sc_int_base &)
DEFN_CTORS_T(const sc_uint_base &)
DEFN_CTORS_T(const sc_signed &)
DEFN_CTORS_T(const sc_unsigned &)
#undef DEFN_CTORS_T
// copy constructor
template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline sc_ufixed_fast<W, I, Q, O, N>::sc_ufixed_fast(
const sc_ufixed_fast<W, I, Q, O, N> &a) :
sc_ufix_fast(a, W, I, Q, O, N)
{}
// assignment operators
template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline sc_ufixed_fast<W, I, Q, O, N> &
sc_ufixed_fast<W, I, Q, O, N>::operator = (
const sc_ufixed_fast<W, I, Q, O, N> &a)
{
sc_ufix_fast::operator = (a);
return *this;
}
#define DEFN_ASN_OP_T(op, tp) \
template<int W, int I, sc_q_mode Q, sc_o_mode O, int N> \
inline sc_ufixed_fast<W, I, Q, O, N> & \
sc_ufixed_fast<W, I, Q, O, N>::operator op (tp a) \
{ \
sc_ufix_fast::operator op (a); \
return *this; \
}
#define DEFN_ASN_OP_OTHER(op) \
DEFN_ASN_OP_T(op, int64) \
DEFN_ASN_OP_T(op, uint64) \
DEFN_ASN_OP_T(op, const sc_int_base &) \
DEFN_ASN_OP_T(op, const sc_uint_base &) \
DEFN_ASN_OP_T(op, const sc_signed &) \
DEFN_ASN_OP_T(op, const sc_unsigned &)
#define DEFN_ASN_OP(op) \
DEFN_ASN_OP_T(op, int) \
DEFN_ASN_OP_T(op, unsigned int) \
DEFN_ASN_OP_T(op, long) \
DEFN_ASN_OP_T(op, unsigned long) \
DEFN_ASN_OP_T(op, float) \
DEFN_ASN_OP_T(op, double) \
DEFN_ASN_OP_T(op, const char *) \
DEFN_ASN_OP_T(op, const sc_fxval &) \
DEFN_ASN_OP_T(op, const sc_fxval_fast &) \
DEFN_ASN_OP_T(op, const sc_fxnum &) \
DEFN_ASN_OP_T(op, const sc_fxnum_fast &) \
DEFN_ASN_OP_OTHER(op)
DEFN_ASN_OP(=)
DEFN_ASN_OP(*=)
DEFN_ASN_OP(/=)
DEFN_ASN_OP(+=)
DEFN_ASN_OP(-=)
DEFN_ASN_OP_T(<<=, int)
DEFN_ASN_OP_T(>>=, int)
DEFN_ASN_OP_T(&=, const sc_ufix &)
DEFN_ASN_OP_T(&=, const sc_ufix_fast &)
DEFN_ASN_OP_T(|=, const sc_ufix &)
DEFN_ASN_OP_T(|=, const sc_ufix_fast &)
DEFN_ASN_OP_T(^=, const sc_ufix &)
DEFN_ASN_OP_T(^=, const sc_ufix_fast &)
#undef DEFN_ASN_OP_T
#undef DEFN_ASN_OP_OTHER
#undef DEFN_ASN_OP
// auto-increment and auto-decrement
template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline const sc_fxval_fast
sc_ufixed_fast<W, I, Q, O, N>::operator ++ (int)
{
return sc_fxval_fast( sc_ufix_fast::operator ++ (0));
}
template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline const sc_fxval_fast
sc_ufixed_fast<W, I, Q, O, N>::operator -- (int)
{
return sc_fxval_fast( sc_ufix_fast::operator -- (0));
}
template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline sc_ufixed_fast<W, I, Q, O, N> &
sc_ufixed_fast<W, I, Q, O, N>::operator ++ ()
{
sc_ufix_fast::operator ++ ();
return *this;
}
template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
inline sc_ufixed_fast<W, I, Q, O, N> &
sc_ufixed_fast<W,I,Q,O,N>::operator -- ()
{
sc_ufix_fast::operator -- ();
return *this;
}
} // namespace sc_dt
#endif // __SYSTEMC_EXT_DT_FX_SC_UFIXED_HH__

View File

@@ -0,0 +1,613 @@
/*****************************************************************************
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.
*****************************************************************************/
/*****************************************************************************
scfx_ieee.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: scfx_ieee.h,v $
// Revision 1.3 2011/08/24 22:05:43 acg
// Torsten Maehne: initialization changes to remove warnings.
//
// Revision 1.2 2011/08/07 18:55:24 acg
// Philipp A. Hartmann: added guard for __clang__ to get the clang platform
// working.
//
// Revision 1.1.1.1 2006/12/15 20:20:04 acg
// SystemC 2.3
//
// Revision 1.3 2006/01/13 18:53:58 acg
// Andy Goodrich: added $Log command so that CVS comments are reproduced in
// the source.
//
#ifndef __SYSTEMC_EXT_DT_FX_SCFX_IEEE_HH__
#define __SYSTEMC_EXT_DT_FX_SCFX_IEEE_HH__
#include "../../utils/endian.hh"
#include "sc_fxdefs.hh"
namespace sc_dt
{
// classes defined in this module
union ieee_double;
class scfx_ieee_double;
union ieee_float;
class scfx_ieee_float;
#define SCFX_MASK_(Size) ((1u << (Size))-1u)
// ----------------------------------------------------------------------------
// UNION : ieee_double
//
// IEEE 754 double-precision format.
// ----------------------------------------------------------------------------
union ieee_double
{
double d;
struct
{
#if defined(SC_BOOST_BIG_ENDIAN)
unsigned negative:1;
unsigned exponent:11;
unsigned mantissa0:20;
unsigned mantissa1:32;
#elif defined(SC_BOOST_LITTLE_ENDIAN)
unsigned mantissa1:32;
unsigned mantissa0:20;
unsigned exponent:11;
unsigned negative:1;
#endif
} s;
};
const unsigned int SCFX_IEEE_DOUBLE_BIAS = 1023U;
const int SCFX_IEEE_DOUBLE_E_MAX = 1023;
const int SCFX_IEEE_DOUBLE_E_MIN = -1022;
const unsigned int SCFX_IEEE_DOUBLE_M_SIZE = 52;
const unsigned int SCFX_IEEE_DOUBLE_M0_SIZE = 20;
const unsigned int SCFX_IEEE_DOUBLE_M1_SIZE = 32;
const unsigned int SCFX_IEEE_DOUBLE_E_SIZE = 11;
// ----------------------------------------------------------------------------
// CLASS : scfx_ieee_double
//
// Convenient interface to union ieee_double.
// ----------------------------------------------------------------------------
class scfx_ieee_double
{
ieee_double m_id;
public:
scfx_ieee_double();
scfx_ieee_double(double);
scfx_ieee_double(const scfx_ieee_double &);
scfx_ieee_double &operator = (double);
scfx_ieee_double &operator = (const scfx_ieee_double &);
operator double() const;
unsigned int negative() const;
void negative(unsigned int);
int exponent() const;
void exponent(int);
unsigned int mantissa0() const;
void mantissa0(unsigned int);
unsigned int mantissa1() const;
void mantissa1(unsigned int);
bool is_zero() const;
bool is_subnormal() const;
bool is_normal() const;
bool is_inf() const;
bool is_nan() const;
void set_inf();
void set_nan();
int msb() const; // most significant non-zero bit
int lsb() const; // least significant non-zero bit
static const scfx_ieee_double nan();
static const scfx_ieee_double inf(int);
};
// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
inline scfx_ieee_double::scfx_ieee_double() : m_id()
{
m_id.d = 0.0;
}
inline scfx_ieee_double::scfx_ieee_double(double d) : m_id()
{
m_id.d = d;
}
inline scfx_ieee_double::scfx_ieee_double(const scfx_ieee_double &a) :
m_id(a.m_id)
{
// m_id.d = a.m_id.d;
}
inline scfx_ieee_double &
scfx_ieee_double::operator = (double d)
{
m_id.d = d;
return *this;
}
inline scfx_ieee_double &
scfx_ieee_double::operator = (const scfx_ieee_double &a)
{
m_id.d = a.m_id.d;
return *this;
}
inline scfx_ieee_double::operator double() const
{
return m_id.d;
}
inline unsigned int
scfx_ieee_double::negative() const
{
return m_id.s.negative;
}
inline void
scfx_ieee_double::negative(unsigned int a)
{
m_id.s.negative = a & SCFX_MASK_(1);
}
inline int
scfx_ieee_double::exponent() const
{
return m_id.s.exponent - SCFX_IEEE_DOUBLE_BIAS;
}
inline void
scfx_ieee_double::exponent(int a)
{
m_id.s.exponent = (SCFX_IEEE_DOUBLE_BIAS + a)
& SCFX_MASK_(SCFX_IEEE_DOUBLE_E_SIZE);
}
inline unsigned int
scfx_ieee_double::mantissa0() const
{
return m_id.s.mantissa0;
}
inline void
scfx_ieee_double::mantissa0(unsigned int a)
{
m_id.s.mantissa0 = a & SCFX_MASK_(SCFX_IEEE_DOUBLE_M0_SIZE);
}
inline unsigned int
scfx_ieee_double::mantissa1() const
{
return m_id.s.mantissa1;
}
inline void
scfx_ieee_double::mantissa1(unsigned int a)
{
m_id.s.mantissa1 = a; // & SCFX_MASK_(SCFX_IEEE_DOUBLE_M1_SIZE);
}
inline bool
scfx_ieee_double::is_zero() const
{
return (exponent() == SCFX_IEEE_DOUBLE_E_MIN - 1 &&
mantissa0() == 0U && mantissa1() == 0U);
}
inline bool
scfx_ieee_double::is_subnormal() const
{
return (exponent() == SCFX_IEEE_DOUBLE_E_MIN - 1 &&
(mantissa0() != 0U || mantissa1() != 0U));
}
inline bool
scfx_ieee_double::is_normal() const
{
return (exponent() >= SCFX_IEEE_DOUBLE_E_MIN &&
exponent() <= SCFX_IEEE_DOUBLE_E_MAX);
}
inline bool
scfx_ieee_double::is_inf() const
{
return (exponent() == SCFX_IEEE_DOUBLE_E_MAX + 1 &&
mantissa0() == 0U && mantissa1() == 0U);
}
inline bool
scfx_ieee_double::is_nan() const
{
return (exponent() == SCFX_IEEE_DOUBLE_E_MAX + 1 &&
(mantissa0() != 0U || mantissa1() != 0U));
}
inline void
scfx_ieee_double::set_inf()
{
exponent(SCFX_IEEE_DOUBLE_E_MAX + 1);
mantissa0(0U);
mantissa1(0U);
}
inline void
scfx_ieee_double::set_nan()
{
exponent(SCFX_IEEE_DOUBLE_E_MAX + 1);
mantissa0((unsigned int)-1);
mantissa1((unsigned int)-1);
}
#define MSB_STATEMENT(x,n) if ( x >> n ) { x >>= n; i += n; }
inline int
scfx_ieee_double::msb() const
{
unsigned int m0 = mantissa0();
unsigned int m1 = mantissa1();
if (m0 != 0) {
int i = 0;
MSB_STATEMENT(m0, 16);
MSB_STATEMENT(m0, 8);
MSB_STATEMENT(m0, 4);
MSB_STATEMENT(m0, 2);
MSB_STATEMENT(m0, 1);
return (i - 20);
} else if (m1 != 0) {
int i = 0;
MSB_STATEMENT(m1, 16);
MSB_STATEMENT(m1, 8);
MSB_STATEMENT(m1, 4);
MSB_STATEMENT(m1, 2);
MSB_STATEMENT(m1, 1);
return (i - 52);
} else {
return 0;
}
}
#undef MSB_STATEMENT
#define LSB_STATEMENT(x,n) if ( x << n ) { x <<= n; i -= n; }
inline int
scfx_ieee_double::lsb() const
{
unsigned int m0 = mantissa0();
unsigned int m1 = mantissa1();
if (m1 != 0) {
int i = 31;
LSB_STATEMENT(m1, 16);
LSB_STATEMENT(m1, 8);
LSB_STATEMENT(m1, 4);
LSB_STATEMENT(m1, 2);
LSB_STATEMENT(m1, 1);
return (i - 52);
} else if (m0 != 0) {
int i = 31;
LSB_STATEMENT(m0, 16);
LSB_STATEMENT(m0, 8);
LSB_STATEMENT(m0, 4);
LSB_STATEMENT(m0, 2);
LSB_STATEMENT(m0, 1);
return (i - 20);
} else {
return 0;
}
}
#undef LSB_STATEMENT
inline const scfx_ieee_double
scfx_ieee_double::nan()
{
scfx_ieee_double id;
id.set_nan();
return id;
}
inline const scfx_ieee_double
scfx_ieee_double::inf(int sign)
{
scfx_ieee_double id(sign);
id.set_inf();
return id;
}
// ----------------------------------------------------------------------------
// UNION : ieee_float
//
// IEEE 754 single-precision format.
// ----------------------------------------------------------------------------
union ieee_float
{
float f;
struct
{
#if defined(SC_BOOST_BIG_ENDIAN)
unsigned negative:1;
unsigned exponent:8;
unsigned mantissa:23;
#elif defined(SC_BOOST_LITTLE_ENDIAN)
unsigned mantissa:23;
unsigned exponent:8;
unsigned negative:1;
#endif
} s;
};
const unsigned int SCFX_IEEE_FLOAT_BIAS = 127U;
const int SCFX_IEEE_FLOAT_E_MAX = 127;
const int SCFX_IEEE_FLOAT_E_MIN = -126;
const unsigned int SCFX_IEEE_FLOAT_M_SIZE = 23;
const unsigned int SCFX_IEEE_FLOAT_E_SIZE = 8;
// ----------------------------------------------------------------------------
// CLASS : scfx_ieee_float
//
// Convenient wrapper to union ieee_float.
// ----------------------------------------------------------------------------
class scfx_ieee_float
{
ieee_float m_if;
public:
scfx_ieee_float();
scfx_ieee_float(float);
scfx_ieee_float(const scfx_ieee_float &);
scfx_ieee_float &operator = (float);
scfx_ieee_float &operator = (const scfx_ieee_float &);
operator float() const;
unsigned int negative() const;
void negative(unsigned int);
int exponent() const;
void exponent(int);
unsigned int mantissa() const;
void mantissa(unsigned int);
bool is_zero() const;
bool is_subnormal() const;
bool is_normal() const;
bool is_inf() const;
bool is_nan() const;
void set_inf();
void set_nan();
};
// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
inline scfx_ieee_float::scfx_ieee_float() : m_if()
{
m_if.f = 0.0;
}
inline scfx_ieee_float::scfx_ieee_float(float f) : m_if()
{
m_if.f = f;
}
inline scfx_ieee_float::scfx_ieee_float(const scfx_ieee_float &a) :
m_if(a.m_if)
{
// m_if.f = a.m_if.f;
}
inline scfx_ieee_float &
scfx_ieee_float::operator = (float f)
{
m_if.f = f;
return *this;
}
inline scfx_ieee_float &
scfx_ieee_float::operator = (const scfx_ieee_float &a)
{
m_if.f = a.m_if.f;
return *this;
}
inline scfx_ieee_float::operator float() const
{
return m_if.f;
}
inline unsigned int
scfx_ieee_float::negative() const
{
return m_if.s.negative;
}
inline void
scfx_ieee_float::negative(unsigned int a)
{
m_if.s.negative = a & SCFX_MASK_(1);
}
inline int
scfx_ieee_float::exponent() const
{
return m_if.s.exponent - SCFX_IEEE_FLOAT_BIAS;
}
inline void
scfx_ieee_float::exponent(int a)
{
m_if.s.exponent = (SCFX_IEEE_FLOAT_BIAS + a) &
SCFX_MASK_(SCFX_IEEE_FLOAT_E_SIZE);
}
inline unsigned int
scfx_ieee_float::mantissa() const
{
return m_if.s.mantissa;
}
inline void
scfx_ieee_float::mantissa(unsigned int a)
{
m_if.s.mantissa = a & SCFX_MASK_(SCFX_IEEE_FLOAT_M_SIZE);
}
inline bool
scfx_ieee_float::is_zero() const
{
return (exponent() == SCFX_IEEE_FLOAT_E_MIN - 1 && mantissa() == 0U);
}
inline bool
scfx_ieee_float::is_subnormal() const
{
return (exponent() == SCFX_IEEE_FLOAT_E_MIN - 1 && mantissa() != 0U);
}
inline bool
scfx_ieee_float::is_normal() const
{
return (exponent() >= SCFX_IEEE_FLOAT_E_MIN &&
exponent() <= SCFX_IEEE_FLOAT_E_MAX);
}
inline bool
scfx_ieee_float::is_inf() const
{
return (exponent() == SCFX_IEEE_FLOAT_E_MAX + 1 && mantissa() == 0U);
}
inline bool
scfx_ieee_float::is_nan() const
{
return (exponent() == SCFX_IEEE_FLOAT_E_MAX + 1 && mantissa() != 0U);
}
inline void
scfx_ieee_float::set_inf()
{
exponent(SCFX_IEEE_FLOAT_E_MAX + 1);
mantissa(0U);
}
inline void
scfx_ieee_float::set_nan()
{
exponent(SCFX_IEEE_FLOAT_E_MAX + 1);
mantissa((unsigned int)-1);
}
// ----------------------------------------------------------------------------
// FUNCTION : scfx_pow2
//
// Computes 2.0**exp in double-precision.
// ----------------------------------------------------------------------------
inline double
scfx_pow2(int exp)
{
scfx_ieee_double r;
if (exp < SCFX_IEEE_DOUBLE_E_MIN) {
r = 0.0;
// handle subnormal case
exp -= SCFX_IEEE_DOUBLE_E_MIN;
if ((exp += 20) >= 0) {
r.mantissa0(1U << exp);
} else if ((exp += 32) >= 0) {
r.mantissa1(1U << exp);
}
} else if (exp > SCFX_IEEE_DOUBLE_E_MAX) {
r.set_inf();
} else {
r = 1.0;
r.exponent(exp);
}
return r;
}
// ----------------------------------------------------------------------------
// FUNCTION : uint64_to_double
//
// Platform independent conversion from double uint64 to double.
// Needed because VC++6 doesn't support this conversion.
// ----------------------------------------------------------------------------
inline double
uint64_to_double(uint64 a)
{
#if defined(__clang__)
// conversion from uint64 to double not implemented; use int64
double tmp = static_cast<double>(static_cast<int64>(a));
return (tmp >= 0) ? tmp : tmp + sc_dt::scfx_pow2(64);
#else
return static_cast<double>(a);
#endif
}
} // namespace sc_dt
#undef SCFX_MASK_
#endif // __SYSTEMC_EXT_DT_FX_SCFX_IEEE_HH__

View File

@@ -0,0 +1,415 @@
/*****************************************************************************
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.
*****************************************************************************/
/*****************************************************************************
scfx_mant.h -
Original Author: Robert Graulich, Synopsys, Inc.
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: scfx_mant.h,v $
// Revision 1.2 2011/08/24 22:05:43 acg
// Torsten Maehne: initialization changes to remove warnings.
//
// Revision 1.1.1.1 2006/12/15 20:20:04 acg
// SystemC 2.3
//
// Revision 1.3 2006/01/13 18:53:58 acg
// Andy Goodrich: added $Log command so that CVS comments are reproduced in
// the source.
//
#ifndef __SYSTEMC_EXT_DT_FX_SCFX_MANT_HH__
#define __SYSTEMC_EXT_DT_FX_SCFX_MANT_HH__
#include "../../utils/endian.hh"
#include "../../utils/functions.hh"
#include "scfx_ieee.hh"
#include "scfx_utils.hh"
namespace sc_dt
{
// classes defined in this module
class scfx_mant;
class scfx_mant_ref;
typedef unsigned int word; // Using int because of 64-bit machines.
typedef unsigned short half_word;
// ----------------------------------------------------------------------------
// CLASS : scfx_mant
//
// Mantissa class.
// ----------------------------------------------------------------------------
class scfx_mant
{
word *m_array;
int m_size;
public:
explicit scfx_mant(std::size_t);
scfx_mant(const scfx_mant &);
scfx_mant &operator = (const scfx_mant &);
~scfx_mant();
void clear();
void resize_to(int, int=0);
int size() const;
word operator [] (int) const;
word &operator [] (int);
half_word half_at(int) const;
half_word &half_at(int);
half_word *half_addr(int=0) const;
private:
static word *alloc(std::size_t);
static void free(word *, std::size_t);
static word *alloc_word(std::size_t size);
static void free_word(word *array, std::size_t size);
};
// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
inline int scfx_mant::size() const { return m_size; }
inline word *
scfx_mant::alloc(std::size_t size)
{
#if defined(SC_BOOST_BIG_ENDIAN )
return alloc_word(size) + (size - 1);
#elif defined(SC_BOOST_LITTLE_ENDIAN)
return alloc_word(size);
#endif
}
inline void
scfx_mant::free(word *mant, std::size_t size)
{
#if defined(SC_BOOST_BIG_ENDIAN)
free_word(mant - (size - 1), size);
#elif defined(SC_BOOST_LITTLE_ENDIAN)
free_word(mant, size);
#endif
}
inline word
scfx_mant::operator [] (int i) const
{
SC_ASSERT_(i >= 0 && i < m_size, "mantissa index out of range");
#if defined(SC_BOOST_BIG_ENDIAN)
return m_array[-i];
#elif defined(SC_BOOST_LITTLE_ENDIAN)
return m_array[i];
#endif
}
inline word &
scfx_mant::operator [] (int i)
{
SC_ASSERT_(i >= 0 && i < m_size, "mantissa index out of range");
#if defined(SC_BOOST_BIG_ENDIAN)
return m_array[-i];
#elif defined(SC_BOOST_LITTLE_ENDIAN)
return m_array[i];
#endif
}
inline scfx_mant::scfx_mant(std::size_t size_) : m_array(0), m_size(size_)
{
m_array = alloc(size_);
}
inline scfx_mant::scfx_mant(const scfx_mant &rhs) :
m_array(0), m_size(rhs.m_size)
{
m_array = alloc(m_size);
for (int i = 0; i < m_size; i++) {
(*this)[i] = rhs[i];
}
}
inline scfx_mant &
scfx_mant::operator = (const scfx_mant &rhs)
{
if (&rhs != this) {
if (m_size != rhs.m_size) {
free(m_array, m_size);
m_array = alloc(m_size = rhs.m_size);
}
for (int i = 0; i < m_size; i++) {
(*this)[i] = rhs[i];
}
}
return *this;
}
inline scfx_mant::~scfx_mant()
{
if (m_array != 0) {
free(m_array, m_size);
}
}
inline void
scfx_mant::clear()
{
for (int i = 0; i < m_size; i++) {
(*this)[i] = 0;
}
}
inline void
scfx_mant::resize_to(int size, int restore)
{
if (size == m_size) {
return;
}
if (!m_array) {
m_array = alloc(m_size = size);
} else {
word* p = alloc(size);
if (restore) {
int end = sc_min(size, m_size);
if (restore == 1) { // msb resized -> align at 0
for (int i = 0; i < size; i++) {
if (i < end) {
#if defined(SC_BOOST_BIG_ENDIAN)
p[-i] = m_array[-i];
#elif defined(SC_BOOST_LITTLE_ENDIAN)
p[i] = m_array[i];
#endif
} else {
#if defined(SC_BOOST_BIG_ENDIAN)
p[-i] = 0;
#elif defined(SC_BOOST_LITTLE_ENDIAN)
p[i] = 0;
#endif
}
}
} else { // lsb resized -> align at size - 1
for (int i = 0; i < size; i++) {
if (i < end) {
#if defined(SC_BOOST_BIG_ENDIAN)
p[-size + 1 + i] = m_array[-m_size + 1 + i];
#elif defined(SC_BOOST_LITTLE_ENDIAN)
p[size - 1 - i] = m_array[m_size - 1 - i];
#endif
} else {
#if defined(SC_BOOST_BIG_ENDIAN)
p[-size + 1 + i] = 0;
#elif defined(SC_BOOST_LITTLE_ENDIAN)
p[size - 1 - i] = 0;
#endif
}
}
}
}
free(m_array, m_size);
m_array = p;
m_size = size;
}
}
inline half_word
scfx_mant::half_at(int i) const
{
SC_ASSERT_((i >> 1) >= 0 && (i >> 1) < m_size,
"mantissa index out of range");
#if defined(SC_BOOST_BIG_ENDIAN)
return reinterpret_cast<half_word *>(m_array)[-i];
#elif defined(SC_BOOST_LITTLE_ENDIAN )
return reinterpret_cast<half_word *>(m_array)[i];
#endif
}
inline half_word &
scfx_mant::half_at(int i)
{
SC_ASSERT_((i >> 1) >= 0 && (i >> 1) < m_size,
"mantissa index out of range" );
#if defined(SC_BOOST_BIG_ENDIAN)
return reinterpret_cast<half_word *>(m_array)[-i];
#elif defined(SC_BOOST_LITTLE_ENDIAN)
return reinterpret_cast<half_word *>(m_array)[i];
#endif
}
inline half_word *
scfx_mant::half_addr(int i) const
{
SC_ASSERT_(i >= 0 && i < m_size, "mantissa index out of range");
#if defined(SC_BOOST_BIG_ENDIAN)
return reinterpret_cast<half_word *>(m_array - i) + 1;
#elif defined(SC_BOOST_LITTLE_ENDIAN)
return reinterpret_cast<half_word *>(m_array + i);
#endif
}
// ----------------------------------------------------------------------------
// one's complement of a mantissa
// ----------------------------------------------------------------------------
inline void
complement(scfx_mant &target, const scfx_mant &source, int size)
{
for (int i = 0; i < size; i++) {
target[i] = ~source[i];
}
}
// ----------------------------------------------------------------------------
// increment mantissa
// ----------------------------------------------------------------------------
inline void
inc(scfx_mant &mant)
{
for (int i = 0; i < mant.size(); i++) {
if (++mant[i]) {
break;
}
}
}
// ----------------------------------------------------------------------------
// CLASS : scfx_mant_ref
//
// Mantissa reference class.
// ----------------------------------------------------------------------------
class scfx_mant_ref
{
scfx_mant *m_mant;
bool m_not_const;
public:
scfx_mant_ref();
scfx_mant_ref(const scfx_mant &);
scfx_mant_ref(scfx_mant *);
scfx_mant_ref &operator = (const scfx_mant &);
scfx_mant_ref &operator = (scfx_mant *);
~scfx_mant_ref();
operator scfx_mant & ();
word operator [] (int);
private:
void remove_it();
scfx_mant_ref(const scfx_mant_ref &);
scfx_mant_ref &operator = (const scfx_mant_ref &);
void *operator new(std::size_t sz) { return ::operator new (sz); }
};
// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
inline void
scfx_mant_ref::remove_it()
{
if (m_not_const) {
delete m_mant;
}
}
inline scfx_mant_ref::scfx_mant_ref() : m_mant(0), m_not_const(false) {}
inline scfx_mant_ref::scfx_mant_ref(const scfx_mant &mant) :
m_mant(const_cast<scfx_mant *>(& mant)), m_not_const(false)
{}
inline scfx_mant_ref::scfx_mant_ref(scfx_mant *mant) :
m_mant(mant), m_not_const(true)
{}
inline scfx_mant_ref &
scfx_mant_ref::operator = (const scfx_mant &mant)
{
remove_it();
m_mant = const_cast<scfx_mant *>(&mant);
m_not_const = false;
return *this;
}
inline scfx_mant_ref &
scfx_mant_ref::operator = (scfx_mant *mant)
{
remove_it();
m_mant = mant;
m_not_const = true;
return *this;
}
inline scfx_mant_ref::~scfx_mant_ref()
{
remove_it();
}
inline scfx_mant_ref::operator scfx_mant & ()
{
// SC_ASSERT_(m_not_const, "not allowed to modify mant");
return *m_mant;
}
inline word
scfx_mant_ref::operator [] (int i)
{
return (*m_mant)[i];
}
} // namespace sc_dt
#endif // __SYSTEMC_EXT_DT_FX_SCFX_MANT_HH__

View File

@@ -0,0 +1,324 @@
/*****************************************************************************
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.
*****************************************************************************/
/*****************************************************************************
scfx_other_defs.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: scfx_other_defs.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:58 acg
// Andy Goodrich: added $Log command so that CVS comments are reproduced in
// the source.
//
#ifndef __SYSTEMC_EXT_DT_FX_SCFX_OTHER_DEFS_HH__
#define __SYSTEMC_EXT_DT_FX_SCFX_OTHER_DEFS_HH__
#include "../int/sc_int_base.hh"
#include "../int/sc_signed.hh"
#include "../int/sc_uint_base.hh"
#include "../int/sc_unsigned.hh"
namespace sc_dt
{
// ----------------------------------------------------------------------------
// CLASS : sc_signed
// ----------------------------------------------------------------------------
// assignment operators
inline const sc_signed &
sc_signed::operator = (const sc_fxval &v)
{
if (!v.is_normal()) { /* also triggers OBSERVER_READ call */
SC_REPORT_ERROR("invalid fixed-point value",
"sc_signed::operator = ( const sc_fxval& )");
return *this;
}
for (int i = 0; i < length(); ++i)
(*this)[i] = v.get_bit(i);
return *this;
}
inline const sc_signed &
sc_signed::operator = (const sc_fxval_fast &v)
{
if (!v.is_normal()) { /* also triggers OBSERVER_READ call */
SC_REPORT_ERROR("invalid fixed-point value",
"sc_signed::operator = ( const sc_fxval_fast& )");
return *this;
}
for (int i = 0; i < length(); ++i)
(*this)[i] = v.get_bit(i);
return *this;
}
inline const sc_signed &
sc_signed::operator = (const sc_fxnum &v)
{
if (!v.is_normal()) { /* also triggers OBSERVER_READ call */
SC_REPORT_ERROR("invalid fixed-point value",
"sc_signed::operator = ( const sc_fxnum& )");
return *this;
}
for (int i = 0; i < length(); ++i)
(*this)[i] = v.get_bit(i);
return *this;
}
inline const sc_signed &
sc_signed::operator = (const sc_fxnum_fast &v)
{
if (!v.is_normal()) { /* also triggers OBSERVER_READ call */
SC_REPORT_ERROR("invalid fixed-point value",
"sc_signed::operator = ( const sc_fxnum_fast& )");
return *this;
}
for (int i = 0; i < length(); ++i)
(*this)[i] = v.get_bit(i);
return *this;
}
// ----------------------------------------------------------------------------
// CLASS : sc_unsigned
// ----------------------------------------------------------------------------
// assignment operators
inline const sc_unsigned &
sc_unsigned::operator = (const sc_fxval &v)
{
if (!v.is_normal()) { /* also triggers OBSERVER_READ call */
SC_REPORT_ERROR("invalid fixed-point value",
"sc_unsigned::operator = ( const sc_fxval& )");
return *this;
}
for (int i = 0; i < length(); ++i)
(*this)[i] = v.get_bit(i);
return *this;
}
inline const sc_unsigned &
sc_unsigned::operator = (const sc_fxval_fast &v)
{
if (!v.is_normal()) { /* also triggers OBSERVER_READ call */
SC_REPORT_ERROR("invalid fixed-point value",
"sc_unsigned::operator = ( const sc_fxval_fast& )");
return *this;
}
for (int i = 0; i < length(); ++i)
(*this)[i] = v.get_bit(i);
return *this;
}
inline const sc_unsigned &
sc_unsigned::operator = (const sc_fxnum &v)
{
if (!v.is_normal()) { /* also triggers OBSERVER_READ call */
SC_REPORT_ERROR("invalid fixed-point value",
"sc_unsigned::operator = ( const sc_fxnum& )" );
return *this;
}
for (int i = 0; i < length(); ++i)
(*this)[i] = v.get_bit(i);
return *this;
}
inline const sc_unsigned &
sc_unsigned::operator = (const sc_fxnum_fast &v)
{
if (!v.is_normal()) { /* also triggers OBSERVER_READ call */
SC_REPORT_ERROR("invalid fixed-point value",
"sc_unsigned::operator = ( const sc_fxnum_fast& )" );
return *this;
}
for (int i = 0; i < length(); ++i)
(*this)[i] = v.get_bit(i);
return *this;
}
// ----------------------------------------------------------------------------
// CLASS : sc_int_base
// ----------------------------------------------------------------------------
// assignment operators
inline sc_int_base &
sc_int_base::operator = (const sc_fxval &v)
{
if (!v.is_normal()) { /* also triggers OBSERVER_READ call */
SC_REPORT_ERROR("invalid fixed-point value",
"sc_int_base::operator = ( const sc_fxval& )");
return *this;
}
for (int i = 0; i < m_len; ++i) {
set(i, v.get_bit(i));
}
extend_sign();
return *this;
}
inline sc_int_base &
sc_int_base::operator = (const sc_fxval_fast &v)
{
if (!v.is_normal()) { /* also triggers OBSERVER_READ call */
SC_REPORT_ERROR("invalid fixed-point value",
"sc_int_base::operator = ( const sc_fxval_fast& )");
return *this;
}
for (int i = 0; i < m_len; ++i) {
set(i, v.get_bit(i));
}
extend_sign();
return *this;
}
inline sc_int_base &
sc_int_base::operator = (const sc_fxnum &v)
{
if (!v.is_normal()) { /* also triggers OBSERVER_READ call */
SC_REPORT_ERROR("invalid fixed-point value",
"sc_int_base::operator = ( const sc_fxnum& )");
return *this;
}
for (int i = 0; i < m_len; ++i) {
set(i, v.get_bit(i));
}
extend_sign();
return *this;
}
inline sc_int_base &
sc_int_base::operator = (const sc_fxnum_fast &v)
{
if (!v.is_normal()) { /* also triggers OBSERVER_READ call */
SC_REPORT_ERROR("invalid fixed-point value",
"sc_int_base::operator = ( const sc_fxnum_fast& )");
return *this;
}
for (int i = 0; i < m_len; ++i) {
set (i, v.get_bit(i));
}
extend_sign();
return *this;
}
// ----------------------------------------------------------------------------
// CLASS : sc_uint_base
// ----------------------------------------------------------------------------
// assignment operators
inline sc_uint_base &
sc_uint_base::operator = (const sc_fxval &v)
{
if (!v.is_normal()) { /* also triggers OBSERVER_READ call */
SC_REPORT_ERROR("invalid fixed-point value",
"sc_uint_base::operator = ( const sc_fxval& )");
return *this;
}
for (int i = 0; i < m_len; ++i) {
set(i, v.get_bit(i));
}
extend_sign();
return *this;
}
inline sc_uint_base &
sc_uint_base::operator = (const sc_fxval_fast &v)
{
if (!v.is_normal()) { /* also triggers OBSERVER_READ call */
SC_REPORT_ERROR("invalid fixed-point value",
"sc_uint_base::operator = ( const sc_fxval_fast& )");
return *this;
}
for (int i = 0; i < m_len; ++i) {
set(i, v.get_bit(i));
}
extend_sign();
return *this;
}
inline sc_uint_base &
sc_uint_base::operator = (const sc_fxnum &v)
{
if (!v.is_normal()) { /* also triggers OBSERVER_READ call */
SC_REPORT_ERROR("invalid fixed-point value",
"sc_uint_base::operator = ( const sc_fxnum& )");
return *this;
}
for (int i = 0; i < m_len; ++i) {
set(i, v.get_bit(i));
}
extend_sign();
return *this;
}
inline sc_uint_base &
sc_uint_base::operator = (const sc_fxnum_fast &v)
{
if (!v.is_normal()) { /* also triggers OBSERVER_READ call */
SC_REPORT_ERROR("invalid fixed-point value",
"sc_uint_base::operator = ( const sc_fxnum_fast& )");
return *this;
}
for (int i = 0; i < m_len; ++i) {
set(i, v.get_bit(i));
}
extend_sign();
return *this;
}
} // namespace sc_dt
#endif // __SYSTEMC_EXT_DT_FX_SCFX_OTHER_DEFS_HH__

View File

@@ -0,0 +1,182 @@
/*****************************************************************************
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.
*****************************************************************************/
/*****************************************************************************
scfx_params.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: scfx_params.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:58 acg
// Andy Goodrich: added $Log command so that CVS comments are reproduced in
// the source.
//
#ifndef __SYSTEMC_EXT_DT_FX_SCFX_PARAMS_HH__
#define __SYSTEMC_EXT_DT_FX_SCFX_PARAMS_HH__
#include "sc_fxcast_switch.hh"
#include "sc_fxtype_params.hh"
namespace sc_dt
{
// classes defined in this module
class scfx_params;
// ----------------------------------------------------------------------------
// CLASS : scfx_params
//
// ...
// ----------------------------------------------------------------------------
class scfx_params
{
public:
// constructor
scfx_params(const sc_fxtype_params &, sc_enc, const sc_fxcast_switch &);
// query functions
const sc_fxtype_params &type_params() const;
sc_enc enc() const;
const sc_fxcast_switch &cast_switch() const;
// shortcuts
int wl() const;
int iwl() const;
int fwl() const;
sc_q_mode q_mode() const;
sc_o_mode o_mode() const;
int n_bits() const;
// dump content
void dump(::std::ostream &) const;
private:
sc_fxtype_params m_type_params;
sc_enc m_enc;
sc_fxcast_switch m_cast_switch;
};
// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
// constructor
inline scfx_params::scfx_params(const sc_fxtype_params &type_params_,
sc_enc enc_,
const sc_fxcast_switch &cast_sw) :
m_type_params(type_params_), m_enc(enc_), m_cast_switch(cast_sw)
{
if (m_enc == SC_US_ && m_type_params.o_mode() == SC_WRAP_SM) {
SC_REPORT_ERROR("invalid overflow mode",
"SC_WRAP_SM not defined for unsigned numbers");
// may continue, if suppressed
}
}
// query functions
inline const sc_fxtype_params &
scfx_params::type_params() const
{
return m_type_params;
}
inline sc_enc
scfx_params::enc() const
{
return m_enc;
}
inline const sc_fxcast_switch &
scfx_params::cast_switch() const
{
return m_cast_switch;
}
// shortcuts
inline int
scfx_params::wl() const
{
return m_type_params.wl();
}
inline int
scfx_params::iwl() const
{
return m_type_params.iwl();
}
inline int
scfx_params::fwl() const
{
return (m_type_params.wl() - m_type_params.iwl());
}
inline sc_q_mode
scfx_params::q_mode() const
{
return m_type_params.q_mode();
}
inline sc_o_mode
scfx_params::o_mode() const
{
return m_type_params.o_mode();
}
inline int
scfx_params::n_bits() const
{
return m_type_params.n_bits();
}
// dump content
inline void
scfx_params::dump(::std::ostream &os) const
{
os << "scfx_params" << ::std::endl;
os << "(" << ::std::endl;
os << "type_params = ";
m_type_params.dump( os );
os << "enc = " << m_enc << ::std::endl;
os << "cast_switch = ";
m_cast_switch.dump( os );
os << ")" << ::std::endl;
}
} // namespace sc_dt
#endif // __SYSTEMC_EXT_DT_FX_SCFX_PARAMS_HH__

View File

@@ -0,0 +1,86 @@
/*****************************************************************************
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.
*****************************************************************************/
/*****************************************************************************
scfx_pow10.h -
Original Author: Robert Graulich, Synopsys, Inc.
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: scfx_pow10.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:58 acg
// Andy Goodrich: added $Log command so that CVS comments are reproduced in
// the source.
//
#ifndef __SYSTEMC_EXT_DT_FX_SCFX_POW10_HH__
#define __SYSTEMC_EXT_DT_FX_SCFX_POW10_HH__
#include "scfx_rep.hh"
namespace sc_dt
{
// classes defined in this module
class scfx_pow10;
// ----------------------------------------------------------------------------
// CLASS : scfx_pow10
//
// Class to compute (and cache) powers of 10 in arbitrary precision.
// ----------------------------------------------------------------------------
const int SCFX_POW10_TABLE_SIZE = 32;
class scfx_pow10
{
public:
scfx_pow10();
~scfx_pow10();
const scfx_rep operator() (int);
private:
scfx_rep *pos(int);
scfx_rep *neg(int);
scfx_rep m_pos[SCFX_POW10_TABLE_SIZE];
scfx_rep m_neg[SCFX_POW10_TABLE_SIZE];
};
} // namespace sc_dt
#endif // __SYSTEMC_EXT_DT_FX_SCFX_POW10_HH__

View File

@@ -0,0 +1,724 @@
/*****************************************************************************
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.
*****************************************************************************/
/*****************************************************************************
scfx_rep.h -
Original Author: Robert Graulich, Synopsys, Inc.
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: scfx_rep.h,v $
// Revision 1.6 2011/08/24 22:05:43 acg
// Torsten Maehne: initialization changes to remove warnings.
//
// Revision 1.5 2011/07/25 10:20:29 acg
// Andy Goodrich: check in aftermath of call to automake.
//
// Revision 1.4 2010/12/07 20:09:08 acg
// Andy Goodrich: Philipp Hartmann's constructor disambiguation fix
//
// Revision 1.3 2010/08/03 15:54:52 acg
// Andy Goodrich: formatting.
//
// Revision 1.2 2010/03/15 18:29:01 acg
// Andy Goodrich: Moved default argument specifications from friend
// declarations to the actual function signatures.
//
// Revision 1.1.1.1 2006/12/15 20:20:04 acg
// SystemC 2.3
//
// Revision 1.4 2006/03/13 20:24:27 acg
// Andy Goodrich: Addition of function declarations, e.g., neg_scfx_rep(),
// to keep gcc 4.x happy.
//
// Revision 1.3 2006/01/13 18:53:58 acg
// Andy Goodrich: added $Log command so that CVS comments are reproduced in
// the source.
//
#ifndef __SYSTEMC_EXT_DT_FX_SCFX_REP_HH__
#define __SYSTEMC_EXT_DT_FX_SCFX_REP_HH__
#include <climits>
#include "scfx_mant.hh"
#include "scfx_params.hh"
#include "scfx_string.hh"
namespace sc_dt
{
// classes defined in this module
class scfx_index;
class scfx_rep;
// forward class declarations
class sc_bv_base;
class sc_signed;
class sc_unsigned;
// function declarations
void multiply(scfx_rep &, const scfx_rep &, const scfx_rep &,
int max_wl=SC_DEFAULT_MAX_WL_);
scfx_rep *neg_scfx_rep(const scfx_rep &);
scfx_rep *mult_scfx_rep(const scfx_rep &, const scfx_rep &,
int max_wl=SC_DEFAULT_MAX_WL_);
scfx_rep *div_scfx_rep(const scfx_rep &, const scfx_rep &,
int max_wl=SC_DEFAULT_DIV_WL_);
scfx_rep *add_scfx_rep(const scfx_rep &, const scfx_rep &,
int max_wl=SC_DEFAULT_MAX_WL_);
scfx_rep *sub_scfx_rep(const scfx_rep &, const scfx_rep &,
int max_wl=SC_DEFAULT_MAX_WL_);
scfx_rep *lsh_scfx_rep(const scfx_rep &, int);
scfx_rep *rsh_scfx_rep(const scfx_rep &, int);
int cmp_scfx_rep(const scfx_rep &, const scfx_rep &);
const int min_mant = 4;
const int bits_in_int = sizeof(int) * CHAR_BIT;
const int bits_in_word = sizeof(word) * CHAR_BIT;
// ----------------------------------------------------------------------------
// CLASS : scfx_index
// ----------------------------------------------------------------------------
class scfx_index
{
public:
scfx_index(int wi_, int bi_) : m_wi(wi_), m_bi(bi_) {}
int wi() const { return m_wi; }
int bi() const { return m_bi; }
void wi(int wi_) { m_wi = wi_; }
private:
int m_wi;
int m_bi;
};
// ----------------------------------------------------------------------------
// CLASS : scfx_rep
//
// Arbitrary-precision fixed-point implementation class.
// ----------------------------------------------------------------------------
class scfx_rep
{
enum state
{
normal,
infinity,
not_a_number
};
public:
// constructors
scfx_rep();
explicit scfx_rep(int);
explicit scfx_rep(unsigned int);
explicit scfx_rep(long);
explicit scfx_rep(unsigned long);
explicit scfx_rep(double);
explicit scfx_rep(const char *);
explicit scfx_rep(int64);
explicit scfx_rep(uint64);
explicit scfx_rep(const sc_signed &);
explicit scfx_rep(const sc_unsigned &);
// copy constructor
scfx_rep(const scfx_rep &);
// destructor
~scfx_rep();
void *operator new (std::size_t);
void operator delete (void *, std::size_t);
void from_string(const char *, int);
double to_double() const;
uint64 to_uint64() const;
const char *to_string(sc_numrep, int, sc_fmt,
const scfx_params * =0) const;
// assignment operator
void operator = (const scfx_rep &);
friend void multiply( scfx_rep&, const scfx_rep&, const scfx_rep&, int );
friend scfx_rep *neg_scfx_rep(const scfx_rep &);
friend scfx_rep *mult_scfx_rep(const scfx_rep &, const scfx_rep &, int);
friend scfx_rep *div_scfx_rep(const scfx_rep &, const scfx_rep &, int);
friend scfx_rep *add_scfx_rep(const scfx_rep &, const scfx_rep &, int);
friend scfx_rep *sub_scfx_rep(const scfx_rep &, const scfx_rep &, int);
friend scfx_rep *lsh_scfx_rep(const scfx_rep &, int);
friend scfx_rep *rsh_scfx_rep(const scfx_rep &, int);
void lshift(int);
void rshift(int);
friend int cmp_scfx_rep(const scfx_rep &, const scfx_rep &);
void cast(const scfx_params &, bool &, bool &);
bool is_neg() const;
bool is_zero() const;
bool is_nan() const;
bool is_inf() const;
bool is_normal() const;
void set_zero(int=1);
void set_nan();
void set_inf(int);
bool get_bit(int) const;
bool set(int, const scfx_params &);
bool clear(int, const scfx_params &);
bool get_slice(int, int, const scfx_params &, sc_bv_base &) const;
bool set_slice(int, int, const scfx_params &, const sc_bv_base &);
void print(::std::ostream &) const;
void dump(::std::ostream &) const;
void get_type(int &, int &, sc_enc &) const;
friend scfx_rep *quantization_scfx_rep(
const scfx_rep &, const scfx_params &, bool &);
friend scfx_rep *overflow_scfx_rep(
const scfx_rep &, const scfx_params &, bool &);
bool rounding_flag() const;
private:
friend void align(const scfx_rep &, const scfx_rep &, int &, int &,
scfx_mant_ref &, scfx_mant_ref &);
friend int compare_msw(const scfx_rep &, const scfx_rep &);
friend int compare_msw_ff(const scfx_rep &lhs, const scfx_rep &rhs);
unsigned int divide_by_ten();
int find_lsw() const;
int find_msw() const;
void find_sw();
void multiply_by_ten();
void normalize(int);
scfx_mant *resize(int, int) const;
void set_bin(int);
void set_oct(int, int);
void set_hex(int, int);
void shift_left(int);
void shift_right(int);
const scfx_index calc_indices(int) const;
void o_extend(const scfx_index &, sc_enc);
bool o_bit_at(const scfx_index &) const;
bool o_zero_left(const scfx_index &) const;
bool o_zero_right(const scfx_index &) const;
void o_set_low(const scfx_index &, sc_enc);
void o_set_high(const scfx_index &, const scfx_index &, sc_enc, int=1);
void o_set(const scfx_index &, const scfx_index &, sc_enc, bool);
void o_invert(const scfx_index &);
bool q_bit(const scfx_index &) const;
void q_clear(const scfx_index &);
void q_incr(const scfx_index &);
bool q_odd(const scfx_index &) const;
bool q_zero(const scfx_index &) const;
void resize_to(int, int=0);
int size() const;
void toggle_tc();
friend void print_dec(scfx_string &, const scfx_rep &, int, sc_fmt);
friend void print_other(scfx_string &, const scfx_rep &, sc_numrep, int,
sc_fmt, const scfx_params *);
void quantization(const scfx_params &, bool &);
void overflow(const scfx_params &, bool &);
friend int compare_abs(const scfx_rep &, const scfx_rep &);
void round(int);
private:
scfx_mant m_mant; // mantissa (bits of the value).
int m_wp; // index of highest order word in value.
int m_sign; // sign of value.
state m_state; // value state, e.g., normal, inf, etc.
int m_msw; // index of most significant non-zero word.
int m_lsw; // index of least significant non-zero word.
bool m_r_flag; // true if rounding occurred.
};
// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
inline void
scfx_rep::set_zero(int sign)
{
m_mant.clear();
m_wp = m_msw = m_lsw = 0;
m_sign = sign;
m_state = normal;
}
inline void
scfx_rep::set_nan()
{
m_mant.resize_to(min_mant);
m_state = not_a_number;
}
inline void
scfx_rep::set_inf(int sign)
{
m_mant.resize_to(min_mant);
m_state = infinity;
m_sign = sign;
}
// constructors
inline scfx_rep::scfx_rep(const char *s) :
m_mant(min_mant), m_wp(2), m_sign(1), m_state(normal),
m_msw(0), m_lsw(0), m_r_flag(false)
{
from_string(s, SC_DEFAULT_CTE_WL_);
}
// destructor
inline scfx_rep::~scfx_rep() {}
// assignment operator
inline void
scfx_rep::operator = (const scfx_rep &f)
{
if (&f != this) {
m_mant = f.m_mant;
m_wp = f.m_wp;
m_sign = f.m_sign;
m_state = f.m_state;
m_msw = f.m_msw;
m_lsw = f.m_lsw;
round(SC_DEFAULT_MAX_WL_);
}
}
inline scfx_rep *
neg_scfx_rep(const scfx_rep &a)
{
scfx_rep &c = *new scfx_rep(a);
c.m_sign = - c.m_sign;
return &c;
}
inline scfx_rep *
mult_scfx_rep(const scfx_rep &a, const scfx_rep &b, int max_wl)
{
scfx_rep &c = *new scfx_rep;
sc_dt::multiply(c, a, b, max_wl);
return &c;
}
inline scfx_rep *
lsh_scfx_rep(const scfx_rep &a, int b)
{
scfx_rep &c = *new scfx_rep(a);
c.lshift(b);
return &c;
}
inline scfx_rep *
rsh_scfx_rep(const scfx_rep &a, int b)
{
scfx_rep &c = *new scfx_rep(a);
c.rshift(b);
return &c;
}
inline int scfx_rep::size() const { return m_mant.size(); }
inline bool scfx_rep::is_neg() const { return (m_sign == -1); }
inline bool
scfx_rep::is_zero() const
{
if (m_state != normal)
return false;
for (int i = 0; i < size(); i++) {
if (m_mant[i])
return false;
}
return true;
}
inline bool scfx_rep::is_nan() const { return (m_state == not_a_number); }
inline bool scfx_rep::is_inf() const { return (m_state == infinity); }
inline bool scfx_rep::is_normal() const { return (m_state == normal); }
inline scfx_rep *
quantization_scfx_rep(const scfx_rep &a, const scfx_params &params,
bool &q_flag)
{
scfx_rep &c = *new scfx_rep(a);
c.quantization(params, q_flag);
return &c;
}
inline scfx_rep *
overflow_scfx_rep(const scfx_rep &a, const scfx_params &params, bool &o_flag)
{
scfx_rep& c = *new scfx_rep(a);
c.overflow(params, o_flag);
return &c;
}
inline bool scfx_rep::rounding_flag() const { return m_r_flag; }
inline void
scfx_rep::resize_to(int new_size, int restore)
{
if (restore == -1) {
int size_incr = new_size - size();
m_wp += size_incr;
m_msw += size_incr;
m_lsw += size_incr;
}
m_mant.resize_to(new_size, restore);
}
inline const scfx_index
scfx_rep::calc_indices(int n) const
{
int wi = n / bits_in_word + m_wp;
int bi = n % bits_in_word;
if (bi < 0) {
bi += bits_in_word;
-- wi;
}
return scfx_index(wi, bi);
}
inline void
scfx_rep::o_extend(const scfx_index &x, sc_enc enc)
{
int wi = x.wi();
int bi = x.bi();
SC_ASSERT_(wi >= 0 && wi < size(), "word index out of range");
if (enc == SC_US_ || (m_mant[wi] & (((word)1) << bi)) == 0) {
if (bi != bits_in_word - 1)
m_mant[wi] &= ~(((word)-1) << (bi + 1));
for (int i = wi + 1; i < size(); ++i)
m_mant[i] = 0;
m_sign = 1;
} else {
if (bi != bits_in_word - 1)
m_mant[wi] |= (((word)-1) << (bi + 1));
for (int i = wi + 1; i < size(); ++i)
m_mant[i] = static_cast<word>(-1);
m_sign = -1;
}
}
inline bool
scfx_rep::o_bit_at(const scfx_index &x) const
{
int wi = x.wi();
int bi = x.bi();
SC_ASSERT_(wi >= 0 && wi < size(), "word index out of range");
return (m_mant[wi] & (((word)1) << bi)) != 0;
}
inline bool
scfx_rep::o_zero_left(const scfx_index &x) const
{
int wi = x.wi();
int bi = x.bi();
SC_ASSERT_(wi >= 0 && wi < size(), "word index out of range");
bool zero = true;
if (bi != bits_in_word - 1)
zero = (m_mant[wi] & (((word)-1) << (bi + 1))) == 0;
for (int i = wi + 1; i < size(); ++i)
zero = zero && m_mant[i] == 0;
return zero;
}
inline bool
scfx_rep::o_zero_right(const scfx_index &x) const
{
int wi = x.wi();
int bi = x.bi();
SC_ASSERT_(wi >= 0 && wi < size(), "word index out of range");
bool zero = (m_mant[wi] & ~(((word)-1) << bi)) == 0;
for (int i = wi - 1; i >= 0; --i)
zero = zero && m_mant[i] == 0;
return zero;
}
inline void
scfx_rep::o_set_low(const scfx_index &x, sc_enc enc)
{
int wi = x.wi();
int bi = x.bi();
SC_ASSERT_(wi >= 0 && wi < size(), "word index out of range");
m_mant.clear();
if (enc == SC_TC_) {
m_mant[wi] |= (((word)1) << bi);
m_sign = -1;
} else {
m_sign = 1;
}
}
inline void
scfx_rep::o_set_high(const scfx_index &x, const scfx_index &x2,
sc_enc enc, int sign)
{
int wi = x.wi();
int bi = x.bi();
int wi2 = x2.wi();
int bi2 = x2.bi();
SC_ASSERT_(wi >= 0 && wi < size(), "word index out of range");
SC_ASSERT_(wi2 >= 0 && wi2 < size(), "word index out of range");
int i;
for (i = 0; i < size(); ++i)
m_mant[i] = static_cast<word>(-1);
m_mant[wi] &= ~(((word)-1) << bi);
for (i = wi + 1; i < size(); ++i)
m_mant[i] = 0;
m_mant[wi2] &= (((word)-1) << bi2);
for (i = wi2 - 1; i >= 0; --i)
m_mant[i] = 0;
if (enc == SC_TC_) {
m_sign = sign;
} else {
m_mant[wi] |= (((word)1) << bi);
m_sign = 1;
}
}
inline void
scfx_rep::o_set(const scfx_index &x, const scfx_index &x3, sc_enc enc,
bool under)
{
int wi = x.wi();
int bi = x.bi();
int wi3 = x3.wi();
int bi3 = x3.bi();
SC_ASSERT_(wi >= 0 && wi < size(), "word index out of range");
SC_ASSERT_(wi3 >= 0 && wi3 < size(), "word index out of range");
if (bi3 != bits_in_word - 1) {
if (under)
m_mant[wi3] &= ~(((word)-1) << (bi3 + 1));
else
m_mant[wi3] |= (((word)-1) << (bi3 + 1));
}
for (int i = wi3 + 1; i < size(); ++i) {
if (under)
m_mant[i] = 0;
else
m_mant[i] = static_cast<word>(-1);
}
if (enc == SC_TC_) {
if (under)
m_mant[wi] |= (((word)1) << bi);
else
m_mant[wi] &= ~(((word)1) << bi);
}
}
inline void
scfx_rep::o_invert(const scfx_index &x2)
{
int wi2 = x2.wi();
int bi2 = x2.bi();
m_mant[wi2] ^= (((word)-1) << bi2);
for (int i = wi2 + 1; i < size(); ++i)
m_mant[i] = ~ m_mant[i];
}
inline bool
scfx_rep::q_bit(const scfx_index &x) const
{
int wi = x.wi();
int bi = x.bi();
SC_ASSERT_(wi >= 0 && wi < size(), "word index out of range");
if (bi != 0)
return (m_mant[wi] & (((word)1) << (bi - 1))) != 0;
else if (wi != 0)
return (m_mant[wi - 1] & (((word)1) << (bits_in_word - 1))) != 0;
else
return false;
}
inline void
scfx_rep::q_clear(const scfx_index &x)
{
int wi = x.wi();
int bi = x.bi();
SC_ASSERT_(wi >= 0 && wi < size(), "word index out of range");
m_mant[wi] &= (((word)-1) << bi);
for (int i = wi - 1; i >= 0; --i)
m_mant[i] = 0;
}
inline void
scfx_rep::q_incr(const scfx_index &x)
{
int wi = x.wi();
int bi = x.bi();
SC_ASSERT_(wi >= 0 && wi < size(), "word index out of range");
word old_val = m_mant[wi];
m_mant[wi] += (((word)1) << bi);
if (m_mant[wi] <= old_val) {
if (wi + 1 == size())
resize_to(size() + 1, 1);
for (int i = wi + 1; i < size(); ++i) {
if (++m_mant[i] != 0)
break;
}
}
}
inline bool
scfx_rep::q_odd(const scfx_index &x) const
{
int wi = x.wi();
int bi = x.bi();
SC_ASSERT_(wi >= 0 && wi < size(), "word index out of range");
return (m_mant[wi] & (((word)1) << bi)) != 0;
}
inline bool
scfx_rep::q_zero(const scfx_index &x) const
{
int wi = x.wi();
int bi = x.bi();
SC_ASSERT_(wi >= 0 && wi < size(), "word index out of range");
bool zero;
if (bi != 0) {
zero = (m_mant[wi] & ~(((word)-1) << (bi - 1))) == 0;
for (int i = wi - 1; i >= 0; --i)
zero = zero && m_mant[i] == 0;
} else if (wi != 0) {
zero = (m_mant[wi - 1] & ~( ((word)-1) << (bits_in_word - 1))) == 0;
for (int i = wi - 2; i >= 0; --i)
zero = zero && m_mant[i] == 0;
} else {
zero = true;
}
return zero;
}
inline int
scfx_rep::find_lsw() const
{
for (int i = 0; i < size(); i++) {
if (m_mant[i])
return i;
}
return 0;
}
inline int
scfx_rep::find_msw() const
{
for (int i = size() - 1; i >= 0; i--) {
if (m_mant[i])
return i;
}
return 0;
}
inline void
scfx_rep::find_sw()
{
m_lsw = find_lsw();
m_msw = find_msw();
}
inline void
scfx_rep::toggle_tc()
{
if (is_neg()) {
complement(m_mant, m_mant, m_mant.size());
inc(m_mant);
}
}
} // namespace sc_dt
#endif // __SYSTEMC_EXT_DT_FX_SCFX_REP_HH__

View File

@@ -0,0 +1,199 @@
/*****************************************************************************
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.
*****************************************************************************/
/*****************************************************************************
scfx_string.h -
Original Author: Robert Graulich, Synopsys, Inc.
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: scfx_string.h,v $
// Revision 1.1.1.1 2006/12/15 20:20:04 acg
// SystemC 2.3
//
// Revision 1.2 2006/01/03 23:18:34 acg
// Changed copyright to include 2006.
//
// Revision 1.1.1.1 2005/12/19 23:16:43 acg
// First check in of SystemC 2.1 into its own archive.
//
// Revision 1.9 2005/09/15 23:02:03 acg
// Added std:: prefix to appropriate methods and types to get around
// issues with the Edison Front End.
//
// Revision 1.8 2005/06/07 17:27:02 acg
// Fixed bug in scfx_string::operator += where an array reference was used
// rather than the [] operator. This meant that the buffer may have been
// accessed beyond its allocated storage.
//
#ifndef __SYSTEMC_EXT_DT_FX_SCFX_STRING_HH__
#define __SYSTEMC_EXT_DT_FX_SCFX_STRING_HH__
#include <cstdio>
namespace sc_dt
{
// classes defined in this module
class scfx_string;
// ----------------------------------------------------------------------------
// CLASS : scfx_string
//
// Simple string class for internal use.
// ----------------------------------------------------------------------------
class scfx_string
{
void resize(std::size_t);
public:
scfx_string();
~scfx_string();
int length() const;
void clear();
char & operator [] (int);
void append(int);
void discard(int);
void remove(int);
void operator += (char);
void operator += (const char *);
operator const char * ();
private:
std::size_t m_len;
std::size_t m_alloc;
char *m_buffer;
};
// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
inline void
scfx_string::resize(std::size_t i)
{
do {
m_alloc *= 2;
} while (i >= m_alloc);
char *temp = new char[m_alloc];
for (int j = 0; j < (int) m_len; ++j) {
temp[j] = m_buffer[j];
}
temp[m_len] = 0;
delete [] m_buffer;
m_buffer = temp;
}
inline scfx_string::scfx_string() :
m_len(0), m_alloc(BUFSIZ), m_buffer(new char[m_alloc])
{
m_buffer[m_len] = 0;
}
inline scfx_string::~scfx_string() { delete [] m_buffer; }
inline int scfx_string::length() const { return m_len; }
inline void
scfx_string::clear()
{
m_len = 0;
m_buffer[m_len] = 0;
}
inline char &
scfx_string::operator [] (int i)
{
if (i >= (int)m_alloc) {
resize(i);
}
return m_buffer[i];
}
inline void
scfx_string::append(int n)
{
m_len += n;
m_buffer[m_len] = 0;
}
inline void
scfx_string::discard(int n)
{
m_len -= n;
m_buffer[m_len] = 0;
}
inline void
scfx_string::remove(int i)
{
for (int j = i + 1; j < (int)m_len; ++j)
m_buffer[j - 1] = m_buffer[j];
--m_len;
m_buffer[m_len] = 0;
}
inline void
scfx_string::operator += (char c)
{
this->operator [] (m_len) = c;
m_len++;
this->operator [] (m_len) = 0;
}
inline void
scfx_string::operator += (const char *s)
{
while (*s)
(*this) += *s++;
}
inline scfx_string::operator const char * ()
{
m_buffer[m_len] = 0;
return m_buffer;
}
} // namespace sc_dt
#endif // __SYSTEMC_EXT_DT_FX_SCFX_STRING_HH__

View File

@@ -0,0 +1,493 @@
/*****************************************************************************
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.
*****************************************************************************/
/*****************************************************************************
scfx_utils.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: scfx_utils.h,v $
// Revision 1.2 2009/02/28 00:26:20 acg
// Andy Goodrich: bug fixes.
//
// Revision 1.1.1.1 2006/12/15 20:31:36 acg
// SystemC 2.2
//
// Revision 1.3 2006/01/13 18:53:58 acg
// Andy Goodrich: added $Log command so that CVS comments are reproduced in
// the source.
//
#ifndef __SYSTEMC_EXT_DT_FX_SCFX_UTILS_HH__
#define __SYSTEMC_EXT_DT_FX_SCFX_UTILS_HH__
#include "sc_fxdefs.hh"
#include "scfx_params.hh"
#include "scfx_string.hh"
namespace sc_dt
{
// ----------------------------------------------------------------------------
// Find the most and least significant non-zero bits in a unsigned long
// ----------------------------------------------------------------------------
#define MSB_STATEMENT(n) if (x >> n) { x >>= n; i += n; }
inline int
scfx_find_msb(unsigned long x)
{
int i = 0;
# if defined(SC_LONG_64)
MSB_STATEMENT(32);
# endif // defined(SC_LONG_64)
MSB_STATEMENT(16);
MSB_STATEMENT(8);
MSB_STATEMENT(4);
MSB_STATEMENT(2);
MSB_STATEMENT(1);
return i;
}
#undef MSB_STATEMENT
#define LSB_STATEMENT(n) if (x << n) { x <<= n; i -= n; }
inline int
scfx_find_lsb(unsigned long x)
{
int i;
# if defined(SC_LONG_64)
i = 63;
LSB_STATEMENT(32);
# else
i = 31;
# endif // defined(SC_LONG_64)
LSB_STATEMENT(16);
LSB_STATEMENT(8);
LSB_STATEMENT(4);
LSB_STATEMENT(2);
LSB_STATEMENT(1);
return i;
}
#undef LSB_STATEMENT
// ----------------------------------------------------------------------------
// Utilities for parsing a character string number
// ----------------------------------------------------------------------------
inline int
scfx_parse_sign(const char *&s, bool &sign_char)
{
int sign = 1;
if (*s == '+') {
++s;
sign_char = true;
} else if (*s == '-' ) {
sign = -1;
++s;
sign_char = true;
} else {
sign_char = false;
}
return sign;
}
inline sc_numrep
scfx_parse_prefix(const char *&s)
{
if (s[0] == '0') {
switch (s[1]) {
case 'b':
case 'B':
{
if ((s[2] == 'u' || s[2] == 'U') &&
(s[3] == 's' || s[3] == 'S')) {
s += 4;
return SC_BIN_US;
}
if ((s[2] == 's' || s[2] == 'S') &&
(s[3] == 'm' || s[3] == 'M')) {
s += 4;
return SC_BIN_SM;
}
s += 2;
return SC_BIN;
}
case 'o':
case 'O':
{
if ((s[2] == 'u' || s[2] == 'U') &&
(s[3] == 's' || s[3] == 'S')) {
s += 4;
return SC_OCT_US;
}
if ((s[2] == 's' || s[2] == 'S') &&
(s[3] == 'm' || s[3] == 'M')) {
s += 4;
return SC_OCT_SM;
}
s += 2;
return SC_OCT;
}
case 'x':
case 'X':
{
if ((s[2] == 'u' || s[2] == 'U') &&
(s[3] == 's' || s[3] == 'S')) {
s += 4;
return SC_HEX_US;
}
if ((s[2] == 's' || s[2] == 'S') &&
(s[3] == 'm' || s[3] == 'M')) {
s += 4;
return SC_HEX_SM;
}
s += 2;
return SC_HEX;
}
case 'd':
case 'D':
{
s += 2;
return SC_DEC;
}
case 'c':
case 'C':
{
if ((s[2] == 's' || s[2] == 'S') &&
(s[3] == 'd' || s[3] == 'D')) {
s += 4;
return SC_CSD;
}
break;
}
default:
break;
}
}
return SC_DEC;
}
inline int
scfx_parse_base(const char *&s)
{
const char *s1 = s + 1;
int base = 10;
if (*s == '0') {
switch (*s1) {
case 'b':
case 'B': base = 2; s += 2; break;
case 'o':
case 'O': base = 8; s += 2; break;
case 'd':
case 'D': base = 10; s += 2; break;
case 'x':
case 'X': base = 16; s += 2; break;
}
}
return base;
}
inline bool
scfx_is_equal(const char *a, const char *b)
{
while (*a != 0 && *b != 0 && *a == *b) {
++ a;
++ b;
}
return (*a == 0 && *b == 0);
}
inline bool
scfx_is_nan(const char *s)
{
return scfx_is_equal(s, "NaN");
}
inline bool
scfx_is_inf(const char *s)
{
return (scfx_is_equal(s, "Inf") || scfx_is_equal(s, "Infinity"));
}
inline bool
scfx_exp_start(const char *s)
{
if (*s == 'e' || *s == 'E') {
++s;
if (*s == '+' || *s == '-')
return true;
}
return false;
}
inline bool
scfx_is_digit(char c, sc_numrep numrep)
{
bool is_digit;
switch(numrep) {
case SC_DEC:
{
switch(c) {
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
{
is_digit = true;
break;
}
default:
is_digit = false;
}
break;
}
case SC_BIN:
case SC_BIN_US:
case SC_BIN_SM:
{
switch(c) {
case '0': case '1':
{
is_digit = true;
break;
}
default:
is_digit = false;
}
break;
}
case SC_OCT:
case SC_OCT_US:
case SC_OCT_SM:
{
switch(c) {
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
{
is_digit = true;
break;
}
default:
is_digit = false;
}
break;
}
case SC_HEX:
case SC_HEX_US:
case SC_HEX_SM:
{
switch (c) {
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
{
is_digit = true;
break;
}
default:
is_digit = false;
}
break;
}
case SC_CSD:
{
switch (c) {
case '0': case '1': case '-':
{
is_digit = true;
break;
}
default:
is_digit = false;
}
break;
}
default:
is_digit = false;
}
return is_digit;
}
inline int
scfx_to_digit(char c, sc_numrep numrep)
{
int to_digit;
switch (numrep) {
case SC_DEC:
case SC_BIN:
case SC_BIN_US:
case SC_BIN_SM:
case SC_OCT:
case SC_OCT_US:
case SC_OCT_SM:
{
to_digit = c - '0';
break;
}
case SC_HEX:
case SC_HEX_US:
case SC_HEX_SM:
{
switch (c) {
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
to_digit = c - '0';
break;
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
to_digit = c - 'a' + 10;
break;
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
to_digit = c - 'A' + 10;
break;
default:
to_digit = -2;
}
break;
}
case SC_CSD:
{
if (c == '-')
to_digit = -1;
else
to_digit = c - '0';
break;
}
default:
to_digit = -2;
}
return to_digit;
}
// ----------------------------------------------------------------------------
// Utilities for printing a character string number
// ----------------------------------------------------------------------------
inline void scfx_print_nan(scfx_string &s) { s += "NaN"; }
inline void
scfx_print_inf(scfx_string &s, bool negative)
{
if (negative)
s += "-Inf";
else
s += "Inf";
}
inline void
scfx_print_prefix(scfx_string &s, sc_numrep numrep)
{
switch (numrep) {
case SC_DEC:
s += "0d";
break;
case SC_BIN:
s += "0b";
break;
case SC_BIN_US:
s += "0bus";
break;
case SC_BIN_SM:
s += "0bsm";
break;
case SC_OCT:
s += "0o";
break;
case SC_OCT_US:
s += "0ous";
break;
case SC_OCT_SM:
s += "0osm";
break;
case SC_HEX:
s += "0x";
break;
case SC_HEX_US:
s += "0xus";
break;
case SC_HEX_SM:
s += "0xsm";
break;
case SC_CSD:
s += "0csd";
break;
default:
s += "unknown";
}
}
inline void
scfx_print_exp(scfx_string &s, int exp)
{
if (exp != 0) {
s += 'e';
if (exp < 0) {
exp = - exp;
s += '-';
} else {
s += '+';
}
bool first = true;
int scale = 1000000000;
do {
int digit = exp / scale;
exp = exp % scale;
if (digit != 0 || !first) {
s += static_cast<char>(digit + '0');
first = false;
}
scale /= 10;
}
while (scale > 0);
}
}
void scfx_tc2csd(scfx_string &, int);
void scfx_csd2tc(scfx_string &);
} // namespace sc_dt
#endif // __SYSTEMC_EXT_DT_FX_SCFX_UTILS_HH__

View File

@@ -27,9 +27,20 @@
* Authors: Gabe Black
*/
#ifndef __SYSTEMC_EXT_CORE_DT__INT_HH__
#define __SYSTEMC_EXT_CORE_DT__INT_HH__
#ifndef __SYSTEMC_EXT_CORE_DT_INT__INT_HH__
#define __SYSTEMC_EXT_CORE_DT_INT__INT_HH__
#include "sc_bigint.hh"
#include "sc_biguint.hh"
#include "sc_int.hh"
#include "sc_int_base.hh"
#include "sc_length_param.hh"
#include "sc_nbdefs.hh"
#include "sc_nbexterns.hh"
#include "sc_nbutils.hh"
#include "sc_signed.hh"
#include "sc_uint.hh"
#include "sc_uint_base.hh"
#include "sc_unsigned.hh"
#endif //__SYSTEMC_EXT_CORE_DT__INT_HH__
#endif //__SYSTEMC_EXT_CORE_DT_INT__INT_HH__

View File

@@ -27,27 +27,38 @@
* Authors: Gabe Black
*/
#ifndef __SYSTEMC_EXT_CORE_INT__USING_HH__
#define __SYSTEMC_EXT_CORE_INT__USING_HH__
#ifndef __SYSTEMC_EXT_DT_INT__USING_HH__
#define __SYSTEMC_EXT_DT_INT__USING_HH__
#include "int.hh"
#include "_int.hh"
using sc_dt::SC_NOBASE;
using sc_dt::SC_BIN;
using sc_dt::SC_OCT;
using sc_dt::SC_BIN_SM;
using sc_dt::SC_BIN_US;
using sc_dt::SC_CSD;
using sc_dt::SC_DEC;
using sc_dt::SC_HEX;
using sc_dt::SC_BIN_US;
using sc_dt::SC_BIN_SM;
using sc_dt::SC_OCT_US;
using sc_dt::SC_OCT_SM;
using sc_dt::SC_HEX_US;
using sc_dt::SC_HEX_SM;
using sc_dt::SC_CSD;
using sc_dt::small_type
using sc_dt::SC_HEX_US;
using sc_dt::SC_NOBASE;
using sc_dt::SC_OCT;
using sc_dt::SC_OCT_SM;
using sc_dt::SC_OCT_US;
using sc_dt::int64;
using sc_dt::sc_bigint;
using sc_dt::sc_biguint;
using sc_dt::sc_digit;
using sc_dt::sc_int;
using sc_dt::sc_int_base;
using sc_dt::sc_io_show_base;
using sc_dt::sc_length_context;
using sc_dt::sc_length_param;
using sc_dt::sc_logic;
using sc_dt::sc_numrep;
using sc_dt::sc_signed;
using sc_dt::sc_uint;
using sc_dt::sc_uint_base;
using sc_dt::sc_unsigned;
using sc_dt::uint64;
using sc_dt::int_type;
using sc_dt::uint_type;
#endif //__SYSTEMC_EXT_CORE_INT__USING_HH__
#endif //__SYSTEMC_EXT_DT_INT__USING_HH__

View File

@@ -0,0 +1,284 @@
/*****************************************************************************
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_bigint.h -- Template version of sc_signed. This class enables
compile-time bit widths for sc_signed numbers.
Original Author: Ali Dasdan, Synopsys, Inc.
*****************************************************************************/
/*****************************************************************************
MODIFICATION LOG - modifiers, enter your name, affiliation, date and
changes you are making here.
Name, Affiliation, Date: Gene Bushayev, Synopsys, Inc.
Description of Modification: - Interface between sc_bigint and sc_bv/sc_lv.
Name, Affiliation, Date:
Description of Modification:
*****************************************************************************/
// $Log: sc_bigint.h,v $
// Revision 1.2 2011/02/18 20:19:14 acg
// Andy Goodrich: updating Copyright notice.
//
// Revision 1.1.1.1 2006/12/15 20:20:05 acg
// SystemC 2.3
//
// Revision 1.3 2006/01/13 18:49:31 acg
// Added $Log command so that CVS check in comments are reproduced in the
// source.
//
#ifndef __SYSTEMC_EXT_DT_INT_SC_BIGINT_HH__
#define __SYSTEMC_EXT_DT_INT_SC_BIGINT_HH__
#include "sc_signed.hh"
#include "sc_unsigned.hh"
namespace sc_dt
{
// classes defined in this module
template <int W>
class sc_bigint;
// forward class declarations
class sc_bv_base;
class sc_lv_base;
class sc_fxval;
class sc_fxval_fast;
class sc_fxnum;
class sc_fxnum_fast;
// ----------------------------------------------------------------------------
// CLASS TEMPLATE : sc_bigint<W>
//
// Arbitrary size signed integer type.
// ----------------------------------------------------------------------------
#ifdef SC_MAX_NBITS
template<int W=SC_MAX_NBITS>
#else
template<int W>
#endif
class sc_bigint : public sc_signed
{
public:
// constructors
sc_bigint() : sc_signed(W) {}
sc_bigint(const sc_bigint<W> &v) : sc_signed(W) { *this = v; }
sc_bigint(const sc_signed &v) : sc_signed(W) { *this = v; }
sc_bigint(const sc_signed_subref &v) : sc_signed(W) { *this = v; }
template< class T >
sc_bigint(const sc_generic_base<T> &a) : sc_signed(W)
{
a->to_sc_signed(*this);
}
sc_bigint(const sc_unsigned &v) : sc_signed(W) { *this = v; }
sc_bigint(const sc_unsigned_subref &v) : sc_signed(W) { *this = v; }
sc_bigint(const char *v) : sc_signed(W) { *this = v; }
sc_bigint(int64 v) : sc_signed(W) { *this = v; }
sc_bigint(uint64 v) : sc_signed(W) { *this = v; }
sc_bigint(long v) : sc_signed(W) { *this = v; }
sc_bigint(unsigned long v) : sc_signed(W) { *this = v; }
sc_bigint(int v) : sc_signed(W) { *this = v; }
sc_bigint(unsigned int v) : sc_signed(W) { *this = v; }
sc_bigint(double v) : sc_signed(W) { *this = v; }
sc_bigint(const sc_bv_base &v) : sc_signed(W) { *this = v; }
sc_bigint(const sc_lv_base &v) : sc_signed(W) { *this = v; }
explicit sc_bigint(const sc_fxval &v) : sc_signed(W) { *this = v; }
explicit sc_bigint(const sc_fxval_fast &v) : sc_signed(W) { *this = v; }
explicit sc_bigint(const sc_fxnum &v) : sc_signed(W) { *this = v; }
explicit sc_bigint(const sc_fxnum_fast &v) : sc_signed(W) { *this = v; }
#ifndef SC_MAX_NBITS
// destructor
~sc_bigint() {}
#endif
// assignment operators
sc_bigint<W> &
operator = (const sc_bigint<W> &v)
{
sc_signed::operator = (v);
return *this;
}
sc_bigint<W> &
operator = (const sc_signed &v)
{
sc_signed::operator = (v);
return *this;
}
sc_bigint<W> &
operator = (const sc_signed_subref &v)
{
sc_signed::operator = (v);
return *this;
}
template< class T >
sc_bigint<W> &
operator = (const sc_generic_base<T> &a)
{
a->to_sc_signed(*this);
return *this;
}
sc_bigint<W> &
operator = (const sc_unsigned &v)
{
sc_signed::operator = (v);
return *this;
}
sc_bigint<W> &
operator = (const sc_unsigned_subref &v)
{
sc_signed::operator = (v);
return *this;
}
sc_bigint<W> &
operator = (const char *v)
{
sc_signed::operator = (v);
return *this;
}
sc_bigint<W> &
operator = (int64 v)
{
sc_signed::operator = (v);
return *this;
}
sc_bigint<W> &
operator = (uint64 v)
{
sc_signed::operator = (v);
return *this;
}
sc_bigint<W> &
operator = (long v)
{
sc_signed::operator = (v);
return *this;
}
sc_bigint<W> &
operator = (unsigned long v)
{
sc_signed::operator = (v);
return *this;
}
sc_bigint<W> &
operator = (int v)
{
sc_signed::operator = (v);
return *this;
}
sc_bigint<W> &
operator = (unsigned int v)
{
sc_signed::operator = (v);
return *this;
}
sc_bigint<W> &operator = (double v)
{
sc_signed::operator = (v);
return *this;
}
sc_bigint<W> &
operator = (const sc_bv_base &v)
{
sc_signed::operator = (v);
return *this;
}
sc_bigint<W> &
operator = (const sc_lv_base &v)
{
sc_signed::operator = (v);
return *this;
}
sc_bigint<W> &
operator = (const sc_int_base &v)
{
sc_signed::operator = (v);
return *this;
}
sc_bigint<W> &
operator = (const sc_uint_base &v)
{
sc_signed::operator = (v);
return *this;
}
sc_bigint<W> &
operator = (const sc_fxval &v)
{
sc_signed::operator = (v);
return *this;
}
sc_bigint<W> &
operator = (const sc_fxval_fast& v)
{
sc_signed::operator = (v);
return *this;
}
sc_bigint<W> &
operator = (const sc_fxnum &v)
{
sc_signed::operator = (v);
return *this;
}
sc_bigint<W> &
operator = (const sc_fxnum_fast &v)
{
sc_signed::operator = (v);
return *this;
}
};
} // namespace sc_dt
#endif // __SYSTEMC_EXT_DT_INT_SC_BIGINT_HH__

View File

@@ -0,0 +1,284 @@
/*****************************************************************************
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_biguint.h -- Template version of sc_unsigned. This class
enables compile-time bit widths for sc_unsigned numbers.
Original Author: Ali Dasdan, Synopsys, Inc.
*****************************************************************************/
/*****************************************************************************
MODIFICATION LOG - modifiers, enter your name, affiliation, date and
changes you are making here.
Name, Affiliation, Date: Gene Bushayev, Synopsys, Inc.
Description of Modification: - Interface between sc_bigint and sc_bv/sc_lv.
Name, Affiliation, Date:
Description of Modification:
*****************************************************************************/
// $Log: sc_biguint.h,v $
// Revision 1.2 2011/02/18 20:19:14 acg
// Andy Goodrich: updating Copyright notice.
//
// Revision 1.1.1.1 2006/12/15 20:20:05 acg
// SystemC 2.3
//
// Revision 1.3 2006/01/13 18:49:31 acg
// Added $Log command so that CVS check in comments are reproduced in the
// source.
//
#ifndef __SYSTEMC_EXT_DT_INT_SC_BIGUINT_HH__
#define __SYSTEMC_EXT_DT_INT_SC_BIGUINT_HH__
#include "sc_signed.hh"
#include "sc_unsigned.hh"
namespace sc_dt
{
// classes defined in this module
template <int W>
class sc_biguint;
// forward class declarations
class sc_bv_base;
class sc_lv_base;
class sc_fxval;
class sc_fxval_fast;
class sc_fxnum;
class sc_fxnum_fast;
// ----------------------------------------------------------------------------
// CLASS TEMPLATE : sc_biguint<W>
//
// Arbitrary size unsigned integer type.
// ----------------------------------------------------------------------------
#ifdef SC_MAX_NBITS
template<int W=SC_MAX_NBITS>
#else
template<int W>
#endif
class sc_biguint : public sc_unsigned
{
public:
// constructors
sc_biguint() : sc_unsigned(W) {}
sc_biguint(const sc_biguint<W> &v) : sc_unsigned(W) { *this = v; }
sc_biguint(const sc_unsigned &v) : sc_unsigned(W) { *this = v; }
sc_biguint(const sc_unsigned_subref &v) : sc_unsigned(W) { *this = v; }
template<class T>
sc_biguint(const sc_generic_base<T> &a) : sc_unsigned(W)
{
a->to_sc_unsigned(*this);
}
sc_biguint(const sc_signed &v) : sc_unsigned(W) { *this = v; }
sc_biguint(const sc_signed_subref &v) : sc_unsigned(W) { *this = v; }
sc_biguint(const char* v) : sc_unsigned(W) { *this = v; }
sc_biguint(int64 v) : sc_unsigned(W) { *this = v; }
sc_biguint(uint64 v) : sc_unsigned(W) { *this = v; }
sc_biguint(long v) : sc_unsigned(W) { *this = v; }
sc_biguint(unsigned long v) : sc_unsigned(W) { *this = v; }
sc_biguint(int v) : sc_unsigned(W) { *this = v; }
sc_biguint(unsigned int v) : sc_unsigned(W) { *this = v; }
sc_biguint(double v) : sc_unsigned(W) { *this = v; }
sc_biguint(const sc_bv_base &v) : sc_unsigned(W) { *this = v; }
sc_biguint(const sc_lv_base &v) : sc_unsigned(W) { *this = v; }
explicit sc_biguint(const sc_fxval &v) : sc_unsigned(W) { *this = v; }
explicit sc_biguint(const sc_fxval_fast &v) : sc_unsigned(W) { *this = v; }
explicit sc_biguint(const sc_fxnum &v) : sc_unsigned(W) { *this = v; }
explicit sc_biguint(const sc_fxnum_fast &v) : sc_unsigned(W) { *this = v; }
#ifndef SC_MAX_NBITS
// destructor
~sc_biguint() {}
#endif
// assignment operators
sc_biguint<W> &
operator = (const sc_biguint<W> &v)
{
sc_unsigned::operator = (v);
return *this;
}
sc_biguint<W> &
operator = (const sc_unsigned &v)
{
sc_unsigned::operator = (v);
return *this;
}
sc_biguint<W> &
operator = (const sc_unsigned_subref &v)
{
sc_unsigned::operator = (v);
return *this;
}
template< class T >
sc_biguint<W> &
operator = (const sc_generic_base<T> &a)
{ a->to_sc_unsigned(*this);
return *this;
}
sc_biguint<W> &
operator = (const sc_signed &v)
{
sc_unsigned::operator = (v);
return *this;
}
sc_biguint<W> &
operator = (const sc_signed_subref &v)
{
sc_unsigned::operator = (v);
return *this;
}
sc_biguint<W> &
operator = (const char* v)
{
sc_unsigned::operator = (v);
return *this;
}
sc_biguint<W> &
operator = (int64 v)
{
sc_unsigned::operator = (v);
return *this;
}
sc_biguint<W> &
operator = (uint64 v)
{
sc_unsigned::operator = (v);
return *this;
}
sc_biguint<W> &
operator = (long v)
{
sc_unsigned::operator = (v);
return *this;
}
sc_biguint<W> &
operator = (unsigned long v)
{
sc_unsigned::operator = (v);
return *this;
}
sc_biguint<W> &
operator = (int v)
{
sc_unsigned::operator = (v);
return *this;
}
sc_biguint<W> &
operator = (unsigned int v)
{
sc_unsigned::operator = (v);
return *this;
}
sc_biguint<W> &
operator = (double v)
{
sc_unsigned::operator = (v);
return *this;
}
sc_biguint<W> &
operator = (const sc_bv_base &v)
{
sc_unsigned::operator = (v);
return *this;
}
sc_biguint<W> &
operator = (const sc_lv_base &v)
{
sc_unsigned::operator = (v);
return *this;
}
sc_biguint<W> &
operator = (const sc_int_base &v)
{
sc_unsigned::operator = (v);
return *this;
}
sc_biguint<W> &
operator = (const sc_uint_base &v)
{
sc_unsigned::operator = (v);
return *this;
}
sc_biguint<W> &
operator = (const sc_fxval &v)
{
sc_unsigned::operator = (v);
return *this;
}
sc_biguint<W> &
operator = (const sc_fxval_fast &v)
{
sc_unsigned::operator = (v);
return *this;
}
sc_biguint<W> &
operator = (const sc_fxnum &v)
{
sc_unsigned::operator = (v);
return *this;
}
sc_biguint<W> &
operator = (const sc_fxnum_fast &v)
{
sc_unsigned::operator = (v);
return *this;
}
};
} // namespace sc_dt
#endif // __SYSTEMC_EXT_DT_INT_SC_BIGUINT_HH__

View File

@@ -0,0 +1,381 @@
/*****************************************************************************
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_int.h -- A signed integer whose length is less than 64 bits.
Unlike arbitrary precision, arithmetic and bitwise operations
are performed using the native types (hence capped at 64 bits).
The sc_int integer is useful when the user does not need
arbitrary precision and the performance is superior to
sc_bigint/sc_biguint.
Original Author: Amit Rao, Synopsys, Inc.
*****************************************************************************/
/*****************************************************************************
MODIFICATION LOG - modifiers, enter your name, affiliation, date and
changes you are making here.
Name, Affiliation, Date: Ali Dasdan, Synopsys, Inc.
Description of Modification: - Resolved ambiguity with sc_(un)signed.
- Merged the code for 64- and 32-bit versions
via the constants in sc_nbdefs.h.
- Eliminated redundant file inclusions.
Name, Affiliation, Date:
Description of Modification:
*****************************************************************************/
// $Log: sc_int.h,v $
// Revision 1.2 2011/02/18 20:19:14 acg
// Andy Goodrich: updating Copyright notice.
//
// Revision 1.1.1.1 2006/12/15 20:20:05 acg
// SystemC 2.3
//
// Revision 1.3 2006/01/13 18:49:31 acg
// Added $Log command so that CVS check in comments are reproduced in the
// source.
//
#ifndef __SYSTEMC_EXT_DT_INT_SC_INT_HH__
#define __SYSTEMC_EXT_DT_INT_SC_INT_HH__
#include "sc_int_base.hh"
namespace sc_dt
{
// classes defined in this module
template <int W>
class sc_int;
// ----------------------------------------------------------------------------
// CLASS TEMPLATE : sc_int<W>
//
// Template class sc_int<W> is the interface that the user sees. It is
// derived from sc_int_base and most of its methods are just wrappers
// that call the corresponding method in the parent class. Note that
// the length of sc_int datatype is specified as a template parameter.
// ----------------------------------------------------------------------------
template <int W>
class sc_int : public sc_int_base
{
public:
// constructors
sc_int() : sc_int_base(W) {}
sc_int(int_type v) : sc_int_base(v, W) {}
sc_int(const sc_int<W> &a) : sc_int_base(a) {}
sc_int(const sc_int_base &a) : sc_int_base(W)
{
sc_int_base::operator = (a);
}
sc_int(const sc_int_subref_r &a) : sc_int_base(W)
{
sc_int_base::operator = (a);
}
template< class T >
sc_int(const sc_generic_base<T> &a) : sc_int_base(W)
{
sc_int_base::operator = (a->to_int64());
}
sc_int(const sc_signed &a) : sc_int_base(W)
{
sc_int_base::operator = (a);
}
sc_int(const sc_unsigned &a) : sc_int_base(W)
{
sc_int_base::operator = (a);
}
explicit sc_int(const sc_fxval &a) : sc_int_base(W)
{
sc_int_base::operator = (a);
}
explicit sc_int(const sc_fxval_fast &a) : sc_int_base(W)
{
sc_int_base::operator = (a);
}
explicit sc_int(const sc_fxnum &a) : sc_int_base(W)
{
sc_int_base::operator = (a);
}
explicit sc_int(const sc_fxnum_fast &a) : sc_int_base(W)
{
sc_int_base::operator = (a);
}
sc_int(const sc_bv_base &a) : sc_int_base(W)
{
sc_int_base::operator = (a);
}
sc_int(const sc_lv_base &a) : sc_int_base(W)
{
sc_int_base::operator = (a);
}
sc_int(const char *a) : sc_int_base(W)
{
sc_int_base::operator = (a);
}
sc_int(unsigned long a) : sc_int_base(W)
{
sc_int_base::operator = (a);
}
sc_int(long a) : sc_int_base(W)
{
sc_int_base::operator = (a);
}
sc_int(unsigned int a) : sc_int_base(W)
{
sc_int_base::operator = (a);
}
sc_int(int a) : sc_int_base(W)
{
sc_int_base::operator = (a);
}
sc_int(uint64 a) : sc_int_base(W)
{
sc_int_base::operator = (a);
}
sc_int(double a) : sc_int_base(W)
{
sc_int_base::operator = (a);
}
// assignment operators
sc_int<W> &
operator = (int_type v)
{
sc_int_base::operator = (v);
return *this;
}
sc_int<W> &
operator = (const sc_int_base &a)
{
sc_int_base::operator = (a);
return *this;
}
sc_int<W> &
operator = (const sc_int_subref_r &a)
{
sc_int_base::operator = (a);
return *this;
}
sc_int<W> &
operator = (const sc_int<W> &a)
{
m_val = a.m_val;
return *this;
}
template< class T >
sc_int<W> &
operator = (const sc_generic_base<T> &a)
{
sc_int_base::operator = (a->to_int64());
return *this;
}
sc_int<W> &
operator = (const sc_signed &a)
{
sc_int_base::operator = (a);
return *this;
}
sc_int<W> &
operator = (const sc_unsigned &a)
{
sc_int_base::operator = (a);
return *this;
}
sc_int<W> &
operator = (const sc_fxval &a)
{
sc_int_base::operator = (a);
return *this;
}
sc_int<W> &
operator = (const sc_fxval_fast &a)
{
sc_int_base::operator = (a);
return *this;
}
sc_int<W> &
operator = (const sc_fxnum &a)
{
sc_int_base::operator = (a);
return *this;
}
sc_int<W> &operator = (const sc_fxnum_fast &a)
{
sc_int_base::operator = (a);
return *this;
}
sc_int<W> &
operator = (const sc_bv_base &a)
{
sc_int_base::operator = (a);
return *this;
}
sc_int<W> &
operator = (const sc_lv_base &a)
{
sc_int_base::operator = (a);
return *this;
}
sc_int<W> &
operator = (const char *a)
{
sc_int_base::operator = (a);
return *this;
}
sc_int<W> &
operator = (unsigned long a)
{
sc_int_base::operator = (a);
return *this;
}
sc_int<W> &
operator = (long a)
{
sc_int_base::operator = (a);
return *this;
}
sc_int<W> &
operator = (unsigned int a)
{
sc_int_base::operator = (a);
return *this;
}
sc_int<W> &
operator = (int a)
{
sc_int_base::operator = (a);
return *this;
}
sc_int<W> &
operator = (uint64 a)
{
sc_int_base::operator = (a);
return *this;
}
sc_int<W> &
operator = (double a)
{
sc_int_base::operator = (a);
return *this;
}
// arithmetic assignment operators
sc_int<W> &
operator += (int_type v)
{
sc_int_base::operator += (v);
return *this;
}
sc_int<W> &
operator -= (int_type v)
{
sc_int_base::operator -= (v);
return *this;
}
sc_int<W> &
operator *= (int_type v)
{
sc_int_base::operator *= (v);
return *this;
}
sc_int<W> &
operator /= (int_type v)
{
sc_int_base::operator /= (v);
return *this;
}
sc_int<W> &
operator %= (int_type v)
{
sc_int_base::operator %= (v);
return *this;
}
// bitwise assignment operators
sc_int<W> &
operator &= (int_type v)
{
sc_int_base::operator &= (v);
return *this;
}
sc_int<W> &
operator |= (int_type v)
{
sc_int_base::operator |= (v);
return *this;
}
sc_int<W> &
operator ^= (int_type v)
{
sc_int_base::operator ^= (v);
return *this;
}
sc_int<W> &
operator <<= (int_type v)
{
sc_int_base::operator <<= (v);
return *this;
}
sc_int<W> &
operator >>= (int_type v)
{
sc_int_base::operator >>= (v);
return *this;
}
// prefix and postfix increment and decrement operators
sc_int<W> &
operator ++ () // prefix
{
sc_int_base::operator ++ ();
return *this;
}
const sc_int<W>
operator ++ (int) // postfix
{
return sc_int<W>(sc_int_base::operator ++ (0));
}
sc_int<W> &
operator -- () // prefix
{
sc_int_base::operator -- ();
return *this;
}
const sc_int<W>
operator -- (int) // postfix
{
return sc_int<W>(sc_int_base::operator -- (0));
}
};
} // namespace sc_dt
#endif // __SYSTEMC_EXT_DT_INT_SC_INT_HH__

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,192 @@
/*****************************************************************************
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_length_param.h -
Original Author: Martin Janssen, Synopsys, Inc., 2002-03-19
*****************************************************************************/
/*****************************************************************************
MODIFICATION LOG - modifiers, enter your name, affiliation, date and
changes you are making here.
Name, Affiliation, Date:
Description of Modification:
*****************************************************************************/
// $Log: sc_length_param.h,v $
// Revision 1.3 2011/08/24 22:05:46 acg
// Torsten Maehne: initialization changes to remove warnings.
//
// Revision 1.2 2011/02/18 20:19:15 acg
// Andy Goodrich: updating Copyright notice.
//
// Revision 1.1.1.1 2006/12/15 20:20:05 acg
// SystemC 2.3
//
// Revision 1.4 2006/05/08 17:50:01 acg
// Andy Goodrich: Added David Long's declarations for friend operators,
// functions, and methods, to keep the Microsoft compiler happy.
//
// Revision 1.3 2006/01/13 18:49:32 acg
// Added $Log command so that CVS check in comments are reproduced in the
// source.
//
#ifndef __SYSTEMC_EXT_DT_INT_SC_LENGTH_PARAM_HH__
#define __SYSTEMC_EXT_DT_INT_SC_LENGTH_PARAM_HH__
#include <iostream>
#include "../fx/sc_context.hh"
#include "../fx/sc_fxdefs.hh"
namespace sc_dt
{
// classes defined in this module
class sc_length_param;
// friend operator declarations
bool operator == (const sc_length_param &, const sc_length_param &);
bool operator != (const sc_length_param &, const sc_length_param &);
// ----------------------------------------------------------------------------
// CLASS : sc_length_param
//
// Length parameter type.
// ----------------------------------------------------------------------------
class sc_length_param
{
public:
sc_length_param();
sc_length_param(int);
sc_length_param(const sc_length_param &);
explicit sc_length_param(sc_without_context);
sc_length_param &operator = (const sc_length_param &);
friend bool operator == (const sc_length_param &, const sc_length_param &);
friend bool operator != (const sc_length_param &, const sc_length_param &);
int len() const;
void len(int);
const std::string to_string() const;
void print(::std::ostream & =::std::cout) const;
void dump(::std::ostream & =::std::cout) const;
private:
int m_len;
};
} // namespace sc_dt
// ----------------------------------------------------------------------------
// TYPEDEF : sc_length_context
//
// Context type for the length parameter type.
// ----------------------------------------------------------------------------
namespace sc_dt
{
extern template class sc_global<sc_length_param>;
extern template class sc_context<sc_length_param>;
typedef sc_context<sc_length_param> sc_length_context;
// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
inline sc_length_param::sc_length_param() : m_len()
{
*this = sc_length_context::default_value();
}
inline sc_length_param::sc_length_param(int len_) : m_len(len_)
{
SC_CHECK_WL_(len_);
}
inline sc_length_param::sc_length_param(const sc_length_param &a) :
m_len(a.m_len)
{}
inline sc_length_param::sc_length_param(sc_without_context) :
m_len(SC_DEFAULT_WL_)
{}
inline sc_length_param &
sc_length_param::operator = (const sc_length_param &a)
{
if (&a != this) {
m_len = a.m_len;
}
return *this;
}
inline bool
operator == (const sc_length_param &a, const sc_length_param &b)
{
return (a.m_len == b.m_len);
}
inline bool
operator != (const sc_length_param &a, const sc_length_param &b)
{
return (a.m_len != b.m_len);
}
inline int
sc_length_param::len() const
{
return m_len;
}
inline void
sc_length_param::len(int len_)
{
SC_CHECK_WL_(len_);
m_len = len_;
}
inline ::std::ostream &
operator << (::std::ostream &os, const sc_length_param &a)
{
a.print(os);
return os;
}
} // namespace sc_dt
#endif // __SYSTEMC_EXT_DT_INT_SC_LENGTH_PARAM_HH__

View File

@@ -18,12 +18,52 @@
*****************************************************************************/
/*****************************************************************************
sc_nbdefs.h -- Top level header file for arbitrary precision signed/unsigned
arithmetic. This file defines all the constants needed.
Original Author: Ali Dasdan, Synopsys, Inc.
*****************************************************************************/
#ifndef __SYSTEMC_DT_SC_NBDEFS_H__
#define __SYSTEMC_DT_SC_NBDEFS_H__
/*****************************************************************************
MODIFICATION LOG - modifiers, enter your name, affiliation, date and
changes you are making here.
Name, Affiliation, Date: Torsten Maehne, Berner Fachhochschule,
2016-09-24
Description of Modification: Move constant definitions to the header so that
that their value is known at compile time.
*****************************************************************************/
// $Log: sc_nbdefs.h,v $
// Revision 1.7 2011/02/18 20:19:15 acg
// Andy Goodrich: updating Copyright notice.
//
// Revision 1.6 2011/02/18 20:09:34 acg
// Philipp A. Hartmann: added alternative #define for Windows to guard.
//
// Revision 1.5 2011/01/20 16:52:20 acg
// Andy Goodrich: changes for IEEE 1666 2011.
//
// Revision 1.4 2010/02/08 18:35:55 acg
// Andy Goodrich: Philipp Hartmann's changes for Solaris and Linux 64.
//
// Revision 1.2 2009/05/22 16:06:29 acg
// Andy Goodrich: process control updates.
//
// Revision 1.1.1.1 2006/12/15 20:20:05 acg
// SystemC 2.3
//
// Revision 1.3 2006/01/13 18:49:32 acg
// Added $Log command so that CVS check in comments are reproduced in the
// source.
//
#ifndef __SYSTEMC_EXT_DT_INT_SC_NBDEFS_HH__
#define __SYSTEMC_EXT_DT_INT_SC_NBDEFS_HH__
#include <stdint.h>
@@ -77,8 +117,8 @@ typedef int small_type;
#define LOG2_BITS_PER_BYTE 3
// Attributes of the unsigned long. These definitions are used mainly in
// the functions that are aware of the internal representation of digits,
// e.g., get/set_packed_rep().
// the functions that are aware of the internal representation of
// digits, e.g., get/set_packed_rep().
#define BYTES_PER_DIGIT_TYPE 4
#define BITS_PER_DIGIT_TYPE 32
@@ -120,35 +160,41 @@ static const int MAX_NDIGITS = DIV_CEIL(SC_MAX_NBITS) + 2;
// since the unsigned long data type varies in size between 32-bit and 64-bit
// machines.
typedef unsigned int sc_digit; // 32-bit unsigned integer
typedef unsigned int sc_digit; // 32-bit unsigned integer
// Support for the long long type. This type is not in the standard
// but is usually supported by compilers.
#if defined(__x86_64__) || defined(__aarch64__)
typedef long long int64;
typedef unsigned long long uint64;
#else
typedef int64_t int64;
typedef uint64_t uint64;
#endif
static const uint64 UINT64_ZERO = 0ULL;
static const uint64 UINT64_ONE = 1ULL;
static const uint64 UINT64_ZERO = 0ULL;
static const uint64 UINT64_ONE = 1ULL;
static const uint64 UINT64_32ONES = 0x00000000ffffffffULL;
// Bits per ...
// will be deleted in the future. Use numeric_limits instead
#define BITS_PER_CHAR 8
#define BITS_PER_INT (sizeof(int) * BITS_PER_CHAR)
#define BITS_PER_LONG (sizeof(long) * BITS_PER_CHAR)
#define BITS_PER_INT64 (sizeof(::sc_dt::int64) * BITS_PER_CHAR)
#define BITS_PER_UINT (sizeof(unsigned int) * BITS_PER_CHAR)
#define BITS_PER_ULONG (sizeof(unsigned long) * BITS_PER_CHAR)
#define BITS_PER_CHAR 8
#define BITS_PER_INT (sizeof(int) * BITS_PER_CHAR)
#define BITS_PER_LONG (sizeof(long) * BITS_PER_CHAR)
#define BITS_PER_INT64 (sizeof(::sc_dt::int64) * BITS_PER_CHAR)
#define BITS_PER_UINT (sizeof(unsigned int) * BITS_PER_CHAR)
#define BITS_PER_ULONG (sizeof(unsigned long) * BITS_PER_CHAR)
#define BITS_PER_UINT64 (sizeof(::sc_dt::uint64) * BITS_PER_CHAR)
// Digits per ...
#define DIGITS_PER_CHAR 1
#define DIGITS_PER_INT ((BITS_PER_INT+29)/30)
#define DIGITS_PER_LONG ((BITS_PER_LONG+29)/30)
#define DIGITS_PER_INT64 ((BITS_PER_INT64+29)/30)
#define DIGITS_PER_UINT ((BITS_PER_UINT+29)/30)
#define DIGITS_PER_ULONG ((BITS_PER_ULONG+29)/30)
#define DIGITS_PER_UINT64 ((BITS_PER_UINT64+29)/30)
#define DIGITS_PER_CHAR 1
#define DIGITS_PER_INT ((BITS_PER_INT + 29) / 30)
#define DIGITS_PER_LONG ((BITS_PER_LONG + 29) / 30)
#define DIGITS_PER_INT64 ((BITS_PER_INT64 + 29) / 30)
#define DIGITS_PER_UINT ((BITS_PER_UINT + 29) / 30)
#define DIGITS_PER_ULONG ((BITS_PER_ULONG + 29) / 30)
#define DIGITS_PER_UINT64 ((BITS_PER_UINT64 + 29) / 30)
// Above, BITS_PER_X is mainly used for sc_signed, and BITS_PER_UX is
// mainly used for sc_unsigned.
@@ -165,4 +211,4 @@ static const uint64 UINT_ONE = UINT64_ONE;
} // namespace sc_dt
#endif
#endif // __SYSTEMC_EXT_DT_INT_SC_NBDEFS_HH__

View File

@@ -0,0 +1,108 @@
/*****************************************************************************
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_nbexterns.h -- External functions for both sc_signed and sc_unsigned
classes. These functions work on two parameters u and
v, and copy the result to the first parameter u. This
is also the reason that they are suffixed with _on_help.
The vec_* functions are called through either these
functions or those in sc_nbfriends.cpp. The functions in
sc_nbfriends.cpp perform their work on two inputs u and v,
and return the result object.
Original Author: Ali Dasdan, Synopsys, Inc.
*****************************************************************************/
/*****************************************************************************
MODIFICATION LOG - modifiers, enter your name, affiliation, date and
changes you are making here.
Name, Affiliation, Date:
Description of Modification:
*****************************************************************************/
// $Log: sc_nbexterns.h,v $
// Revision 1.2 2011/02/18 20:19:15 acg
// Andy Goodrich: updating Copyright notice.
//
// Revision 1.1.1.1 2006/12/15 20:20:05 acg
// SystemC 2.3
//
// Revision 1.3 2006/01/13 18:49:32 acg
// Added $Log command so that CVS check in comments are reproduced in the
// source.
//
#ifndef __SYSTEMC_EXT_DT_INT_SC_NBEXTERNS_HH__
#define __SYSTEMC_EXT_DT_INT_SC_NBEXTERNS_HH__
#include "sc_nbutils.hh"
namespace sc_dt
{
extern void add_on_help(
small_type &us, int unb, int und, sc_digit *ud,
small_type vs, int vnb, int vnd, const sc_digit *vd);
extern void mul_on_help_signed(
small_type &us, int unb, int und, sc_digit *ud,
int vnb, int vnd, const sc_digit *vd);
void div_on_help_signed(
small_type &us, int unb, int und, sc_digit *ud,
int vnb, int vnd, const sc_digit *vd);
extern void mod_on_help_signed(
small_type &us, int unb, int und, sc_digit *ud,
int vnb, int vnd, const sc_digit *vd);
extern void mul_on_help_unsigned(
small_type &us, int unb, int und, sc_digit *ud,
int vnb, int vnd, const sc_digit *vd);
void div_on_help_unsigned(
small_type &us, int unb, int und, sc_digit *ud,
int vnb, int vnd, const sc_digit *vd);
extern void mod_on_help_unsigned(
small_type &us, int unb, int und, sc_digit *ud,
int vnb, int vnd, const sc_digit *vd);
extern void and_on_help(
small_type us, int unb, int und, sc_digit *ud,
small_type vs, int vnb, int vnd, const sc_digit *vd);
extern void or_on_help(
small_type us, int unb, int und, sc_digit *ud,
small_type vs, int vnb, int vnd, const sc_digit *vd);
extern void xor_on_help(
small_type us, int unb, int und, sc_digit *ud,
small_type vs, int vnb, int vnd, const sc_digit *vd);
} // namespace sc_dt
#endif // __SYSTEMC_EXT_DT_INT_SC_NBEXTERNS_HH__

View File

@@ -0,0 +1,832 @@
/*****************************************************************************
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_nbutils.h -- External and friend functions for both sc_signed and
sc_unsigned classes.
Original Author: Ali Dasdan, Synopsys, Inc.
*****************************************************************************/
/*****************************************************************************
MODIFICATION LOG - modifiers, enter your name, affiliation, date and
changes you are making here.
Name, Affiliation, Date:
Description of Modification:
*****************************************************************************/
// $Log: sc_nbutils.h,v $
// Revision 1.6 2011/09/08 16:12:15 acg
// Philipp A. Hartmann: fix issue with Sun machines wrt real math libraries.
//
// Revision 1.5 2011/08/26 23:00:01 acg
// Torsten Maehne: remove use of ieeefp.h.
//
// Revision 1.4 2011/08/15 16:43:24 acg
// Torsten Maehne: changes to remove unused argument warnings.
//
// Revision 1.3 2011/02/18 20:19:15 acg
// Andy Goodrich: updating Copyright notice.
//
// Revision 1.2 2010/09/06 16:35:48 acg
// Andy Goodrich: changed i386 to __i386__ in ifdef's.
//
// Revision 1.1.1.1 2006/12/15 20:20:05 acg
// SystemC 2.3
//
// Revision 1.3 2006/01/13 18:49:32 acg
// Added $Log command so that CVS check in comments are reproduced in the
// source.
//
#ifndef __SYSTEMC_EXT_DT_INT_SC_NBUTILS_HH__
#define __SYSTEMC_EXT_DT_INT_SC_NBUTILS_HH__
#include <cmath>
#include <ios>
#include <limits>
#include <ostream>
#include "../../utils/sc_report_handler.hh"
#include "sc_nbdefs.hh"
namespace sc_dt
{
//-----------------------------------------------------------------------------
//"sc_io_base"
//
// This inline function returns the type of an i/o stream's base as a SystemC
// base designator.
// stream_object = reference to the i/o stream whose base is to be returned.
//
//"sc_io_show_base"
//
// This inline function returns true if the base should be shown when a SystemC
// value is displayed via the supplied stream operator.
// stream_object = reference to the i/o stream to return showbase value for.
//-----------------------------------------------------------------------------
inline sc_numrep
sc_io_base(::std::ostream &os, sc_numrep def_base)
{
std::ios::fmtflags flags = os.flags() & std::ios::basefield;
if (flags & ::std::ios::dec) return SC_DEC;
if (flags & ::std::ios::hex) return SC_HEX;
if (flags & ::std::ios::oct) return SC_OCT;
return def_base;
}
inline bool
sc_io_show_base(::std::ostream &os)
{
return (os.flags() & ::std::ios::showbase) != 0;
}
const std::string to_string(sc_numrep);
inline ::std::ostream &
operator << (::std::ostream &os, sc_numrep numrep)
{
os << to_string(numrep);
return os;
}
// ----------------------------------------------------------------------------
// One transition of the FSM to find base and sign of a number.
extern small_type fsm_move(
char c, small_type &b, small_type &s, small_type &state);
// Parse a character string into its equivalent binary bits.
extern void parse_binary_bits(
const char *src_p, int dst_n, sc_digit *data_p, sc_digit *ctrl_p=0);
// Parse a character string into its equivalent hexadecimal bits.
extern void parse_hex_bits(
const char *src_p, int dst_n, sc_digit *data_p, sc_digit *ctrl_p=0);
// Find the base and sign of a number in v.
extern const char *get_base_and_sign(
const char *v, small_type &base, small_type &sign);
// Create a number out of v in base.
extern small_type
vec_from_str(int unb, int und, sc_digit *u,
const char *v, sc_numrep base=SC_NOBASE);
// ----------------------------------------------------------------------------
// Naming convention for the vec_ functions below:
// vec_OP(u, v, w) : computes w = u OP v.
// vec_OP_on(u, v) : computes u = u OP v if u has more digits than v.
// vec_OP_on2(u, v) : computes u = u OP v if u has fewer digits than v.
// _large : parameters are vectors.
// _small : one of the parameters is a single digit.
// Xlen : the number of digits in X.
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Functions for vector addition: w = u + v or u += v.
// ----------------------------------------------------------------------------
extern void vec_add(int ulen, const sc_digit *u,
int vlen, const sc_digit *v, sc_digit *w);
extern void vec_add_on(int ulen, sc_digit *u, int vlen, const sc_digit *v);
extern void vec_add_on2(int ulen, sc_digit *u, int vlen, const sc_digit *v);
extern void vec_add_small(int ulen, const sc_digit *u,
sc_digit v, sc_digit *w);
extern void vec_add_small_on(int ulen, sc_digit *u, sc_digit v);
// ----------------------------------------------------------------------------
// Functions for vector subtraction: w = u - v, u -= v, or u = v - u.
// ----------------------------------------------------------------------------
extern void vec_sub(int ulen, const sc_digit *u,
int vlen, const sc_digit *v, sc_digit *w);
extern void vec_sub_on(int ulen, sc_digit *u, int vlen, const sc_digit *v);
extern void vec_sub_on2(int ulen, sc_digit *u, int vlen, const sc_digit *v);
extern void vec_sub_small(int ulen, const sc_digit *u,
sc_digit v, sc_digit *w);
extern void vec_sub_small_on(int ulen, sc_digit *u, sc_digit v);
// ----------------------------------------------------------------------------
// Functions for vector multiplication: w = u * v or u *= v.
// ----------------------------------------------------------------------------
extern void vec_mul(int ulen, const sc_digit *u,
int vlen, const sc_digit *v, sc_digit *w);
extern void vec_mul_small(int ulen, const sc_digit *u,
sc_digit v, sc_digit *w);
extern void vec_mul_small_on(int ulen, sc_digit *u, sc_digit v);
// ----------------------------------------------------------------------------
// Functions for vector division: w = u / v.
// ----------------------------------------------------------------------------
extern void vec_div_large(int ulen, const sc_digit *u,
int vlen, const sc_digit *v, sc_digit *w);
extern void vec_div_small(int ulen, const sc_digit *u,
sc_digit v, sc_digit *w);
// ----------------------------------------------------------------------------
// Functions for vector remainder: w = u % v or u %= v.
// ----------------------------------------------------------------------------
extern void vec_rem_large(int ulen, const sc_digit *u,
int vlen, const sc_digit *v, sc_digit *w);
extern sc_digit vec_rem_small(int ulen, const sc_digit *u, sc_digit v);
extern sc_digit vec_rem_on_small(int ulen, sc_digit *u, sc_digit v);
// ----------------------------------------------------------------------------
// Functions to convert between vectors of char and sc_digit.
// ----------------------------------------------------------------------------
extern int vec_to_char(int ulen, const sc_digit *u, int vlen, uchar *v);
extern void vec_from_char(int ulen, const uchar *u, int vlen, sc_digit *v);
// ----------------------------------------------------------------------------
// Functions to shift left or right, or to create a mirror image of vectors.
// ----------------------------------------------------------------------------
extern void vec_shift_left(int ulen, sc_digit *u, int nsl);
extern void vec_shift_right(int vlen, sc_digit *u, int nsr, sc_digit fill=0);
extern void vec_reverse(int unb, int und, sc_digit *ud, int l, int r=0);
// ----------------------------------------------------------------------------
// Various utility functions.
// ----------------------------------------------------------------------------
// Return the low half part of d.
inline sc_digit low_half(sc_digit d) { return (d & HALF_DIGIT_MASK); }
// Return the high half part of d. The high part of the digit may have
// more bits than BITS_PER_HALF_DIGIT due to, e.g., overflow in the
// multiplication. Hence, in other functions that use high_half(),
// make sure that the result contains BITS_PER_HALF_DIGIT if
// necessary. This is done by high_half_masked().
inline sc_digit high_half(sc_digit d) { return (d >> BITS_PER_HALF_DIGIT); }
inline sc_digit
high_half_masked(sc_digit d)
{
return (high_half(d) & HALF_DIGIT_MASK);
}
// Concatenate the high part h and low part l. Assumes that h and l
// are less than or equal to HALF_DIGIT_MASK;
inline sc_digit
concat(sc_digit h, sc_digit l)
{
return ((h << BITS_PER_HALF_DIGIT) | l);
}
// Create a number with n 1's.
inline sc_digit
one_and_ones(int n)
{
return (((sc_digit) 1 << n) - 1);
}
// Create a number with one 1 and n 0's.
inline sc_digit one_and_zeros(int n) { return ((sc_digit) 1 << n); }
// ----------------------------------------------------------------------------
// Find the digit that bit i is in.
inline int digit_ord(int i) { return (i / BITS_PER_DIGIT); }
// Find the bit in digit_ord(i) that bit i corressponds to.
inline int bit_ord(int i) { return (i % BITS_PER_DIGIT); }
// ----------------------------------------------------------------------------
// Functions to compare, zero, complement vector(s).
// ----------------------------------------------------------------------------
// Compare u and v and return r
// r = 0 if u == v
// r < 0 if u < v
// r > 0 if u > v
// - Assume that all the leading zero digits are already skipped.
// - ulen and/or vlen can be zero.
// - Every digit is less than or equal to DIGIT_MASK;
inline int
vec_cmp(int ulen, const sc_digit *u,
int vlen, const sc_digit *v)
{
#ifdef DEBUG_SYSTEMC
// sc_assert((ulen <= 0) || (u != NULL));
// sc_assert((vlen <= 0) || (v != NULL));
// ulen and vlen can be equal to 0 because vec_cmp can be called
// after vec_skip_leading_zeros.
sc_assert((ulen >= 0) && (u != NULL));
sc_assert((vlen >= 0) && (v != NULL));
// If ulen > 0, then the leading digit of u must be non-zero.
sc_assert((ulen <= 0) || (u[ulen - 1] != 0));
sc_assert((vlen <= 0) || (v[vlen - 1] != 0));
#endif
if (ulen != vlen)
return (ulen - vlen);
// ulen == vlen >= 1
while ((--ulen >= 0) && (u[ulen] == v[ulen]))
{}
if (ulen < 0)
return 0;
#ifdef DEBUG_SYSTEMC
// Test to see if the result is wrong due to the presence of
// overflow bits.
sc_assert((u[ulen] & DIGIT_MASK) != (v[ulen] & DIGIT_MASK));
#endif
return (int)(u[ulen] - v[ulen]);
}
// Find the index of the first non-zero digit.
// - ulen (before) = the number of digits in u.
// - the returned value = the index of the first non-zero digit.
// A negative value of -1 indicates that every digit in u is zero.
inline int
vec_find_first_nonzero(int ulen, const sc_digit *u)
{
#ifdef DEBUG_SYSTEMC
// sc_assert((ulen <= 0) || (u != NULL));
sc_assert((ulen > 0) && (u != NULL));
#endif
while ((--ulen >= 0) && (! u[ulen]))
{}
return ulen;
}
// Skip all the leading zero digits.
// - ulen (before) = the number of digits in u.
// - the returned value = the number of non-zero digits in u.
// - the returned value is non-negative.
inline int
vec_skip_leading_zeros(int ulen, const sc_digit *u)
{
#ifdef DEBUG_SYSTEMC
// sc_assert((ulen <= 0) || (u != NULL));
sc_assert((ulen > 0) && (u != NULL));
#endif
return (1 + vec_find_first_nonzero(ulen, u));
}
// Compare u and v and return r
// r = 0 if u == v
// r < 0 if u < v
// r > 0 if u > v
inline int
vec_skip_and_cmp(int ulen, const sc_digit *u, int vlen, const sc_digit *v)
{
#ifdef DEBUG_SYSTEMC
sc_assert((ulen > 0) && (u != NULL));
sc_assert((vlen > 0) && (v != NULL));
#endif
ulen = vec_skip_leading_zeros(ulen, u);
vlen = vec_skip_leading_zeros(vlen, v);
// ulen and/or vlen can be equal to zero here.
return vec_cmp(ulen, u, vlen, v);
}
// Set u[i] = 0 where i = from ... (ulen - 1).
inline void
vec_zero(int from, int ulen, sc_digit *u)
{
#ifdef DEBUG_SYSTEMC
sc_assert((ulen > 0) && (u != NULL));
#endif
for (int i = from; i < ulen; i++)
u[i] = 0;
}
// Set u[i] = 0 where i = 0 .. (ulen - 1).
inline void vec_zero(int ulen, sc_digit *u) { vec_zero(0, ulen, u); }
// Copy n digits from v to u.
inline void
vec_copy(int n, sc_digit *u, const sc_digit *v)
{
#ifdef DEBUG_SYSTEMC
sc_assert((n > 0) && (u != NULL) && (v != NULL));
#endif
for (int i = 0; i < n; ++i)
u[i] = v[i];
}
// Copy v to u, where ulen >= vlen, and zero the rest of the digits in u.
inline void
vec_copy_and_zero(int ulen, sc_digit *u, int vlen, const sc_digit *v)
{
#ifdef DEBUG_SYSTEMC
sc_assert((ulen > 0) && (u != NULL));
sc_assert((vlen > 0) && (v != NULL));
sc_assert(ulen >= vlen);
#endif
vec_copy(vlen, u, v);
vec_zero(vlen, ulen, u);
}
// 2's-complement the digits in u.
inline void
vec_complement(int ulen, sc_digit *u)
{
#ifdef DEBUG_SYSTEMC
sc_assert((ulen > 0) && (u != NULL));
#endif
sc_digit carry = 1;
for (int i = 0; i < ulen; ++i) {
carry += (~u[i] & DIGIT_MASK);
u[i] = carry & DIGIT_MASK;
carry >>= BITS_PER_DIGIT;
}
}
// ----------------------------------------------------------------------------
// Functions to handle built-in types or signs.
// ----------------------------------------------------------------------------
// u = v
// - v is an unsigned long or uint64, and positive integer.
template<class Type>
inline void
from_uint(int ulen, sc_digit *u, Type v)
{
#ifdef DEBUG_SYSTEMC
// sc_assert((ulen <= 0) || (u != NULL));
sc_assert((ulen > 0) && (u != NULL));
sc_assert(v >= 0);
#endif
int i = 0;
while (v && (i < ulen)) {
u[i++] = static_cast<sc_digit>(v & DIGIT_MASK);
v >>= BITS_PER_DIGIT;
}
vec_zero(i, ulen, u);
}
#ifndef __GNUC__
# define SC_LIKELY_(x) !!(x)
#else
# define SC_LIKELY_(x) __builtin_expect(!!(x), 1)
#endif
// Get u's sign and return its absolute value.
// u can be long, unsigned long, int64, or uint64.
template<class Type>
inline small_type
get_sign(Type &u)
{
if (u > 0)
return SC_POS;
if (u == 0)
return SC_ZERO;
// no positive number representable for minimum value,
// leave as is to avoid Undefined Behaviour
if (SC_LIKELY_(u > (std::numeric_limits<Type>::min)()))
u = -u;
return SC_NEG;
}
#undef SC_LIKELY_
// Return us * vs:
// - Return SC_ZERO if either sign is SC_ZERO.
// - Return SC_POS if us == vs
// - Return SC_NEG if us != vs.
inline small_type
mul_signs(small_type us, small_type vs)
{
if ((us == SC_ZERO) || (vs == SC_ZERO))
return SC_ZERO;
if (us == vs)
return SC_POS;
return SC_NEG;
}
// ----------------------------------------------------------------------------
// Functions to test for errors and print out error messages.
// ----------------------------------------------------------------------------
#ifdef SC_MAX_NBITS
void test_bound_failed(int nb);
inline void
test_bound(int nb)
{
if (nb > SC_MAX_NBITS) {
test_bound_failed(nb);
sc_core::sc_abort(); // can't recover from here
}
}
#endif
template<class Type>
inline void
div_by_zero(Type s)
{
if (s == 0) {
SC_REPORT_ERROR("operation failed",
"div_by_zero<Type>(Type) : division by zero");
sc_core::sc_abort(); // can't recover from here
}
}
// ----------------------------------------------------------------------------
// Functions to check if a given vector is zero or make one.
// ----------------------------------------------------------------------------
// If u[i] is zero for every i = 0,..., ulen - 1, return SC_ZERO,
// else return s.
inline small_type
check_for_zero(small_type s, int ulen, const sc_digit *u)
{
#ifdef DEBUG_SYSTEMC
// sc_assert(ulen >= 0);
sc_assert((ulen > 0) && (u != NULL));
#endif
if (vec_find_first_nonzero(ulen, u) < 0)
return SC_ZERO;
return s;
}
// If u[i] is zero for every i = 0,..., ulen - 1, return true,
// else return false.
inline bool
check_for_zero(int ulen, const sc_digit *u)
{
#ifdef DEBUG_SYSTEMC
// sc_assert(ulen >= 0);
sc_assert((ulen > 0) && (u != NULL));
#endif
if (vec_find_first_nonzero(ulen, u) < 0)
return true;
return false;
}
inline small_type
make_zero(int nd, sc_digit *d)
{
vec_zero(nd, d);
return SC_ZERO;
}
// ----------------------------------------------------------------------------
// Functions for both signed and unsigned numbers to convert sign-magnitude
// (SM) and 2's complement (2C) representations.
// added = 1 => for signed.
// added = 0 => for unsigned.
// IF_SC_SIGNED can be used as 'added'.
// ----------------------------------------------------------------------------
// Trim the extra leading bits of a signed or unsigned number.
inline void
trim(small_type added, int nb, int nd, sc_digit *d)
{
#ifdef DEBUG_SYSTEMC
sc_assert((nb > 0) && (nd > 0) && (d != NULL));
#endif
d[nd - 1] &= one_and_ones(bit_ord(nb - 1) + added);
}
// Convert an (un)signed number from sign-magnitude representation to
// 2's complement representation and trim the extra bits.
inline void
convert_SM_to_2C_trimmed(small_type added,
small_type s, int nb, int nd, sc_digit *d)
{
if (s == SC_NEG) {
vec_complement(nd, d);
trim(added, nb, nd, d);
}
}
// Convert an (un)signed number from sign-magnitude representation to
// 2's complement representation but do not trim the extra bits.
inline void
convert_SM_to_2C(small_type s, int nd, sc_digit *d)
{
if (s == SC_NEG)
vec_complement(nd, d);
}
// ----------------------------------------------------------------------------
// Functions to convert between sign-magnitude (SM) and 2's complement
// (2C) representations of signed numbers.
// ----------------------------------------------------------------------------
// Trim the extra leading bits off a signed number.
inline void
trim_signed(int nb, int nd, sc_digit *d)
{
#ifdef DEBUG_SYSTEMC
sc_assert((nb > 0) && (nd > 0) && (d != NULL));
#endif
d[nd - 1] &= one_and_ones(bit_ord(nb - 1) + 1);
}
// Convert a signed number from 2's complement representation to
// sign-magnitude representation, and return its sign. nd is d's
// actual size, without zeros eliminated.
inline small_type
convert_signed_2C_to_SM(int nb, int nd, sc_digit *d)
{
#ifdef DEBUG_SYSTEMC
sc_assert((nb > 0) && (nd > 0) && (d != NULL));
#endif
small_type s;
int xnb = bit_ord(nb - 1) + 1;
// Test the sign bit.
if (d[nd - 1] & one_and_zeros(xnb - 1)) {
s = SC_NEG;
vec_complement(nd, d);
} else {
s = SC_POS;
}
// Trim the last digit.
d[nd - 1] &= one_and_ones(xnb);
// Check if the new number is zero.
if (s == SC_POS)
return check_for_zero(s, nd, d);
return s;
}
// Convert a signed number from sign-magnitude representation to 2's
// complement representation, get its sign, convert back to
// sign-magnitude representation, and return its sign. nd is d's
// actual size, without zeros eliminated.
inline small_type
convert_signed_SM_to_2C_to_SM(small_type s, int nb, int nd, sc_digit *d)
{
convert_SM_to_2C(s, nd, d);
return convert_signed_2C_to_SM(nb, nd, d);
}
// Convert a signed number from sign-magnitude representation to 2's
// complement representation and trim the extra bits.
inline void
convert_signed_SM_to_2C_trimmed(small_type s, int nb, int nd, sc_digit *d)
{
convert_SM_to_2C_trimmed(1, s, nb, nd, d);
}
// Convert a signed number from sign-magnitude representation to 2's
// complement representation but do not trim the extra bits.
inline void
convert_signed_SM_to_2C(small_type s, int nd, sc_digit *d)
{
convert_SM_to_2C(s, nd, d);
}
// ----------------------------------------------------------------------------
// Functions to convert between sign-magnitude (SM) and 2's complement
// (2C) representations of unsigned numbers.
// ----------------------------------------------------------------------------
// Trim the extra leading bits off an unsigned number.
inline void
trim_unsigned(int nb, int nd, sc_digit *d)
{
#ifdef DEBUG_SYSTEMC
sc_assert((nb > 0) && (nd > 0) && (d != NULL));
#endif
d[nd - 1] &= one_and_ones(bit_ord(nb - 1));
}
// Convert an unsigned number from 2's complement representation to
// sign-magnitude representation, and return its sign. nd is d's
// actual size, without zeros eliminated.
inline small_type
convert_unsigned_2C_to_SM(int nb, int nd, sc_digit *d)
{
trim_unsigned(nb, nd, d);
return check_for_zero(SC_POS, nd, d);
}
// Convert an unsigned number from sign-magnitude representation to
// 2's complement representation, get its sign, convert back to
// sign-magnitude representation, and return its sign. nd is d's
// actual size, without zeros eliminated.
inline small_type
convert_unsigned_SM_to_2C_to_SM(small_type s, int nb, int nd, sc_digit *d)
{
convert_SM_to_2C(s, nd, d);
return convert_unsigned_2C_to_SM(nb, nd, d);
}
// Convert an unsigned number from sign-magnitude representation to
// 2's complement representation and trim the extra bits.
inline void
convert_unsigned_SM_to_2C_trimmed(small_type s, int nb, int nd, sc_digit *d)
{
convert_SM_to_2C_trimmed(0, s, nb, nd, d);
}
// Convert an unsigned number from sign-magnitude representation to
// 2's complement representation but do not trim the extra bits.
inline void
convert_unsigned_SM_to_2C(small_type s, int nd, sc_digit *d)
{
convert_SM_to_2C(s, nd, d);
}
// ----------------------------------------------------------------------------
// Functions to copy one (un)signed number to another.
// ----------------------------------------------------------------------------
// Copy v to u.
inline void
copy_digits_signed(small_type &us,
int unb, int und, sc_digit *ud,
int vnb, int vnd, const sc_digit *vd)
{
if (und <= vnd) {
vec_copy(und, ud, vd);
if (unb <= vnb)
us = convert_signed_SM_to_2C_to_SM(us, unb, und, ud);
} else { // und > vnd
vec_copy_and_zero(und, ud, vnd, vd);
}
}
// Copy v to u.
inline void
copy_digits_unsigned(small_type &us,
int unb, int und, sc_digit *ud,
int /* vnb */, int vnd, const sc_digit *vd)
{
if (und <= vnd)
vec_copy(und, ud, vd);
else // und > vnd
vec_copy_and_zero(und, ud, vnd, vd);
us = convert_unsigned_SM_to_2C_to_SM(us, unb, und, ud);
}
// ----------------------------------------------------------------------------
// Faster set(i, v), without bound checking.
// ----------------------------------------------------------------------------
// A version of set(i, v) without bound checking.
inline void
safe_set(int i, bool v, sc_digit *d)
{
#ifdef DEBUG_SYSTEMC
sc_assert((i >= 0) && (d != NULL));
#endif
int bit_num = bit_ord(i);
int digit_num = digit_ord(i);
if (v)
d[digit_num] |= one_and_zeros(bit_num);
else
d[digit_num] &= ~(one_and_zeros(bit_num));
}
// ----------------------------------------------------------------------------
// Function to check if a double number is bad (NaN or infinite).
// ----------------------------------------------------------------------------
inline bool
is_nan(double v)
{
return std::numeric_limits<double>::has_quiet_NaN && (v != v);
}
inline bool
is_inf(double v)
{
return v == std::numeric_limits<double>::infinity() ||
v == -std::numeric_limits<double>::infinity();
}
inline void
is_bad_double(double v)
{
// Windows throws exception.
if (is_nan(v) || is_inf(v))
SC_REPORT_ERROR("value is not valid",
"is_bad_double(double v) : "
"v is not finite - NaN or Inf");
}
} // namespace sc_dt
#endif // __SYSTEMC_EXT_DT_INT_SC_NBUTILS_HH__

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,382 @@
/*****************************************************************************
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_uint.h -- An unsigned integer whose length is less than 64 bits.
Unlike arbitrary precision, arithmetic and bitwise operations
are performed using the native types (hence capped at 64 bits).
The sc_uint integer is useful when the user does not need
arbitrary precision and the performance is superior to
sc_bigint/sc_biguint.
Original Author: Amit Rao, Synopsys, Inc.
*****************************************************************************/
/*****************************************************************************
MODIFICATION LOG - modifiers, enter your name, affiliation, date and
changes you are making here.
Name, Affiliation, Date: Ali Dasdan, Synopsys, Inc.
Description of Modification: - Resolved ambiguity with sc_(un)signed.
- Merged the code for 64- and 32-bit versions
via the constants in sc_nbdefs.h.
- Eliminated redundant file inclusions.
Name, Affiliation, Date:
Description of Modification:
*****************************************************************************/
// $Log: sc_uint.h,v $
// Revision 1.2 2011/02/18 20:19:15 acg
// Andy Goodrich: updating Copyright notice.
//
// Revision 1.1.1.1 2006/12/15 20:20:05 acg
// SystemC 2.3
//
// Revision 1.3 2006/01/13 18:49:32 acg
// Added $Log command so that CVS check in comments are reproduced in the
// source.
//
#ifndef __SYSTEMC_EXT_DT_INT_SC_UINT_HH__
#define __SYSTEMC_EXT_DT_INT_SC_UINT_HH__
#include "sc_uint_base.hh"
namespace sc_dt
{
// classes defined in this module
template <int W>
class sc_uint;
// ----------------------------------------------------------------------------
// CLASS TEMPLATE : sc_uint<W>
//
// Template class sc_uint<W> is the interface that the user sees. It
// is derived from sc_uint_base and most of its methods are just
// wrappers that call the corresponding method in the parent
// class. Note that the length of sc_uint datatype is specified as a
// template parameter.
// ----------------------------------------------------------------------------
template <int W>
class sc_uint : public sc_uint_base
{
public:
// constructors
sc_uint() : sc_uint_base(W) {}
sc_uint(uint_type v) : sc_uint_base(v, W) {}
sc_uint(const sc_uint<W> &a) : sc_uint_base(a) {}
sc_uint(const sc_uint_base &a) : sc_uint_base(W)
{
sc_uint_base::operator = (a);
}
sc_uint(const sc_uint_subref_r &a) : sc_uint_base(W)
{
sc_uint_base::operator = (a);
}
template< class T >
sc_uint(const sc_generic_base<T> &a) : sc_uint_base(W)
{
sc_uint_base::operator = (a);
}
sc_uint(const sc_signed &a) : sc_uint_base(W)
{
sc_uint_base::operator = (a);
}
sc_uint(const sc_unsigned &a) : sc_uint_base(W)
{
sc_uint_base::operator = (a);
}
explicit sc_uint(const sc_fxval &a) : sc_uint_base(W)
{
sc_uint_base::operator = (a);
}
explicit sc_uint(const sc_fxval_fast &a) : sc_uint_base(W)
{
sc_uint_base::operator = (a);
}
explicit sc_uint(const sc_fxnum &a) : sc_uint_base(W)
{
sc_uint_base::operator = (a);
}
explicit sc_uint(const sc_fxnum_fast &a) : sc_uint_base(W)
{
sc_uint_base::operator = (a);
}
sc_uint(const sc_bv_base &a) : sc_uint_base(W)
{
sc_uint_base::operator = (a);
}
sc_uint(const sc_lv_base &a) : sc_uint_base(W)
{
sc_uint_base::operator = (a);
}
sc_uint(const char* a) : sc_uint_base(W)
{
sc_uint_base::operator = (a);
}
sc_uint(unsigned long a) : sc_uint_base(W)
{
sc_uint_base::operator = (a);
}
sc_uint(long a) : sc_uint_base(W)
{
sc_uint_base::operator = (a);
}
sc_uint(unsigned int a) : sc_uint_base(W)
{
sc_uint_base::operator = (a);
}
sc_uint(int a) : sc_uint_base(W)
{
sc_uint_base::operator = (a);
}
sc_uint(int64 a) : sc_uint_base(W)
{
sc_uint_base::operator = (a);
}
sc_uint(double a) : sc_uint_base(W)
{
sc_uint_base::operator = (a);
}
// assignment operators
sc_uint<W> &
operator = (uint_type v)
{
sc_uint_base::operator = (v);
return *this;
}
sc_uint<W> &
operator = (const sc_uint_base &a)
{
sc_uint_base::operator = (a);
return *this;
}
sc_uint<W> &
operator = (const sc_uint_subref_r &a)
{
sc_uint_base::operator = (a);
return *this;
}
sc_uint<W> &
operator = (const sc_uint<W> &a)
{
m_val = a.m_val;
return *this;
}
template<class T>
sc_uint<W> &
operator = (const sc_generic_base<T> &a)
{
sc_uint_base::operator = (a);
return *this;
}
sc_uint<W> &
operator = (const sc_signed &a)
{
sc_uint_base::operator = (a);
return *this;
}
sc_uint<W> &
operator = (const sc_unsigned &a)
{
sc_uint_base::operator = (a);
return *this;
}
sc_uint<W> &
operator = (const sc_fxval &a)
{
sc_uint_base::operator = (a);
return *this;
}
sc_uint<W> &
operator = (const sc_fxval_fast &a)
{
sc_uint_base::operator = (a);
return *this;
}
sc_uint<W> &
operator = (const sc_fxnum &a)
{
sc_uint_base::operator = (a);
return *this;
}
sc_uint<W> &
operator = (const sc_fxnum_fast &a)
{
sc_uint_base::operator = (a);
return *this;
}
sc_uint<W> &
operator = (const sc_bv_base &a)
{
sc_uint_base::operator = (a);
return *this;
}
sc_uint<W> &
operator = (const sc_lv_base &a)
{
sc_uint_base::operator = (a);
return *this;
}
sc_uint<W> &
operator = (const char* a)
{
sc_uint_base::operator = (a);
return *this;
}
sc_uint<W> &
operator = (unsigned long a)
{
sc_uint_base::operator = (a);
return *this;
}
sc_uint<W> &
operator = (long a)
{
sc_uint_base::operator = (a);
return *this;
}
sc_uint<W> &
operator = (unsigned int a)
{
sc_uint_base::operator = (a);
return *this;
}
sc_uint<W> &
operator = (int a)
{
sc_uint_base::operator = (a);
return *this;
}
sc_uint<W> &
operator = (int64 a)
{
sc_uint_base::operator = (a);
return *this;
}
sc_uint<W> &
operator = (double a)
{
sc_uint_base::operator = (a);
return *this;
}
// arithmetic assignment operators
sc_uint<W> &
operator += (uint_type v)
{
sc_uint_base::operator += (v);
return *this;
}
sc_uint<W> &
operator -= (uint_type v)
{
sc_uint_base::operator -= (v);
return *this;
}
sc_uint<W> &
operator *= (uint_type v)
{
sc_uint_base::operator *= (v);
return *this;
}
sc_uint<W> &
operator /= (uint_type v)
{
sc_uint_base::operator /= (v);
return *this;
}
sc_uint<W> &
operator %= (uint_type v)
{
sc_uint_base::operator %= (v);
return *this;
}
// bitwise assignment operators
sc_uint<W> &
operator &= (uint_type v)
{
sc_uint_base::operator &= (v);
return *this;
}
sc_uint<W> &
operator |= (uint_type v)
{
sc_uint_base::operator |= (v);
return *this;
}
sc_uint<W> &
operator ^= (uint_type v)
{
sc_uint_base::operator ^= (v);
return *this;
}
sc_uint<W> &
operator <<= (uint_type v)
{
sc_uint_base::operator <<= (v);
return *this;
}
sc_uint<W> &
operator >>= (uint_type v)
{
sc_uint_base::operator >>= (v);
return *this;
}
// prefix and postfix increment and decrement operators
sc_uint<W> &
operator ++ () // prefix
{
sc_uint_base::operator ++ ();
return *this;
}
const sc_uint<W>
operator ++ ( int ) // postfix
{
return sc_uint<W>(sc_uint_base::operator ++ (0));
}
sc_uint<W> &
operator -- () // prefix
{
sc_uint_base::operator -- ();
return *this;
}
const sc_uint<W>
operator -- (int) // postfix
{
return sc_uint<W>(sc_uint_base::operator -- (0));
}
};
} // namespace sc_dt
#endif // __SYSTEMC_EXT_DT_INT_SC_UINT_HH__

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,36 @@
/*
* Copyright 2018 Google, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: Gabe Black
*/
#ifndef __SYSTEMC_EXT_CORE_DT_MISC__MISC_HH__
#define __SYSTEMC_EXT_CORE_DT_MISC__MISC_HH__
#include "sc_concatref.hh"
#include "sc_value_base.hh"
#endif //__SYSTEMC_EXT_CORE_DT_MISC__MISC_HH__

View File

@@ -0,0 +1,35 @@
/*
* Copyright 2018 Google, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: Gabe Black
*/
#ifndef __SYSTEMC_EXT_CORE_MISC__USING_HH__
#define __SYSTEMC_EXT_CORE_MISC__USING_HH__
#include "_misc.hh"
#endif //__SYSTEMC_EXT_CORE_MISC__USING_HH__

View File

@@ -0,0 +1,806 @@
/*****************************************************************************
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_concatref.h -- Concatenation support.
Original Author: Andy Goodrich, Forte Design, Inc.
*****************************************************************************/
/*****************************************************************************
MODIFICATION LOG - modifiers, enter your name, affiliation, date and
changes you are making here.
Name, Affiliation, Date:
Description of Modification:
Andy Goodrich, Forte Design Systems, 17 Nov 2002
Creation of sc_concatref class by merging the capabilities of
sc_int_concref, sc_int_concref, sc_uint_concref, sc_uint_concref,
and implementing the capabilities of sc_signed_concref, sc_signed_concref,
sc_unsigned_concref, and sc_unsigned_concref. The resultant class allows
mixed mode concatenations on the left and right sides of an assignment.
*****************************************************************************/
// $Log: sc_concatref.h,v $
// Revision 1.6 2011/08/24 22:05:48 acg
// Torsten Maehne: initialization changes to remove warnings.
//
// Revision 1.5 2009/11/17 19:58:15 acg
// Andy Goodrich: fix of shift rhs possibilities to include "int".
//
// Revision 1.4 2009/02/28 00:26:29 acg
// Andy Goodrich: bug fixes.
//
// Revision 1.3 2008/04/29 20:23:55 acg
// Andy Goodrich: fixed the code that assigns the value of a string to
// an sc_concatref instance.
//
// Revision 1.2 2008/02/14 20:57:26 acg
// Andy Goodrich: added casts to ~0 instances to keep MSVC compiler happy.
//
// Revision 1.1.1.1 2006/12/15 20:20:05 acg
// SystemC 2.3
//
// Revision 1.4 2006/10/23 19:36:59 acg
// Andy Goodrich: changed casts for operations on concatenation values to
// mirror those of sc_unsigned. For instance, an sc_unsigned minus a value
// returns an sc_signed result, whereas an sc_concatref minus a value was
// returning an sc_unsigned result. Now both sc_unsigned and sc_concatref
// minus a value return an sc_signed result.
//
// Revision 1.3 2006/01/13 18:54:01 acg
// Andy Goodrich: added $Log command so that CVS comments are reproduced in
// the source.
//
#ifndef __SYSTEMC_EXT_DT_MISC_SC_CONCATREF_HH__
#define __SYSTEMC_EXT_DT_MISC_SC_CONCATREF_HH__
#include <iostream>
#include "../bit/sc_bv.hh"
#include "../bit/sc_lv.hh"
#include "../int/sc_int_base.hh"
#include "../int/sc_signed.hh"
#include "../int/sc_uint_base.hh"
#include "../int/sc_unsigned.hh"
#include "../sc_temporary.hh"
#include "sc_value_base.hh"
namespace sc_dt
{
// classes defined in this module
class sc_concatref;
class sc_concat_bool;
} // namespace sc_dt
namespace sc_core
{
extern sc_byte_heap sc_temp_heap; // Temporary storage.
// explicit template instantiations
extern template class sc_vpool<sc_dt::sc_concatref>;
extern template class sc_vpool<sc_dt::sc_concat_bool>;
} // namespace sc_core
namespace sc_dt {
// ----------------------------------------------------------------------------
// CLASS TEMPLATE : sc_concatref
//
// Proxy class for sized bit concatenation.
// ----------------------------------------------------------------------------
class sc_concatref : public sc_generic_base<sc_concatref>, public sc_value_base
{
public:
friend class sc_core::sc_vpool<sc_concatref>;
inline void
initialize(sc_value_base &left, sc_value_base &right)
{
bool left_xz; // True if x's and/or z's found in left.
bool right_xz; // True if x's and/or z's found in right.
m_left_p = (sc_value_base *)&left;
m_right_p = (sc_value_base *)&right;
m_len_r = right.concat_length(&right_xz);
m_len = left.concat_length(&left_xz) + m_len_r;
m_flags = (left_xz || right_xz) ? cf_xz_present : cf_none;
}
inline void
initialize(const sc_value_base &left, const sc_value_base &right)
{
bool left_xz; // True if x's and/or z's found in left.
bool right_xz; // True if x's and/or z's found in right.
m_left_p = (sc_value_base *)&left;
m_right_p = (sc_value_base *)&right;
m_len_r = right.concat_length(&right_xz);
m_len = left.concat_length(&left_xz) + m_len_r;
m_flags = (left_xz || right_xz) ? cf_xz_present : cf_none;
}
// destructor
virtual ~sc_concatref() {}
// capacity
unsigned int length() const { return m_len; }
// concatenation
virtual int
concat_length(bool *xz_present_p) const
{
if (xz_present_p)
*xz_present_p = m_flags & cf_xz_present ? true : false;
return m_len;
}
virtual void
concat_clear_data(bool to_ones)
{
m_left_p->concat_clear_data(to_ones);
m_right_p->concat_clear_data(to_ones);
}
virtual bool
concat_get_ctrl(sc_digit *dst_p, int low_i) const
{
bool rnz = m_right_p->concat_get_ctrl(dst_p, low_i);
bool lnz = m_left_p->concat_get_ctrl(dst_p, low_i + m_len_r);
return rnz || lnz;
}
virtual bool
concat_get_data(sc_digit *dst_p, int low_i) const
{
bool rnz = m_right_p->concat_get_data(dst_p, low_i);
bool lnz = m_left_p->concat_get_data(dst_p, low_i + m_len_r);
return rnz || lnz;
}
virtual uint64
concat_get_uint64() const
{
if (m_len_r >= 64) {
return m_right_p->concat_get_uint64();
} else {
return (m_left_p->concat_get_uint64() << m_len_r) |
m_right_p->concat_get_uint64();
}
}
virtual void
concat_set(int64 src, int low_i)
{
m_right_p->concat_set(src, low_i);
m_left_p->concat_set(src, low_i + m_len_r);
}
virtual void
concat_set(const sc_signed &src, int low_i)
{
m_right_p->concat_set(src, low_i);
m_left_p->concat_set(src, low_i + m_len_r);
}
virtual void
concat_set(const sc_unsigned &src, int low_i)
{
m_right_p->concat_set(src, low_i);
m_left_p->concat_set(src, low_i + m_len_r);
}
virtual void
concat_set(uint64 src, int low_i)
{
m_right_p->concat_set(src, low_i);
m_left_p->concat_set(src, low_i + m_len_r);
}
// explicit conversions
uint64
to_uint64() const
{
uint64 mask;
uint64 result;
result = m_right_p->concat_get_uint64();
if (m_len_r < 64) {
mask = (uint64)~0;
result = (m_left_p->concat_get_uint64() << m_len_r) |
(result & ~(mask << m_len_r));
}
if (m_len < 64) {
mask = (uint64)~0;
result = result & ~(mask << m_len);
}
return result;
}
const sc_unsigned &
value() const
{
bool left_non_zero;
sc_unsigned *result_p = sc_unsigned::m_pool.allocate();
bool right_non_zero;
result_p->nbits = result_p->num_bits(m_len);
result_p->ndigits = DIV_CEIL(result_p->nbits);
result_p->digit = (sc_digit *)sc_core::sc_temp_heap.allocate(
sizeof(sc_digit) * result_p->ndigits);
result_p->digit[result_p->ndigits - 1] = 0;
right_non_zero = m_right_p->concat_get_data(result_p->digit, 0);
left_non_zero = m_left_p->concat_get_data(result_p->digit, m_len_r);
if (left_non_zero || right_non_zero)
result_p->sgn = SC_POS;
else
result_p->sgn = SC_ZERO;
return *result_p;
}
int64 to_int64() const { return (int64)to_uint64(); }
int to_int() const { return (int)to_int64(); }
unsigned int to_uint() const { return (unsigned int)to_uint64(); }
long to_long() const { return (long)to_int64(); }
unsigned long to_ulong() const { return (unsigned long)to_uint64(); }
double to_double() const { return value().to_double(); }
void to_sc_signed(sc_signed &target) const { target = value(); }
void to_sc_unsigned(sc_unsigned &target) const { target = value(); }
// implicit conversions:
operator uint64 () const { return to_uint64(); }
operator const sc_unsigned & () const { return value(); }
// unary operators:
sc_unsigned operator + () const { return value(); }
sc_signed operator - () const { return -value(); }
sc_unsigned operator ~ () const { return ~value(); }
// explicit conversion to character string
const std::string
to_string(sc_numrep numrep=SC_DEC) const
{
return value().to_string(numrep);
}
const std::string
to_string(sc_numrep numrep, bool w_prefix) const
{
return value().to_string(numrep,w_prefix);
}
// assignments
inline const sc_concatref &
operator = (int v)
{
m_right_p->concat_set((int64)v, 0);
m_left_p->concat_set((int64)v, m_len_r);
return *this;
}
inline const sc_concatref &
operator = (long v)
{
m_right_p->concat_set((int64)v, 0);
m_left_p->concat_set((int64)v, m_len_r);
return *this;
}
inline const sc_concatref &
operator = (int64 v)
{
m_right_p->concat_set(v, 0);
m_left_p->concat_set(v, m_len_r);
return *this;
}
inline const sc_concatref &
operator = (unsigned int v)
{
m_right_p->concat_set((uint64)v, 0);
m_left_p->concat_set((uint64)v, m_len_r);
return *this;
}
inline const sc_concatref &
operator = (unsigned long v)
{
m_right_p->concat_set((uint64)v, 0);
m_left_p->concat_set((uint64)v, m_len_r);
return *this;
}
inline const sc_concatref &
operator = (uint64 v)
{
m_right_p->concat_set(v, 0);
m_left_p->concat_set(v, m_len_r);
return *this;
}
const sc_concatref &
operator = (const sc_concatref &v)
{
sc_unsigned temp(v.length());
temp = v.value();
m_right_p->concat_set(temp, 0);
m_left_p->concat_set(temp, m_len_r);
return *this;
}
const sc_concatref &
operator = (const sc_signed &v)
{
m_right_p->concat_set(v, 0);
m_left_p->concat_set(v, m_len_r);
return *this;
}
const sc_concatref &
operator = (const sc_unsigned &v)
{
m_right_p->concat_set(v, 0);
m_left_p->concat_set(v, m_len_r);
return *this;
}
const sc_concatref &
operator = (const char *v_p)
{
sc_unsigned v(m_len);
v = v_p;
m_right_p->concat_set(v, 0);
m_left_p->concat_set(v, m_len_r);
return *this;
}
const sc_concatref &
operator = (const sc_bv_base &v)
{
sc_unsigned temp(v.length());
temp = v;
m_right_p->concat_set(temp, 0);
m_left_p->concat_set(temp, m_len_r);
return *this;
}
const sc_concatref &
operator = (const sc_lv_base &v)
{
sc_unsigned data(v.length());
data = v;
m_right_p->concat_set(data, 0);
m_left_p->concat_set(data, m_len_r);
return *this;
}
// reduce methods
bool and_reduce() const { return value().and_reduce(); }
bool nand_reduce() const { return value().nand_reduce(); }
bool or_reduce() const { return value().or_reduce(); }
bool nor_reduce() const { return value().nor_reduce(); }
bool xor_reduce() const { return value().xor_reduce(); }
bool xnor_reduce() const { return value().xnor_reduce(); }
// other methods
void print(::std::ostream &os=::std::cout) const { os << this->value(); }
void
scan(::std::istream &is)
{
std::string s;
is >> s;
*this = s.c_str();
}
public:
// Pool of temporary objects.
static sc_core::sc_vpool<sc_concatref> m_pool;
public:
enum concat_flags {
cf_none = 0, // Normal value.
cf_xz_present = 1 // X and/or Z values present.
};
protected:
sc_value_base *m_left_p; // Left hand operand of concatenation.
sc_value_base *m_right_p; // Right hand operand of concatenation.
int m_len; // Length of concatenation.
int m_len_r; // Length of m_rightt_p.
concat_flags m_flags; // Value is read only.
private:
sc_concatref(const sc_concatref &);
sc_concatref() : m_left_p(0), m_right_p(0), m_len(0), m_len_r(0), m_flags()
{}
};
// functional notation for the reduce methods
inline bool and_reduce(const sc_concatref &a) { return a.and_reduce(); }
inline bool nand_reduce(const sc_concatref &a) { return a.nand_reduce(); }
inline bool or_reduce(const sc_concatref &a) { return a.or_reduce(); }
inline bool nor_reduce(const sc_concatref &a) { return a.nor_reduce(); }
inline bool xor_reduce(const sc_concatref &a) { return a.xor_reduce(); }
inline bool xnor_reduce(const sc_concatref &a) { return a.xnor_reduce(); }
// SHIFT OPERATORS FOR sc_concatref OBJECT INSTANCES:
//
// Because sc_concatref has implicit casts to both uint64 and sc_unsigned
// it is necessary to disambiguate the use of the shift operators. We do
// this in favor of sc_unsigned so that precision is not lost. To get an
// integer-based result use a cast to uint64 before performing the shift.
inline const sc_unsigned
operator << (const sc_concatref &target, uint64 shift)
{
return target.value() << (int)shift;
}
inline const sc_unsigned
operator << (const sc_concatref &target, int64 shift)
{
return target.value() << (int)shift;
}
inline const sc_unsigned
operator << (const sc_concatref &target, unsigned long shift)
{
return target.value() << (int)shift;
}
inline const sc_unsigned
operator << (const sc_concatref &target, int shift)
{
return target.value() << shift;
}
inline const sc_unsigned
operator << (const sc_concatref &target, unsigned int shift)
{
return target.value() << (int)shift;
}
inline const sc_unsigned
operator << (const sc_concatref &target, long shift)
{
return target.value() << (int)shift;
}
inline const sc_unsigned
operator >> (const sc_concatref &target, uint64 shift)
{
return target.value() >> (int)shift;
}
inline const sc_unsigned
operator >> (const sc_concatref &target, int64 shift)
{
return target.value() >> (int)shift;
}
inline const sc_unsigned
operator >> (const sc_concatref &target, unsigned long shift)
{
return target.value() >> (int)shift;
}
inline const sc_unsigned
operator >> (const sc_concatref &target, int shift)
{
return target.value() >> shift;
}
inline const sc_unsigned
operator >> (const sc_concatref &target, unsigned int shift)
{
return target.value() >> (int)shift;
}
inline const sc_unsigned
operator >> (const sc_concatref &target, long shift)
{
return target.value() >> (int)shift;
}
// STREAM OPERATORS FOR sc_concatref OBJECT INSTANCES:
inline ::std::ostream &
operator << (::std::ostream &os, const sc_concatref &v)
{
return os << v.value();
}
inline ::std::istream &
operator >> (::std::istream &is, sc_concatref &a)
{
sc_unsigned temp(a.concat_length(0));
temp.scan(is);
a = temp;
return is;
}
// ----------------------------------------------------------------------------
// CLASS TEMPLATE : sc_concat_bool
//
// Proxy class for read-only boolean values in concatenations.
// ----------------------------------------------------------------------------
class sc_concat_bool : public sc_value_base
{
protected:
static sc_core::sc_vpool<sc_concat_bool> m_pool; // Temporaries pool.
bool m_value; // Value for this obj.
public:
// constructor:
sc_concat_bool() : sc_value_base(), m_value() {}
// destructor:
virtual ~sc_concat_bool() { }
// allocation of temporary object:
static inline sc_concat_bool *
allocate(bool v)
{
sc_concat_bool *result_p = m_pool.allocate();
result_p->m_value = v;
return result_p;
}
// concatenation:
virtual int
concat_length(bool *xz_present_p) const
{
if (xz_present_p)
*xz_present_p = false;
return 1;
}
virtual bool
concat_get_ctrl(sc_digit *dst_p, int low_i) const
{
int bit = 1 << (low_i % BITS_PER_DIGIT);
int word_i = low_i / BITS_PER_DIGIT;
dst_p[word_i] &= ~bit;
return false;
}
virtual bool
concat_get_data(sc_digit *dst_p, int low_i) const
{
int bit = 1 << (low_i % BITS_PER_DIGIT);
int word_i = low_i / BITS_PER_DIGIT;
if (m_value)
dst_p[word_i] |= bit;
else
dst_p[word_i] &= ~bit;
return m_value;
}
virtual uint64
concat_get_uint64() const
{
return m_value ? 1 : 0;
}
};
// ----------------------------------------------------------------------------
// ARITHMETIC AND LOGIC OPERATORS FOR sc_concatref
// ----------------------------------------------------------------------------
#define SC_CONCAT_OP_TYPE(RESULT, OP, OTHER_TYPE) \
inline RESULT \
operator OP (const sc_concatref &a, OTHER_TYPE b) \
{ \
return a.value() OP b; \
} \
inline RESULT \
operator OP (OTHER_TYPE a, const sc_concatref &b) \
{ \
return a OP b.value(); \
}
#define SC_CONCAT_OP(RESULT, OP) \
inline RESULT \
operator OP (const sc_concatref &a, const sc_concatref &b) \
{ \
return a.value() OP b.value(); \
} \
SC_CONCAT_OP_TYPE(const sc_signed, OP, int) \
SC_CONCAT_OP_TYPE(const sc_signed, OP, long) \
SC_CONCAT_OP_TYPE(const sc_signed, OP, int64) \
SC_CONCAT_OP_TYPE(RESULT, OP, unsigned int) \
SC_CONCAT_OP_TYPE(RESULT, OP, unsigned long) \
SC_CONCAT_OP_TYPE(RESULT, OP, uint64) \
SC_CONCAT_OP_TYPE(const sc_signed, OP, const sc_int_base &) \
SC_CONCAT_OP_TYPE(RESULT, OP, const sc_uint_base &) \
SC_CONCAT_OP_TYPE(const sc_signed, OP, const sc_signed &) \
SC_CONCAT_OP_TYPE(RESULT, OP, const sc_unsigned &) \
inline RESULT \
operator OP (const sc_concatref &a, bool b) \
{ \
return a.value() OP (int)b; \
} \
inline RESULT \
operator OP (bool a, const sc_concatref &b) \
{ \
return (int)a OP b.value(); \
}
#define SC_CONCAT_BOOL_OP(OP) \
inline bool \
operator OP (const sc_concatref &a, const sc_concatref &b) \
{ \
return a.value() OP b.value(); \
} \
SC_CONCAT_OP_TYPE(bool, OP, int) \
SC_CONCAT_OP_TYPE(bool, OP, long) \
SC_CONCAT_OP_TYPE(bool, OP, int64) \
SC_CONCAT_OP_TYPE(bool, OP, unsigned int) \
SC_CONCAT_OP_TYPE(bool, OP, unsigned long) \
SC_CONCAT_OP_TYPE(bool, OP, uint64) \
SC_CONCAT_OP_TYPE(bool, OP, const sc_int_base &) \
SC_CONCAT_OP_TYPE(bool, OP, const sc_uint_base &) \
SC_CONCAT_OP_TYPE(bool, OP, const sc_signed &) \
SC_CONCAT_OP_TYPE(bool, OP, const sc_unsigned &) \
inline bool \
operator OP (const sc_concatref &a, bool b) \
{ \
return a.value() OP (int)b; \
} \
inline bool \
operator OP (bool a, const sc_concatref &b) \
{ \
return (int)a OP b.value(); \
}
SC_CONCAT_OP(const sc_unsigned, +)
SC_CONCAT_OP(const sc_signed, -)
SC_CONCAT_OP(const sc_unsigned, *)
SC_CONCAT_OP(const sc_unsigned, /)
SC_CONCAT_OP(const sc_unsigned, %)
SC_CONCAT_OP(const sc_unsigned, &)
SC_CONCAT_OP(const sc_unsigned, |)
SC_CONCAT_OP(const sc_unsigned, ^)
SC_CONCAT_BOOL_OP(==)
SC_CONCAT_BOOL_OP(<=)
SC_CONCAT_BOOL_OP(>=)
SC_CONCAT_BOOL_OP(!=)
SC_CONCAT_BOOL_OP(>)
SC_CONCAT_BOOL_OP(<)
#undef SC_CONCAT_OP
#undef SC_CONCAT_OP_TYPE
// ----------------------------------------------------------------------------
// CONCATENATION FUNCTION AND OPERATOR FOR STANDARD SYSTEM C DATA TYPES:
// ----------------------------------------------------------------------------
inline sc_dt::sc_concatref &
concat(sc_dt::sc_value_base &a, sc_dt::sc_value_base &b)
{
sc_dt::sc_concatref *result_p; // Proxy for the concatenation.
result_p = sc_dt::sc_concatref::m_pool.allocate();
result_p->initialize(a, b);
return *result_p;
}
inline const sc_dt::sc_concatref &
concat(const sc_dt::sc_value_base &a, const sc_dt::sc_value_base &b)
{
sc_dt::sc_concatref *result_p; // Proxy for the concatenation.
result_p = sc_dt::sc_concatref::m_pool.allocate();
result_p->initialize(a, b);
return *result_p;
}
inline const sc_dt::sc_concatref &
concat(const sc_dt::sc_value_base &a, bool b)
{
const sc_dt::sc_concat_bool *b_p; // Proxy for boolean value.
sc_dt::sc_concatref *result_p; // Proxy for the concatenation.
b_p = sc_dt::sc_concat_bool::allocate(b);
result_p = sc_dt::sc_concatref::m_pool.allocate();
result_p->initialize(a, *b_p);
return *result_p;
}
inline const sc_dt::sc_concatref &
concat(bool a, const sc_dt::sc_value_base &b)
{
const sc_dt::sc_concat_bool *a_p; // Proxy for boolean value.
sc_dt::sc_concatref *result_p; // Proxy for the concatenation.
a_p = sc_dt::sc_concat_bool::allocate(a);
result_p = sc_dt::sc_concatref::m_pool.allocate();
result_p->initialize(*a_p, b);
return *result_p;
}
inline sc_dt::sc_concatref &
operator , (sc_dt::sc_value_base &a, sc_dt::sc_value_base &b)
{
sc_dt::sc_concatref *result_p; // Proxy for the concatenation.
result_p = sc_dt::sc_concatref::m_pool.allocate();
result_p->initialize(a, b);
return *result_p;
}
inline const sc_dt::sc_concatref &
operator , (const sc_dt::sc_value_base &a, const sc_dt::sc_value_base &b)
{
sc_dt::sc_concatref *result_p; // Proxy for the concatenation.
result_p = sc_dt::sc_concatref::m_pool.allocate();
result_p->initialize(a, b);
return *result_p;
}
inline const sc_dt::sc_concatref &
operator , (const sc_dt::sc_value_base &a, bool b)
{
const sc_dt::sc_concat_bool *b_p; // Proxy for boolean value.
sc_dt::sc_concatref *result_p; // Proxy for the concatenation.
b_p = sc_dt::sc_concat_bool::allocate(b);
result_p = sc_dt::sc_concatref::m_pool.allocate();
result_p->initialize(a, *b_p);
return *result_p;
}
inline const sc_dt::sc_concatref &
operator , (bool a, const sc_dt::sc_value_base &b)
{
const sc_dt::sc_concat_bool *a_p; // Proxy for boolean value.
sc_dt::sc_concatref *result_p; // Proxy for the concatenation.
a_p = sc_dt::sc_concat_bool::allocate(a);
result_p = sc_dt::sc_concatref::m_pool.allocate();
result_p->initialize(*a_p, b);
return *result_p;
}
} // namespace sc_dt
#endif // __SYSTEMC_EXT_DT_MISC_SC_CONCATREF_HH__

View File

@@ -0,0 +1,123 @@
/*****************************************************************************
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_value_base.h -- Base class for SystemC bit values.
Original Author: Andy Goodrich, Forte Design Systems
*****************************************************************************/
/*****************************************************************************
MODIFICATION LOG - modifiers, enter your name, affiliation, date and
changes you are making here.
Name, Affiliation, Date:
Description of Modification:
*****************************************************************************/
// $Log: sc_value_base.h,v $
// Revision 1.4 2011/08/29 18:04:32 acg
// Philipp A. Hartmann: miscellaneous clean ups.
//
// Revision 1.3 2011/08/24 22:05:48 acg
// Torsten Maehne: initialization changes to remove warnings.
//
// Revision 1.2 2011/06/28 21:23:04 acg
// Andy Goodrich: merging of SCV tree.
//
// Revision 1.1.1.1 2006/12/15 20:20:05 acg
// SystemC 2.3
//
// Revision 1.3 2006/01/13 18:54:01 acg
// Andy Goodrich: added $Log command so that CVS comments are reproduced in
// the source.
//
#ifndef __SYSTEMC_EXT_DT_MISC_SC_VALUE_BASE_HH__
#define __SYSTEMC_EXT_DT_MISC_SC_VALUE_BASE_HH__
#include "../int/sc_nbdefs.hh"
namespace sc_dt
{
class sc_signed;
class sc_unsigned;
// ----------------------------------------------------------------------------
// CLASS : sc_value_base
//
// Abstract base class of all SystemC native variables. It provides
// support for concatenation operations via a set of virtual methods.
// A general description of the methods appear with their default
// definitions in sc_object.cpp.
// ----------------------------------------------------------------------------
class sc_value_base
{
friend class sc_concatref;
private:
virtual void concat_clear_data(bool to_ones=false);
virtual bool concat_get_ctrl(sc_digit *dst_p, int low_i) const;
virtual bool concat_get_data(sc_digit *dst_p, int low_i) const;
virtual uint64 concat_get_uint64() const;
virtual int concat_length(bool *xz_present_p=0) const;
virtual void concat_set(int64 src, int low_i);
virtual void concat_set(const sc_signed& src, int low_i);
virtual void concat_set(const sc_unsigned& src, int low_i);
virtual void concat_set(uint64 src, int low_i);
public:
virtual ~sc_value_base() {}
};
// ----------------------------------------------------------------------------
// CLASS : sc_generic_base
//
// Proxy class for user-defined value classes and other classes that
// are defined outside of SystemC.
// The class is utilized as a base class for the arbitrary class:
//
// class my_class : public sc_generic_base<my_class>
//
// The purpose of the class is to allow to_XXXX methods defined within that
// class so that assignments and casts from the arbitrary class to native
// SystemC types are possible. To interact correctly with the SystemC library
// the class derived from sc_generic_base must implement the following
// methods:
// (1) uint64 to_uint64() const
// (2) int64 to_int64() const
// (3) void to_sc_unsigned( sc_unsigned& ) const
// (4) void to_sc_signed( sc_signed& ) const
// ----------------------------------------------------------------------------
template< class T >
class sc_generic_base
{
public:
inline const T *operator-> () const { return (const T *)this; }
inline T *operator-> () { return (T *)this; }
};
} // namespace sc_dt
#endif // SYSTEMC_EXT_DT_MISC_SC_VALUE_BASE_HH__

View File

@@ -0,0 +1,100 @@
/*****************************************************************************
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_mempool.h - Memory pools for small objects.
Original Author: Stan Y. Liao, Synopsys, Inc.
CHANGE LOG AT END OF FILE
*****************************************************************************/
#ifndef __SYSTEMC_EXT_DT_SC_MEMPOOL_HH__
#define __SYSTEMC_EXT_DT_SC_MEMPOOL_HH__
namespace sc_core
{
// ----------------------------------------------------------------------------
// CLASS : sc_mempool
//
// ...
// ----------------------------------------------------------------------------
class sc_mempool
{
public:
static void *allocate(std::size_t sz);
static void release(void *p, std::size_t sz);
static void display_statistics();
};
// ----------------------------------------------------------------------------
// CLASS : sc_mpobject
//
// ...
// ----------------------------------------------------------------------------
class sc_mpobject
{
public:
static void *
operator new(std::size_t sz)
{
return sc_mempool::allocate(sz);
}
static void
operator delete(void *p, std::size_t sz)
{
sc_mempool::release(p, sz);
}
static void *
operator new [] (std::size_t sz)
{
return sc_mempool::allocate(sz);
}
static void
operator delete [] (void *p, std::size_t sz)
{
sc_mempool::release(p, sz);
}
};
} // namespace sc_core
// $Log: sc_mempool.h,v $
// Revision 1.3 2011/08/26 20:46:18 acg
// Andy Goodrich: moved the modification log to the end of the file to
// eliminate source line number skew when check-ins are done.
//
// Revision 1.2 2011/02/18 20:38:44 acg
// Andy Goodrich: Updated Copyright notice.
//
// Revision 1.1.1.1 2006/12/15 20:20:06 acg
// SystemC 2.3
//
// Revision 1.3 2006/01/13 18:53:11 acg
// Andy Goodrich: Added $Log command so that CVS comments are reproduced in
// the source.
#endif // __SYSTEMC_EXT_DT_SC_MEMPOOL_HH__

View File

@@ -0,0 +1,227 @@
/*****************************************************************************
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_temporary.h -- Temporary value pool classes.
Original Author: Andy Goodrich, Forte Design Systems, Inc.
CHANGE LOG AT END OF FILE
*****************************************************************************/
#ifndef __SYSTEMC_EXT_DT_SC_TEMPORARY_HH__
#define __SYSTEMC_EXT_DT_SC_TEMPORARY_HH__
#include <cstddef> // std::size_t
namespace sc_core
{
//-----------------------------------------------------------------------------
// sc_byte_heap - CLASS MANAGING A TEMPORARY HEAP OF BYTES
//
// This facility implements a heap of temporary byte allocations. Once an
// request has been allocated it is not freed. However the entire heap
// wraps and the storage is reused. This means that no allocations should
// be assumed as permanent. Allocations are double-word aligned. This is
// raw storage, so objects which contain virtual methods cannot be allocated
// with this object. See the sc_vpool object for that type of storage
// allocation.
//
// char* allocate( int size )
// This method returns a pointer to block of size bytes. The block
// returned is the next available one in the heap. If the current heap
// cannot fullfil the request it will be rewound and storage allocated from
// its start. All allocations start on an 8-byte boundary.
// size = number of bytes to be allocated.
//
// void initialize( int heap_size=0x100000 )
// This method allocates the storage to be managed. If there is already
// a block of storage under management it is freed. If no argument is
// provided for the heap size, a megabyte will be allocated.
// heap_size = number of bytes to allocate for the heap.
//
// unsigned int length()
// This method returns the size of this object's heap in bytes.
//
// sc_byte_heap()
// This is the non-initialized object instance constructor. It does not
// allocate the heap storage, that is done by the initialize() method.
//
// sc_byte_heap(int)
// This is the initializing object instance constructor. It does allocates
// a heap of the specified number of bytes.
// heap_size = number of bytes to allocate for the heap.
//-----------------------------------------------------------------------------
class sc_byte_heap
{
public:
char *m_bgn_p; // Beginning of heap storage.
char *m_end_p; // End of heap storage.
char *m_next_p; // Next heap location to be allocated.
inline char *
allocate(std::size_t bytes_n)
{
char *result_p;
bytes_n = (bytes_n + 7) & ((std::size_t)(-8));
result_p = m_next_p;
m_next_p += bytes_n;
if (m_next_p >= m_end_p) {
result_p = m_bgn_p;
m_next_p = m_bgn_p + bytes_n;
}
return result_p;
}
inline void
initialize(std::size_t heap_size=0x100000)
{
delete [] m_bgn_p;
m_bgn_p = new char[heap_size];
m_end_p = &m_bgn_p[heap_size];
m_next_p = m_bgn_p;
}
inline std::size_t
length()
{
return (std::size_t)(m_end_p - m_bgn_p);
}
inline sc_byte_heap() : m_bgn_p(0), m_end_p(0), m_next_p(0) {}
inline sc_byte_heap(std::size_t heap_size) :
m_bgn_p(0), m_end_p(0), m_next_p(0)
{
initialize(heap_size);
}
inline ~sc_byte_heap() { delete [] m_bgn_p; }
};
//-----------------------------------------------------------------------------
// sc_vpool<T> - CLASS MANAGING A TEMPORARY VECTOR OF CLASS T INSTANCES
//
// This class implements a fixed pool of objects contained in a vector. These
// objects are allocated via the allocate() method. An index, m_pool_i,
// indicates the next object to be allocated. The vector is a power of 2 in
// size, and this fact is used to wrap the list when m_pool_i reaches the
// end of the vector.
//
// sc_vpool( int log2, T* pool_p=0 )
// This is the object instance constructor for this class. It configures
// the object to manage a vector of 2**log2 entries. If a vector is
// not supplied one will be allocated.
// log2 = the log base two of the size of the vector.
// pool_p -> vector of 2**log2 entries to be managed or 0.
//
// ~sc_vpool()
// This is the object instance destructor for this class. It frees the
// block of storage which was being managed.
//
// T* allocate()
// This method returns the address of the next entry in the vector, m_pool_p,
// pointed to by the index, m_pool_i, and updates that index. The index
// update consists of adding 1 to m_pool_i and masking it by m_wrap.
//
// void reset()
// This method resets the allocation index, m_pool_i, to point to the start
// of the vector of objects under management. This call is not usually made
// since there are a fixed number of entries and the index wraps. However,
// for diagnostics tests it is convenient to be able to reset to the start
// of the vector.
//
// int size()
// This method returns the number of object instances contained in the
// vector being managed by this object instance.
//-----------------------------------------------------------------------------
template<class T>
class sc_vpool
{
protected:
std::size_t m_pool_i; // Index of next entry to m_pool_m to provide.
T *m_pool_p; // Vector of temporaries.
std::size_t m_wrap; // Mask to wrap vector index.
public:
inline sc_vpool(int log2, T *pool_p=0);
inline ~sc_vpool();
inline T *allocate();
inline void reset();
inline std::size_t size();
};
template<class T>
sc_vpool<T>::sc_vpool(int log2, T *pool_p) : m_pool_i(0),
m_pool_p(pool_p ? pool_p : new T[static_cast<std::size_t>(1) << log2]),
m_wrap(~(static_cast<std::size_t>(-1) << log2))
{
// if (log2 > 32) SC_REPORT_ERROR(SC_ID_POOL_SIZE_, "");
}
template<class T>
sc_vpool<T>::~sc_vpool()
{
// delete [] m_pool_p;
}
template<class T>
T *sc_vpool<T>::allocate()
{
T *result_p; // Entry to return.
result_p = &m_pool_p[m_pool_i];
m_pool_i = (m_pool_i + 1) & m_wrap;
return result_p;
}
template<class T>
void sc_vpool<T>::reset()
{
m_pool_i = 0;
}
template<class T>
std::size_t sc_vpool<T>::size() { return m_wrap + 1; }
} // namespace sc_core
// $Log: sc_temporary.h,v $
// Revision 1.4 2011/08/26 20:46:19 acg
// Andy Goodrich: moved the modification log to the end of the file to
// eliminate source line number skew when check-ins are done.
//
// Revision 1.3 2011/08/24 22:05:56 acg
// Torsten Maehne: initialization changes to remove warnings.
//
// Revision 1.2 2011/02/18 20:38:44 acg
// Andy Goodrich: Updated Copyright notice.
//
// Revision 1.1.1.1 2006/12/15 20:20:06 acg
// SystemC 2.3
//
// Revision 1.3 2006/01/13 18:53:11 acg
// Andy Goodrich: Added $Log command so that CVS comments are reproduced in
// the source.
//
#endif // __SYSTEMC_EXT_DT_SC_TEMPORARY_HH__