systemc: Add the Accellera implementation for the data type classes.
These files have been cleaned up style wise, and some macros have been resolved like they were for the header files. Change-Id: I447e5311961036847e7da0c5a86c0da25a633010 Reviewed-on: https://gem5-review.googlesource.com/10844 Reviewed-by: Gabe Black <gabeblack@google.com> Maintainer: Gabe Black <gabeblack@google.com>
This commit is contained in:
34
src/systemc/dt/bit/SConscript
Normal file
34
src/systemc/dt/bit/SConscript
Normal file
@@ -0,0 +1,34 @@
|
||||
# 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
|
||||
|
||||
Import('*')
|
||||
|
||||
if env['USE_SYSTEMC']:
|
||||
Source('sc_bit.cc')
|
||||
Source('sc_bv_base.cc')
|
||||
Source('sc_logic.cc')
|
||||
Source('sc_lv_base.cc')
|
||||
127
src/systemc/dt/bit/sc_bit.cc
Normal file
127
src/systemc/dt/bit/sc_bit.cc
Normal file
@@ -0,0 +1,127 @@
|
||||
/*****************************************************************************
|
||||
|
||||
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.cpp -- Bit 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_bit.cpp,v $
|
||||
// Revision 1.1.1.1 2006/12/15 20:20:04 acg
|
||||
// SystemC 2.3
|
||||
//
|
||||
// Revision 1.6 2006/04/12 20:17:52 acg
|
||||
// Andy Goodrich: enabled deprecation message for sc_bit.
|
||||
//
|
||||
// Revision 1.5 2006/01/25 00:31:15 acg
|
||||
// Andy Goodrich: Changed over to use a standard message id of
|
||||
// SC_ID_IEEE_1666_DEPRECATION for all deprecation messages.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "systemc/ext/dt/bit/sc_bit.hh"
|
||||
#include "systemc/ext/dt/bit/sc_logic.hh"
|
||||
#include "systemc/ext/utils/sc_report_handler.hh"
|
||||
|
||||
namespace sc_dt
|
||||
{
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_bit
|
||||
//
|
||||
// Bit class.
|
||||
// Note: VSIA compatibility indicated.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// support methods
|
||||
void
|
||||
sc_bit::invalid_value(char c)
|
||||
{
|
||||
std::stringstream msg;
|
||||
msg << "sc_bit('" << c << "')";
|
||||
SC_REPORT_ERROR("value is not valid", msg.str().c_str());
|
||||
sc_core::sc_abort(); // can't recover from here
|
||||
}
|
||||
|
||||
void
|
||||
sc_bit::invalid_value(int i)
|
||||
{
|
||||
std::stringstream msg;
|
||||
msg << "sc_bit(" << i << ")";
|
||||
SC_REPORT_ERROR("value is not valid", msg.str().c_str());
|
||||
sc_core::sc_abort(); // can't recover from here
|
||||
}
|
||||
|
||||
// constructors
|
||||
sc_bit::sc_bit(const sc_logic &a) : m_val(a.to_bool()) // non-VSIA
|
||||
{
|
||||
sc_deprecated_sc_bit();
|
||||
}
|
||||
|
||||
// assignment operators
|
||||
sc_bit &
|
||||
sc_bit::operator = (const sc_logic &b) // non-VSIA
|
||||
{
|
||||
return (*this = sc_bit(b));
|
||||
}
|
||||
|
||||
// other methods
|
||||
void
|
||||
sc_bit::scan(::std::istream &is)
|
||||
{
|
||||
bool b;
|
||||
is >> b;
|
||||
*this = b;
|
||||
}
|
||||
|
||||
void
|
||||
sc_deprecated_sc_bit()
|
||||
{
|
||||
static bool warn_sc_bit_deprecated = true;
|
||||
if (warn_sc_bit_deprecated) {
|
||||
warn_sc_bit_deprecated = false;
|
||||
SC_REPORT_INFO("/IEEE_Std_1666/deprecated",
|
||||
"sc_bit is deprecated, use bool instead");
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sc_dt
|
||||
231
src/systemc/dt/bit/sc_bv_base.cc
Normal file
231
src/systemc/dt/bit/sc_bv_base.cc
Normal file
@@ -0,0 +1,231 @@
|
||||
/*****************************************************************************
|
||||
|
||||
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.cpp -- 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.cpp,v $
|
||||
// Revision 1.2 2011/08/24 22:05:40 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.4 2006/04/11 23:12:26 acg
|
||||
// Andy Goodrich: Fixed bug in parsing of extended string constants like
|
||||
// 0bus1110011.
|
||||
//
|
||||
// Revision 1.3 2006/01/13 18:53:53 acg
|
||||
// Andy Goodrich: added $Log command so that CVS comments are reproduced in
|
||||
// the source.
|
||||
//
|
||||
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
|
||||
#include "systemc/ext/dt/bit/sc_bv_base.hh"
|
||||
#include "systemc/ext/dt/fx/sc_fix.hh"
|
||||
#include "systemc/ext/dt/fx/sc_ufix.hh"
|
||||
#include "systemc/ext/utils/sc_report.hh"
|
||||
|
||||
namespace sc_dt
|
||||
{
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_bv_base
|
||||
//
|
||||
// Arbitrary size bit vector base class.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void
|
||||
sc_bv_base::init(int length_, bool init_value)
|
||||
{
|
||||
// check the length
|
||||
if (length_ <= 0) {
|
||||
SC_REPORT_ERROR("zero length", 0);
|
||||
sc_core::sc_abort(); // can't recover from here
|
||||
}
|
||||
// allocate memory for the data and control words
|
||||
m_len = length_;
|
||||
m_size = (m_len - 1) / SC_DIGIT_SIZE + 1;
|
||||
m_data = new sc_digit[m_size];
|
||||
// initialize the bits to 'init_value'
|
||||
sc_digit dw = init_value ? ~SC_DIGIT_ZERO : SC_DIGIT_ZERO;
|
||||
int sz = m_size;
|
||||
for (int i = 0; i < sz; ++i) {
|
||||
m_data[i] = dw;
|
||||
}
|
||||
clean_tail();
|
||||
}
|
||||
|
||||
void
|
||||
sc_bv_base::assign_from_string(const std::string &s)
|
||||
{
|
||||
// s must have been converted to bin
|
||||
int len = m_len;
|
||||
int s_len = s.length() - 1;
|
||||
int min_len = sc_min(len, s_len);
|
||||
int i = 0;
|
||||
for (; i < min_len; ++i) {
|
||||
char c = s[s_len - i - 1];
|
||||
if (c != '0' && c != '1') {
|
||||
SC_REPORT_ERROR("cannot perform conversion",
|
||||
"string can contain only '0' and '1' characters");
|
||||
// may continue, if suppressed
|
||||
c = '0';
|
||||
}
|
||||
set_bit(i, sc_logic_value_t(c - '0'));
|
||||
}
|
||||
// if formatted, fill the rest with sign(s), otherwise fill with zeros
|
||||
sc_logic_value_t fill = (s[s_len] == 'F' ? sc_logic_value_t(s[0] - '0')
|
||||
: sc_logic_value_t(0));
|
||||
for (; i < len; ++i) {
|
||||
set_bit(i, fill);
|
||||
}
|
||||
}
|
||||
|
||||
// constructors
|
||||
sc_bv_base::sc_bv_base(const char *a) : m_len(0), m_size(0), m_data(0)
|
||||
{
|
||||
std::string s = convert_to_bin(a);
|
||||
init(s.length() - 1);
|
||||
assign_from_string(s);
|
||||
}
|
||||
|
||||
sc_bv_base::sc_bv_base(const char *a, int length_) :
|
||||
m_len(0), m_size(0), m_data(0)
|
||||
{
|
||||
init(length_);
|
||||
assign_from_string(convert_to_bin(a));
|
||||
}
|
||||
|
||||
sc_bv_base::sc_bv_base(const sc_bv_base &a) :
|
||||
sc_proxy<sc_bv_base>(), m_len(a.m_len), m_size(a.m_size),
|
||||
m_data(new sc_digit[m_size])
|
||||
{
|
||||
// copy the bits
|
||||
int sz = m_size;
|
||||
for (int i = 0; i < sz; ++i) {
|
||||
m_data[i] = a.m_data[i];
|
||||
}
|
||||
}
|
||||
|
||||
// assignment operators
|
||||
sc_bv_base &
|
||||
sc_bv_base::operator = (const char *a)
|
||||
{
|
||||
assign_from_string(convert_to_bin(a));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// convert formatted string to binary string
|
||||
|
||||
const std::string
|
||||
convert_to_bin(const char *s)
|
||||
{
|
||||
// Beware: logic character strings cannot start with '0x' or '0X',
|
||||
// because this is seen as a hexadecimal encoding prefix!
|
||||
|
||||
if (s == 0) {
|
||||
SC_REPORT_ERROR("cannot perform conversion",
|
||||
"character string is zero");
|
||||
return std::string();
|
||||
}
|
||||
if (*s == 0) {
|
||||
SC_REPORT_ERROR("cannot perform conversion",
|
||||
"character string is empty");
|
||||
return std::string();
|
||||
}
|
||||
|
||||
int n = strlen(s);
|
||||
int i = 0;
|
||||
if (s[0] == '-' || s[0] == '+') {
|
||||
++i;
|
||||
}
|
||||
if (n > (i + 2) && s[i] == '0') {
|
||||
if (s[i + 1] == 'b' || s[i + 1] == 'B') {
|
||||
if (s[i + 2] == '0' || s[i + 2] == '1') {
|
||||
std::string str(&s[2]);
|
||||
str += "F";
|
||||
return str;
|
||||
}
|
||||
}
|
||||
if (s[i + 1] == 'b' || s[i + 1] == 'B' ||
|
||||
s[i + 1] == 'c' || s[i + 1] == 'C' ||
|
||||
s[i + 1] == 'd' || s[i + 1] == 'D' ||
|
||||
s[i + 1] == 'o' || s[i + 1] == 'O' ||
|
||||
s[i + 1] == 'x' || s[i + 1] == 'X') {
|
||||
try {
|
||||
// worst case length = n * 4
|
||||
sc_fix a(s, n * 4, n * 4, SC_TRN, SC_WRAP, 0, SC_ON);
|
||||
std::string str = a.to_bin();
|
||||
str += "F"; // mark the string as formatted
|
||||
// get rid of prefix (0b) and redundant leading bits
|
||||
const char *p = str.c_str() + 2;
|
||||
while (p[1] && p[0] == p[1]) {
|
||||
++p;
|
||||
}
|
||||
return std::string(p);
|
||||
} catch (const sc_core::sc_report &) {
|
||||
std::stringstream msg;
|
||||
msg << "character string '" << s << "' is not valid";
|
||||
SC_REPORT_ERROR("cannot perform conversion",
|
||||
msg.str().c_str());
|
||||
return std::string();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// bin by default
|
||||
std::string str(s);
|
||||
str += "U"; // mark the string as unformatted
|
||||
return str;
|
||||
}
|
||||
|
||||
// convert binary string to formatted string
|
||||
const std::string
|
||||
convert_to_fmt(const std::string &s, sc_numrep numrep, bool w_prefix)
|
||||
{
|
||||
int n = s.length();
|
||||
std::string str("0bus");
|
||||
// str += "0bus";
|
||||
str += s;
|
||||
sc_ufix a(str.c_str(), n, n, SC_TRN, SC_WRAP, 0, SC_ON);
|
||||
return a.to_string(numrep, w_prefix);
|
||||
}
|
||||
|
||||
} // namespace sc_dt
|
||||
166
src/systemc/dt/bit/sc_logic.cc
Normal file
166
src/systemc/dt/bit/sc_logic.cc
Normal file
@@ -0,0 +1,166 @@
|
||||
/*****************************************************************************
|
||||
|
||||
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.cpp -- C++ implementation of logic type. Behaves
|
||||
pretty much the same way as HDLs logic type.
|
||||
|
||||
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.cpp,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.
|
||||
//
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "systemc/ext/dt/bit/sc_logic.hh"
|
||||
#include "systemc/ext/utils/sc_report_handler.hh"
|
||||
|
||||
namespace sc_dt
|
||||
{
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_logic
|
||||
//
|
||||
// Four-valued logic type.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// support methods
|
||||
void
|
||||
sc_logic::invalid_value(sc_logic_value_t v)
|
||||
{
|
||||
invalid_value((int)v);
|
||||
}
|
||||
|
||||
void
|
||||
sc_logic::invalid_value(char c)
|
||||
{
|
||||
std::stringstream msg;
|
||||
msg << "sc_logic('" << c << "')";
|
||||
SC_REPORT_ERROR("value is not valid", msg.str().c_str());
|
||||
}
|
||||
|
||||
void
|
||||
sc_logic::invalid_value(int i)
|
||||
{
|
||||
std::stringstream msg;
|
||||
msg << "sc_logic(" << i << ")";
|
||||
SC_REPORT_ERROR("value is not valid", msg.str().c_str());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
sc_logic::invalid_01() const
|
||||
{
|
||||
if ((int)m_val == Log_Z) {
|
||||
SC_REPORT_WARNING("sc_logic value 'Z' cannot be converted to bool", 0);
|
||||
} else {
|
||||
SC_REPORT_WARNING("sc_logic value 'X' cannot be converted to bool", 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// conversion tables
|
||||
const sc_logic_value_t sc_logic::char_to_logic[128] = {
|
||||
Log_0, Log_1, Log_Z, Log_X, Log_X, Log_X, Log_X, Log_X,
|
||||
Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
|
||||
Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
|
||||
Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
|
||||
Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
|
||||
Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
|
||||
Log_0, Log_1, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
|
||||
Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
|
||||
Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
|
||||
Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
|
||||
Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
|
||||
Log_X, Log_X, Log_Z, Log_X, Log_X, Log_X, Log_X, Log_X,
|
||||
Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
|
||||
Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
|
||||
Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
|
||||
Log_X, Log_X, Log_Z, Log_X, Log_X, Log_X, Log_X, Log_X
|
||||
};
|
||||
|
||||
const char sc_logic::logic_to_char[4] = { '0', '1', 'Z', 'X' };
|
||||
|
||||
const sc_logic_value_t sc_logic::and_table[4][4] = {
|
||||
{ Log_0, Log_0, Log_0, Log_0 },
|
||||
{ Log_0, Log_1, Log_X, Log_X },
|
||||
{ Log_0, Log_X, Log_X, Log_X },
|
||||
{ Log_0, Log_X, Log_X, Log_X }
|
||||
};
|
||||
|
||||
const sc_logic_value_t sc_logic::or_table[4][4] = {
|
||||
{ Log_0, Log_1, Log_X, Log_X },
|
||||
{ Log_1, Log_1, Log_1, Log_1 },
|
||||
{ Log_X, Log_1, Log_X, Log_X },
|
||||
{ Log_X, Log_1, Log_X, Log_X }
|
||||
};
|
||||
|
||||
const sc_logic_value_t sc_logic::xor_table[4][4] = {
|
||||
{ Log_0, Log_1, Log_X, Log_X },
|
||||
{ Log_1, Log_0, Log_X, Log_X },
|
||||
{ Log_X, Log_X, Log_X, Log_X },
|
||||
{ Log_X, Log_X, Log_X, Log_X }
|
||||
};
|
||||
|
||||
const sc_logic_value_t sc_logic::not_table[4] = {
|
||||
Log_1, Log_0, Log_X, Log_X
|
||||
};
|
||||
|
||||
// other methods
|
||||
void
|
||||
sc_logic::scan(::std::istream &is)
|
||||
{
|
||||
char c;
|
||||
is >> c;
|
||||
*this = c;
|
||||
}
|
||||
|
||||
// #ifdef SC_DT_DEPRECATED
|
||||
const sc_logic sc_logic_0(Log_0);
|
||||
const sc_logic sc_logic_1(Log_1);
|
||||
const sc_logic sc_logic_Z(Log_Z);
|
||||
const sc_logic sc_logic_X(Log_X);
|
||||
// #endif
|
||||
|
||||
const sc_logic SC_LOGIC_0(Log_0);
|
||||
const sc_logic SC_LOGIC_1(Log_1);
|
||||
const sc_logic SC_LOGIC_Z(Log_Z);
|
||||
const sc_logic SC_LOGIC_X(Log_X);
|
||||
|
||||
} // namespace sc_dt
|
||||
180
src/systemc/dt/bit/sc_lv_base.cc
Normal file
180
src/systemc/dt/bit/sc_lv_base.cc
Normal file
@@ -0,0 +1,180 @@
|
||||
/*****************************************************************************
|
||||
|
||||
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_base.cpp -- 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_base.cpp,v $
|
||||
// Revision 1.2 2011/08/24 22:05:40 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:53 acg
|
||||
// Andy Goodrich: added $Log command so that CVS comments are reproduced in
|
||||
// the source.
|
||||
//
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "systemc/ext/dt/bit/sc_lv_base.hh"
|
||||
|
||||
namespace sc_dt
|
||||
{
|
||||
|
||||
// explicit template instantiations
|
||||
template class sc_proxy<sc_lv_base>;
|
||||
template class sc_proxy<sc_bv_base>;
|
||||
|
||||
void
|
||||
sc_proxy_out_of_bounds(const char *msg, int64 val)
|
||||
{
|
||||
std::stringstream ss;
|
||||
if (msg != NULL)
|
||||
ss << msg;
|
||||
if (val != 0)
|
||||
ss << val;
|
||||
SC_REPORT_ERROR("out of bounds", ss.str().c_str());
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_lv_base
|
||||
//
|
||||
// Arbitrary size logic vector base class.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
static const sc_digit data_array[] = {
|
||||
SC_DIGIT_ZERO, ~SC_DIGIT_ZERO, SC_DIGIT_ZERO, ~SC_DIGIT_ZERO
|
||||
};
|
||||
|
||||
static const sc_digit ctrl_array[] = {
|
||||
SC_DIGIT_ZERO, SC_DIGIT_ZERO, ~SC_DIGIT_ZERO, ~SC_DIGIT_ZERO
|
||||
};
|
||||
|
||||
void
|
||||
sc_lv_base::init(int length_, const sc_logic& init_value)
|
||||
{
|
||||
// check the length
|
||||
if (length_ <= 0) {
|
||||
SC_REPORT_ERROR("zero length", 0);
|
||||
sc_core::sc_abort(); // can't recover from here
|
||||
}
|
||||
// allocate memory for the data and control words
|
||||
m_len = length_;
|
||||
m_size = (m_len - 1) / SC_DIGIT_SIZE + 1;
|
||||
m_data = new sc_digit[m_size * 2];
|
||||
m_ctrl = m_data + m_size;
|
||||
// initialize the bits to 'init_value'
|
||||
sc_digit dw = data_array[init_value.value()];
|
||||
sc_digit cw = ctrl_array[init_value.value()];
|
||||
int sz = m_size;
|
||||
for (int i = 0; i < sz; ++i) {
|
||||
m_data[i] = dw;
|
||||
m_ctrl[i] = cw;
|
||||
}
|
||||
clean_tail();
|
||||
}
|
||||
|
||||
void
|
||||
sc_lv_base::assign_from_string(const std::string &s)
|
||||
{
|
||||
// s must have been converted to bin
|
||||
int len = m_len;
|
||||
int s_len = s.length() - 1;
|
||||
int min_len = sc_min(len, s_len);
|
||||
int i = 0;
|
||||
for (; i < min_len; ++i) {
|
||||
char c = s[s_len - i - 1];
|
||||
set_bit(i, sc_logic::char_to_logic[(int)c]);
|
||||
}
|
||||
// if formatted, fill the rest with sign(s), otherwise fill with zeros
|
||||
sc_logic_value_t fill = (s[s_len] == 'F' ? sc_logic_value_t(s[0] - '0')
|
||||
: sc_logic_value_t(0));
|
||||
for (; i < len; ++i) {
|
||||
set_bit(i, fill);
|
||||
}
|
||||
}
|
||||
|
||||
// constructors
|
||||
sc_lv_base::sc_lv_base(const char *a) :
|
||||
m_len(0), m_size(0), m_data(0), m_ctrl(0)
|
||||
{
|
||||
std::string s = convert_to_bin(a);
|
||||
init(s.length() - 1);
|
||||
assign_from_string(s);
|
||||
}
|
||||
|
||||
sc_lv_base::sc_lv_base(const char *a, int length_) :
|
||||
m_len(0), m_size(0), m_data(0), m_ctrl(0)
|
||||
{
|
||||
init(length_);
|
||||
assign_from_string(convert_to_bin(a));
|
||||
}
|
||||
|
||||
sc_lv_base::sc_lv_base(const sc_lv_base &a) :
|
||||
sc_proxy<sc_lv_base>(), m_len(a.m_len), m_size(a.m_size),
|
||||
m_data(new sc_digit[m_size * 2]), m_ctrl(m_data + m_size)
|
||||
{
|
||||
// copy the bits
|
||||
int sz = m_size;
|
||||
for (int i = 0; i < sz; ++i) {
|
||||
m_data[i] = a.m_data[i];
|
||||
m_ctrl[i] = a.m_ctrl[i];
|
||||
}
|
||||
}
|
||||
|
||||
// assignment operators
|
||||
sc_lv_base &
|
||||
sc_lv_base::operator = (const char *a)
|
||||
{
|
||||
assign_from_string(convert_to_bin(a));
|
||||
return *this;
|
||||
}
|
||||
|
||||
// returns true if logic vector contains only 0's and 1's
|
||||
bool
|
||||
sc_lv_base::is_01() const
|
||||
{
|
||||
int sz = m_size;
|
||||
for (int i = 0; i < sz; ++i) {
|
||||
if (m_ctrl[i] != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace sc_dt
|
||||
41
src/systemc/dt/fx/SConscript
Normal file
41
src/systemc/dt/fx/SConscript
Normal file
@@ -0,0 +1,41 @@
|
||||
# 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
|
||||
|
||||
Import('*')
|
||||
|
||||
if env['USE_SYSTEMC']:
|
||||
Source('sc_fxcast_switch.cc')
|
||||
Source('sc_fxdefs.cc')
|
||||
Source('scfx_mant.cc')
|
||||
Source('sc_fxnum.cc')
|
||||
Source('sc_fxnum_observer.cc')
|
||||
Source('scfx_pow10.cc')
|
||||
Source('scfx_rep.cc')
|
||||
Source('sc_fxtype_params.cc')
|
||||
Source('scfx_utils.cc')
|
||||
Source('sc_fxval.cc')
|
||||
Source('sc_fxval_observer.cc')
|
||||
86
src/systemc/dt/fx/sc_fxcast_switch.cc
Normal file
86
src/systemc/dt/fx/sc_fxcast_switch.cc
Normal 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.
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
sc_fxcast_switch.cpp -
|
||||
|
||||
Original Author: Martin Janssen, Synopsys, Inc.
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
MODIFICATION LOG - modifiers, enter your name, affiliation, date and
|
||||
changes you are making here.
|
||||
|
||||
Name, Affiliation, Date: Gene Bushuyev, Synopsys, Inc.
|
||||
Description of Modification: - fix explicit instantiation syntax.
|
||||
|
||||
Name, Affiliation, Date:
|
||||
Description of Modification:
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
// $Log: sc_fxcast_switch.cpp,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.
|
||||
//
|
||||
|
||||
#include "systemc/ext/dt/fx/sc_fxcast_switch.hh"
|
||||
|
||||
namespace sc_dt
|
||||
{
|
||||
|
||||
template class sc_global<sc_fxcast_switch>;
|
||||
template class sc_context<sc_fxcast_switch>;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_fxcast_switch
|
||||
//
|
||||
// Fixed-point cast switch class.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
const std::string
|
||||
sc_fxcast_switch::to_string() const
|
||||
{
|
||||
return sc_dt::to_string(m_sw);
|
||||
}
|
||||
|
||||
void
|
||||
sc_fxcast_switch::print(::std::ostream &os) const
|
||||
{
|
||||
os << sc_dt::to_string(m_sw);
|
||||
}
|
||||
|
||||
void
|
||||
sc_fxcast_switch::dump(::std::ostream &os) const
|
||||
{
|
||||
os << "sc_fxcast_switch" << ::std::endl;
|
||||
os << "(" << ::std::endl;
|
||||
os << "sw = " << sc_dt::to_string(m_sw) << ::std::endl;
|
||||
os << ")" << ::std::endl;
|
||||
}
|
||||
|
||||
} // namespace sc_dt
|
||||
166
src/systemc/dt/fx/sc_fxdefs.cc
Normal file
166
src/systemc/dt/fx/sc_fxdefs.cc
Normal file
@@ -0,0 +1,166 @@
|
||||
/*****************************************************************************
|
||||
|
||||
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.cpp -
|
||||
|
||||
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.cpp,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.
|
||||
//
|
||||
|
||||
#include "systemc/ext/dt/fx/sc_fxdefs.hh"
|
||||
|
||||
namespace sc_dt
|
||||
{
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ENUM : sc_enc
|
||||
//
|
||||
// Enumeration of sign encodings.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
const std::string
|
||||
to_string(sc_enc enc)
|
||||
{
|
||||
switch (enc) {
|
||||
case SC_TC_:
|
||||
return std::string("SC_TC_");
|
||||
case SC_US_:
|
||||
return std::string("SC_US_");
|
||||
default:
|
||||
return std::string("unknown");
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ENUM : sc_q_mode
|
||||
//
|
||||
// Enumeration of quantization modes.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
const std::string
|
||||
to_string(sc_q_mode q_mode)
|
||||
{
|
||||
switch (q_mode) {
|
||||
case SC_RND:
|
||||
return std::string("SC_RND");
|
||||
case SC_RND_ZERO:
|
||||
return std::string("SC_RND_ZERO");
|
||||
case SC_RND_MIN_INF:
|
||||
return std::string("SC_RND_MIN_INF");
|
||||
case SC_RND_INF:
|
||||
return std::string("SC_RND_INF");
|
||||
case SC_RND_CONV:
|
||||
return std::string("SC_RND_CONV");
|
||||
case SC_TRN:
|
||||
return std::string("SC_TRN");
|
||||
case SC_TRN_ZERO:
|
||||
return std::string("SC_TRN_ZERO");
|
||||
default:
|
||||
return std::string("unknown");
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ENUM : sc_o_mode
|
||||
//
|
||||
// Enumeration of overflow modes.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
const std::string
|
||||
to_string(sc_o_mode o_mode)
|
||||
{
|
||||
switch (o_mode) {
|
||||
case SC_SAT:
|
||||
return std::string("SC_SAT");
|
||||
case SC_SAT_ZERO:
|
||||
return std::string("SC_SAT_ZERO");
|
||||
case SC_SAT_SYM:
|
||||
return std::string("SC_SAT_SYM");
|
||||
case SC_WRAP:
|
||||
return std::string("SC_WRAP");
|
||||
case SC_WRAP_SM:
|
||||
return std::string("SC_WRAP_SM");
|
||||
default:
|
||||
return std::string("unknown");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ENUM : sc_switch
|
||||
//
|
||||
// Enumeration of switch states.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
const std::string
|
||||
to_string(sc_switch sw)
|
||||
{
|
||||
switch (sw) {
|
||||
case SC_OFF:
|
||||
return std::string("SC_OFF");
|
||||
case SC_ON:
|
||||
return std::string("SC_ON");
|
||||
default:
|
||||
return std::string("unknown");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ENUM : sc_fmt
|
||||
//
|
||||
// Enumeration of formats for character string conversion.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
const std::string
|
||||
to_string(sc_fmt fmt)
|
||||
{
|
||||
switch (fmt) {
|
||||
case SC_F:
|
||||
return std::string("SC_F");
|
||||
case SC_E:
|
||||
return std::string("SC_E");
|
||||
default:
|
||||
return std::string("unknown");
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sc_dt
|
||||
867
src/systemc/dt/fx/sc_fxnum.cc
Normal file
867
src/systemc/dt/fx/sc_fxnum.cc
Normal file
@@ -0,0 +1,867 @@
|
||||
/*****************************************************************************
|
||||
|
||||
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.cpp -
|
||||
|
||||
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.cpp,v $
|
||||
// Revision 1.3 2011/01/19 18:57:40 acg
|
||||
// Andy Goodrich: changes for IEEE_1666_2011.
|
||||
//
|
||||
// Revision 1.2 2010/12/07 20:09:08 acg
|
||||
// Andy Goodrich: Philipp Hartmann's constructor disambiguation fix
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "systemc/ext/dt/fx/sc_fxnum.hh"
|
||||
|
||||
namespace sc_dt
|
||||
{
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_fxnum_bitref
|
||||
//
|
||||
// Proxy class for bit-selection in class sc_fxnum, behaves like sc_bit.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool sc_fxnum_bitref::get() const { return m_num.get_bit(m_idx); }
|
||||
void sc_fxnum_bitref::set(bool high) { m_num.set_bit(m_idx, high); }
|
||||
|
||||
// print or dump content
|
||||
void sc_fxnum_bitref::print(::std::ostream &os) const { os << get(); }
|
||||
|
||||
void
|
||||
sc_fxnum_bitref::scan(::std::istream &is)
|
||||
{
|
||||
bool b;
|
||||
is >> b;
|
||||
*this = b;
|
||||
}
|
||||
|
||||
void
|
||||
sc_fxnum_bitref::dump(::std::ostream &os) const
|
||||
{
|
||||
os << "sc_fxnum_bitref" << ::std::endl;
|
||||
os << "(" << ::std::endl;
|
||||
os << "num = ";
|
||||
m_num.dump(os);
|
||||
os << "idx = " << m_idx << ::std::endl;
|
||||
os << ")" << ::std::endl;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_fxnum_fast_bitref
|
||||
//
|
||||
// Proxy class for bit-selection in class sc_fxnum_fast, behaves like sc_bit.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool sc_fxnum_fast_bitref::get() const { return m_num.get_bit(m_idx); }
|
||||
void sc_fxnum_fast_bitref::set(bool high) { m_num.set_bit(m_idx, high); }
|
||||
|
||||
// print or dump content
|
||||
void sc_fxnum_fast_bitref::print(::std::ostream &os) const { os << get(); }
|
||||
|
||||
void
|
||||
sc_fxnum_fast_bitref::scan(::std::istream &is)
|
||||
{
|
||||
bool b;
|
||||
is >> b;
|
||||
*this = b;
|
||||
}
|
||||
|
||||
void
|
||||
sc_fxnum_fast_bitref::dump(::std::ostream &os) const
|
||||
{
|
||||
os << "sc_fxnum_fast_bitref" << ::std::endl;
|
||||
os << "(" << ::std::endl;
|
||||
os << "num = ";
|
||||
m_num.dump(os);
|
||||
os << "idx = " << m_idx << ::std::endl;
|
||||
os << ")" << ::std::endl;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_fxnum_subref
|
||||
//
|
||||
// Proxy class for part-selection in class sc_fxnum,
|
||||
// behaves like sc_bv_base.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool
|
||||
sc_fxnum_subref::get() const
|
||||
{
|
||||
return m_num.get_slice(m_from, m_to, m_bv);
|
||||
}
|
||||
|
||||
bool
|
||||
sc_fxnum_subref::set()
|
||||
{
|
||||
return m_num.set_slice(m_from, m_to, m_bv);
|
||||
}
|
||||
|
||||
// print or dump content
|
||||
void
|
||||
sc_fxnum_subref::print(::std::ostream &os) const
|
||||
{
|
||||
get();
|
||||
m_bv.print(os);
|
||||
}
|
||||
|
||||
void
|
||||
sc_fxnum_subref::scan(::std::istream &is)
|
||||
{
|
||||
m_bv.scan(is);
|
||||
set();
|
||||
}
|
||||
|
||||
void
|
||||
sc_fxnum_subref::dump(::std::ostream &os) const
|
||||
{
|
||||
os << "sc_fxnum_subref" << ::std::endl;
|
||||
os << "(" << ::std::endl;
|
||||
os << "num = ";
|
||||
m_num.dump(os);
|
||||
os << "from = " << m_from << ::std::endl;
|
||||
os << "to = " << m_to << ::std::endl;
|
||||
os << ")" << ::std::endl;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_fxnum_fast_subref
|
||||
//
|
||||
// Proxy class for part-selection in class sc_fxnum_fast,
|
||||
// behaves like sc_bv_base.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool
|
||||
sc_fxnum_fast_subref::get() const
|
||||
{
|
||||
return m_num.get_slice(m_from, m_to, m_bv);
|
||||
}
|
||||
|
||||
bool
|
||||
sc_fxnum_fast_subref::set()
|
||||
{
|
||||
return m_num.set_slice(m_from, m_to, m_bv);
|
||||
}
|
||||
|
||||
// print or dump content
|
||||
void
|
||||
sc_fxnum_fast_subref::print(::std::ostream &os) const
|
||||
{
|
||||
get();
|
||||
m_bv.print(os);
|
||||
}
|
||||
|
||||
void
|
||||
sc_fxnum_fast_subref::scan(::std::istream &is)
|
||||
{
|
||||
m_bv.scan(is);
|
||||
set();
|
||||
}
|
||||
|
||||
void
|
||||
sc_fxnum_fast_subref::dump(::std::ostream &os) const
|
||||
{
|
||||
os << "sc_fxnum_fast_subref" << ::std::endl;
|
||||
os << "(" << ::std::endl;
|
||||
os << "num = ";
|
||||
m_num.dump(os);
|
||||
os << "from = " << m_from << ::std::endl;
|
||||
os << "to = " << m_to << ::std::endl;
|
||||
os << ")" << ::std::endl;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_fxnum
|
||||
//
|
||||
// Base class for the fixed-point types; arbitrary precision.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// explicit conversion to character string
|
||||
|
||||
const std::string
|
||||
sc_fxnum::to_string() const
|
||||
{
|
||||
return std::string(m_rep->to_string(SC_DEC, -1, SC_F, &m_params));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxnum::to_string(sc_numrep numrep) const
|
||||
{
|
||||
return std::string(m_rep->to_string(numrep, -1, SC_F, &m_params));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxnum::to_string(sc_numrep numrep, bool w_prefix) const
|
||||
{
|
||||
return std::string(m_rep->to_string(numrep, (w_prefix ? 1 : 0),
|
||||
SC_F, &m_params));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxnum::to_string(sc_fmt fmt) const
|
||||
{
|
||||
return std::string(m_rep->to_string(SC_DEC, -1, fmt, &m_params));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxnum::to_string(sc_numrep numrep, sc_fmt fmt) const
|
||||
{
|
||||
return std::string(m_rep->to_string(numrep, -1, fmt, &m_params));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxnum::to_string(sc_numrep numrep, bool w_prefix, sc_fmt fmt) const
|
||||
{
|
||||
return std::string(m_rep->to_string(numrep, (w_prefix ? 1 : 0),
|
||||
fmt, &m_params));
|
||||
}
|
||||
|
||||
|
||||
const std::string
|
||||
sc_fxnum::to_dec() const
|
||||
{
|
||||
return std::string(m_rep->to_string(SC_DEC, -1, SC_F, &m_params));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxnum::to_bin() const
|
||||
{
|
||||
return std::string(m_rep->to_string(SC_BIN, -1, SC_F, &m_params));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxnum::to_oct() const
|
||||
{
|
||||
return std::string(m_rep->to_string(SC_OCT, -1, SC_F, &m_params));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxnum::to_hex() const
|
||||
{
|
||||
return std::string(m_rep->to_string(SC_HEX, -1, SC_F, &m_params));
|
||||
}
|
||||
|
||||
|
||||
// print or dump content
|
||||
void
|
||||
sc_fxnum::print(::std::ostream &os) const
|
||||
{
|
||||
os << m_rep->to_string(SC_DEC, -1, SC_F, &m_params);
|
||||
}
|
||||
|
||||
void
|
||||
sc_fxnum::scan(::std::istream &is)
|
||||
{
|
||||
std::string s;
|
||||
is >> s;
|
||||
*this = s.c_str();
|
||||
}
|
||||
|
||||
void
|
||||
sc_fxnum::dump(::std::ostream &os) const
|
||||
{
|
||||
os << "sc_fxnum" << ::std::endl;
|
||||
os << "(" << ::std::endl;
|
||||
os << "rep = ";
|
||||
m_rep->dump(os);
|
||||
os << "params = ";
|
||||
m_params.dump(os);
|
||||
os << "q_flag = " << m_q_flag << ::std::endl;
|
||||
os << "o_flag = " << m_o_flag << ::std::endl;
|
||||
// TO BE COMPLETED
|
||||
// os << "observer = ";
|
||||
// if (m_observer != 0)
|
||||
// m_observer->dump(os);
|
||||
// else
|
||||
// os << "0" << ::std::endl;
|
||||
os << ")" << ::std::endl;
|
||||
}
|
||||
|
||||
|
||||
sc_fxnum_observer *
|
||||
sc_fxnum::lock_observer() const
|
||||
{
|
||||
SC_ASSERT_(m_observer != 0, "lock observer failed");
|
||||
sc_fxnum_observer * tmp = m_observer;
|
||||
m_observer = 0;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void
|
||||
sc_fxnum::unlock_observer(sc_fxnum_observer *observer_) const
|
||||
{
|
||||
SC_ASSERT_(observer_ != 0, "unlock observer failed");
|
||||
m_observer = observer_;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_fxnum_fast
|
||||
//
|
||||
// Base class for the fixed-point types; limited precision.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
static void
|
||||
quantization(double &c, const scfx_params ¶ms, bool &q_flag)
|
||||
{
|
||||
int fwl = params.wl() - params.iwl();
|
||||
double scale = scfx_pow2(fwl);
|
||||
double val = scale * c;
|
||||
double int_part;
|
||||
double frac_part = modf(val, &int_part);
|
||||
|
||||
q_flag = (frac_part != 0.0);
|
||||
|
||||
if (q_flag) {
|
||||
val = int_part;
|
||||
|
||||
switch (params.q_mode()) {
|
||||
case SC_TRN: // truncation
|
||||
{
|
||||
if (c < 0.0)
|
||||
val -= 1.0;
|
||||
break;
|
||||
}
|
||||
case SC_RND: // rounding to plus infinity
|
||||
{
|
||||
if (frac_part >= 0.5)
|
||||
val += 1.0;
|
||||
else if (frac_part < -0.5)
|
||||
val -= 1.0;
|
||||
break;
|
||||
}
|
||||
case SC_TRN_ZERO: // truncation to zero
|
||||
{
|
||||
break;
|
||||
}
|
||||
case SC_RND_INF: // rounding to infinity
|
||||
{
|
||||
if (frac_part >= 0.5)
|
||||
val += 1.0;
|
||||
else if (frac_part <= -0.5)
|
||||
val -= 1.0;
|
||||
break;
|
||||
}
|
||||
case SC_RND_CONV: // convergent rounding
|
||||
{
|
||||
if (frac_part > 0.5 ||
|
||||
(frac_part == 0.5 && fmod(int_part, 2.0) != 0.0)) {
|
||||
val += 1.0;
|
||||
} else if (frac_part < -0.5 ||
|
||||
(frac_part == -0.5 && fmod(int_part, 2.0) != 0.0)) {
|
||||
val -= 1.0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SC_RND_ZERO: // rounding to zero
|
||||
{
|
||||
if (frac_part > 0.5)
|
||||
val += 1.0;
|
||||
else if (frac_part < -0.5)
|
||||
val -= 1.0;
|
||||
break;
|
||||
}
|
||||
case SC_RND_MIN_INF: // rounding to minus infinity
|
||||
{
|
||||
if (frac_part > 0.5)
|
||||
val += 1.0;
|
||||
else if (frac_part <= -0.5)
|
||||
val -= 1.0;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
val /= scale;
|
||||
c = val;
|
||||
}
|
||||
|
||||
static void
|
||||
overflow(double &c, const scfx_params ¶ms, bool &o_flag)
|
||||
{
|
||||
int iwl = params.iwl();
|
||||
int fwl = params.wl() - iwl;
|
||||
double full_circle = scfx_pow2(iwl);
|
||||
double resolution = scfx_pow2(-fwl);
|
||||
double low, high;
|
||||
if (params.enc() == SC_TC_) {
|
||||
high = full_circle / 2.0 - resolution;
|
||||
if (params.o_mode() == SC_SAT_SYM)
|
||||
low = - high;
|
||||
else
|
||||
low = - full_circle / 2.0;
|
||||
} else {
|
||||
low = 0.0;
|
||||
high = full_circle - resolution;
|
||||
}
|
||||
double val = c;
|
||||
sc_fxval_fast c2(c);
|
||||
|
||||
bool under = (val < low);
|
||||
bool over = (val > high);
|
||||
|
||||
o_flag = (under || over);
|
||||
|
||||
if (o_flag) {
|
||||
switch (params.o_mode()) {
|
||||
case SC_WRAP: // wrap-around
|
||||
{
|
||||
int n_bits = params.n_bits();
|
||||
|
||||
if (n_bits == 0) {
|
||||
// wrap-around all 'wl' bits
|
||||
val -= floor(val / full_circle) * full_circle;
|
||||
if (val > high)
|
||||
val -= full_circle;
|
||||
} else if (n_bits < params.wl()) {
|
||||
double X = scfx_pow2(iwl - n_bits);
|
||||
|
||||
// wrap-around least significant 'wl - n_bits' bits
|
||||
val -= floor(val / X) * X;
|
||||
if (val > (X - resolution))
|
||||
val -= X;
|
||||
|
||||
// saturate most significant 'n_bits' bits
|
||||
if (under) {
|
||||
val += low;
|
||||
} else {
|
||||
if (params.enc() == SC_TC_)
|
||||
val += full_circle / 2.0 - X;
|
||||
else
|
||||
val += full_circle - X;
|
||||
}
|
||||
} else {
|
||||
// saturate all 'wl' bits
|
||||
if (under)
|
||||
val = low;
|
||||
else
|
||||
val = high;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SC_SAT: // saturation
|
||||
case SC_SAT_SYM: // symmetrical saturation
|
||||
{
|
||||
if (under)
|
||||
val = low;
|
||||
else
|
||||
val = high;
|
||||
break;
|
||||
}
|
||||
case SC_SAT_ZERO: // saturation to zero
|
||||
{
|
||||
val = 0.0;
|
||||
break;
|
||||
}
|
||||
case SC_WRAP_SM: // sign magnitude wrap-around
|
||||
{
|
||||
SC_ERROR_IF_(params.enc() == SC_US_,
|
||||
"SC_WRAP_SM not defined for unsigned numbers");
|
||||
|
||||
int n_bits = params.n_bits();
|
||||
|
||||
if (n_bits == 0) {
|
||||
// invert conditionally
|
||||
if (c2.get_bit(iwl) != c2.get_bit(iwl - 1))
|
||||
val = -val - resolution;
|
||||
|
||||
// wrap-around all 'wl' bits
|
||||
val -= floor(val / full_circle) * full_circle;
|
||||
if (val > high)
|
||||
val -= full_circle;
|
||||
} else if (n_bits == 1) {
|
||||
// invert conditionally
|
||||
if (c2.is_neg() != c2.get_bit(iwl - 1))
|
||||
val = -val - resolution;
|
||||
|
||||
// wrap-around all 'wl' bits
|
||||
val -= floor(val / full_circle) * full_circle;
|
||||
if (val > high)
|
||||
val -= full_circle;
|
||||
} else if (n_bits < params.wl()) {
|
||||
// invert conditionally
|
||||
if (c2.is_neg() == c2.get_bit(iwl - n_bits))
|
||||
val = -val - resolution;
|
||||
|
||||
double X = scfx_pow2(iwl - n_bits);
|
||||
|
||||
// wrap-around least significant 'wl - n_bits' bits
|
||||
val -= floor(val / X) * X;
|
||||
if (val > (X - resolution))
|
||||
val -= X;
|
||||
|
||||
// saturate most significant 'n_bits' bits
|
||||
if (under)
|
||||
val += low;
|
||||
else
|
||||
val += full_circle / 2.0 - X;
|
||||
} else {
|
||||
// saturate all 'wl' bits
|
||||
if (under)
|
||||
val = low;
|
||||
else
|
||||
val = high;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
;
|
||||
}
|
||||
|
||||
c = val;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
sc_fxnum_fast::cast()
|
||||
{
|
||||
scfx_ieee_double id(m_val);
|
||||
SC_ERROR_IF_(id.is_nan() || id.is_inf(), "invalid fixed-point value");
|
||||
|
||||
if (m_params.cast_switch() == SC_ON) {
|
||||
m_q_flag = false;
|
||||
m_o_flag = false;
|
||||
|
||||
// check for special cases
|
||||
|
||||
if (id.is_zero()) {
|
||||
if (id.negative() != 0)
|
||||
m_val = -m_val;
|
||||
return;
|
||||
}
|
||||
|
||||
// perform casting
|
||||
sc_dt::quantization(m_val, m_params, m_q_flag);
|
||||
sc_dt::overflow(m_val, m_params, m_o_flag);
|
||||
|
||||
// check for special case: -0
|
||||
id = m_val;
|
||||
if (id.is_zero() && id.negative() != 0) {
|
||||
m_val = -m_val;
|
||||
}
|
||||
|
||||
// check for special case: NaN of Inf
|
||||
if (id.is_nan() || id.is_inf()) {
|
||||
m_val = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// defined in sc_fxval.cpp;
|
||||
extern const char* to_string(const scfx_ieee_double &, sc_numrep, int, sc_fmt,
|
||||
const scfx_params * =0);
|
||||
|
||||
|
||||
// explicit conversion to character string
|
||||
|
||||
const std::string
|
||||
sc_fxnum_fast::to_string() const
|
||||
{
|
||||
return std::string(sc_dt::to_string(m_val, SC_DEC, -1, SC_F, &m_params));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxnum_fast::to_string(sc_numrep numrep) const
|
||||
{
|
||||
return std::string(sc_dt::to_string(m_val, numrep, -1, SC_F, &m_params));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxnum_fast::to_string(sc_numrep numrep, bool w_prefix) const
|
||||
{
|
||||
return std::string(sc_dt::to_string(m_val, numrep, (w_prefix ? 1 : 0),
|
||||
SC_F, &m_params));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxnum_fast::to_string(sc_fmt fmt) const
|
||||
{
|
||||
return std::string(sc_dt::to_string(m_val, SC_DEC, -1, fmt, &m_params));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxnum_fast::to_string(sc_numrep numrep, sc_fmt fmt) const
|
||||
{
|
||||
return std::string(sc_dt::to_string(m_val, numrep, -1, fmt, &m_params));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxnum_fast::to_string(sc_numrep numrep, bool w_prefix, sc_fmt fmt) const
|
||||
{
|
||||
return std::string(sc_dt::to_string(m_val, numrep, (w_prefix ? 1 : 0),
|
||||
fmt, &m_params));
|
||||
}
|
||||
|
||||
|
||||
const std::string
|
||||
sc_fxnum_fast::to_dec() const
|
||||
{
|
||||
return std::string(sc_dt::to_string(m_val, SC_DEC, -1, SC_F, &m_params));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxnum_fast::to_bin() const
|
||||
{
|
||||
return std::string(sc_dt::to_string(m_val, SC_BIN, -1, SC_F, &m_params));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxnum_fast::to_oct() const
|
||||
{
|
||||
return std::string(sc_dt::to_string(m_val, SC_OCT, -1, SC_F, &m_params));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxnum_fast::to_hex() const
|
||||
{
|
||||
return std::string(sc_dt::to_string(m_val, SC_HEX, -1, SC_F, &m_params));
|
||||
}
|
||||
|
||||
// print or dump content
|
||||
void
|
||||
sc_fxnum_fast::print(::std::ostream &os) const
|
||||
{
|
||||
os << sc_dt::to_string(m_val, SC_DEC, -1, SC_F, &m_params);
|
||||
}
|
||||
|
||||
void
|
||||
sc_fxnum_fast::scan(::std::istream &is)
|
||||
{
|
||||
std::string s;
|
||||
is >> s;
|
||||
*this = s.c_str();
|
||||
}
|
||||
|
||||
void
|
||||
sc_fxnum_fast::dump(::std::ostream &os) const
|
||||
{
|
||||
os << "sc_fxnum_fast" << ::std::endl;
|
||||
os << "(" << ::std::endl;
|
||||
os << "val = " << m_val << ::std::endl;
|
||||
os << "params = ";
|
||||
m_params.dump(os);
|
||||
os << "q_flag = " << m_q_flag << ::std::endl;
|
||||
os << "o_flag = " << m_o_flag << ::std::endl;
|
||||
// TO BE COMPLETED
|
||||
// os << "observer = ";
|
||||
// if (m_observer != 0)
|
||||
// m_observer->dump(os);
|
||||
// else
|
||||
// os << "0" << ::std::endl;
|
||||
os << ")" << ::std::endl;
|
||||
}
|
||||
|
||||
// internal use only;
|
||||
bool
|
||||
sc_fxnum_fast::get_bit(int i) const
|
||||
{
|
||||
scfx_ieee_double id(m_val);
|
||||
if (id.is_zero() || id.is_nan() || id.is_inf())
|
||||
return false;
|
||||
|
||||
// convert to two's complement
|
||||
unsigned int m0 = id.mantissa0();
|
||||
unsigned int m1 = id.mantissa1();
|
||||
|
||||
if (id.is_normal())
|
||||
m0 += 1U << 20;
|
||||
|
||||
if (id.negative() != 0) {
|
||||
m0 = ~ m0;
|
||||
m1 = ~ m1;
|
||||
unsigned int tmp = m1;
|
||||
m1 += 1U;
|
||||
if (m1 <= tmp)
|
||||
m0 += 1U;
|
||||
}
|
||||
|
||||
// get the right bit
|
||||
int j = i - id.exponent();
|
||||
if ((j += 20) >= 32)
|
||||
return ((m0 & 1U << 31) != 0);
|
||||
else if (j >= 0)
|
||||
return ((m0 & 1U << j) != 0);
|
||||
else if ((j += 32) >= 0)
|
||||
return ((m1 & 1U << j) != 0);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
sc_fxnum_fast::set_bit(int i, bool high)
|
||||
{
|
||||
scfx_ieee_double id(m_val);
|
||||
if (id.is_nan() || id.is_inf())
|
||||
return false;
|
||||
|
||||
if (high) {
|
||||
if (get_bit(i))
|
||||
return true;
|
||||
|
||||
if (m_params.enc() == SC_TC_ && i == m_params.iwl() - 1)
|
||||
m_val -= scfx_pow2(i);
|
||||
else
|
||||
m_val += scfx_pow2(i);
|
||||
} else {
|
||||
if (!get_bit(i))
|
||||
return true;
|
||||
|
||||
if (m_params.enc() == SC_TC_ && i == m_params.iwl() - 1)
|
||||
m_val += scfx_pow2(i);
|
||||
else
|
||||
m_val -= scfx_pow2(i);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
sc_fxnum_fast::get_slice(int i, int j, sc_bv_base &bv) const
|
||||
{
|
||||
scfx_ieee_double id(m_val);
|
||||
if (id.is_nan() || id.is_inf())
|
||||
return false;
|
||||
|
||||
// convert to two's complement
|
||||
unsigned int m0 = id.mantissa0();
|
||||
unsigned int m1 = id.mantissa1();
|
||||
|
||||
if (id.is_normal())
|
||||
m0 += 1U << 20;
|
||||
|
||||
if (id.negative() != 0) {
|
||||
m0 = ~ m0;
|
||||
m1 = ~ m1;
|
||||
unsigned int tmp = m1;
|
||||
m1 += 1U;
|
||||
if (m1 <= tmp)
|
||||
m0 += 1U;
|
||||
}
|
||||
|
||||
// get the bits
|
||||
int l = j;
|
||||
for (int k = 0; k < bv.length(); ++ k) {
|
||||
bool b = false;
|
||||
|
||||
int n = l - id.exponent();
|
||||
if ((n += 20) >= 32)
|
||||
b = ((m0 & 1U << 31) != 0);
|
||||
else if (n >= 0)
|
||||
b = ((m0 & 1U << n) != 0);
|
||||
else if ((n += 32) >= 0)
|
||||
b = ((m1 & 1U << n) != 0);
|
||||
|
||||
bv[k] = b;
|
||||
|
||||
if (i >= j)
|
||||
++l;
|
||||
else
|
||||
--l;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
sc_fxnum_fast::set_slice(int i, int j, const sc_bv_base &bv)
|
||||
{
|
||||
scfx_ieee_double id(m_val);
|
||||
if (id.is_nan() || id.is_inf())
|
||||
return false;
|
||||
|
||||
// set the bits
|
||||
int l = j;
|
||||
for (int k = 0; k < bv.length(); ++k) {
|
||||
if (bv[k].to_bool()) {
|
||||
if (!get_bit(l)) {
|
||||
if (m_params.enc() == SC_TC_ && l == m_params.iwl() - 1)
|
||||
m_val -= scfx_pow2(l);
|
||||
else
|
||||
m_val += scfx_pow2(l);
|
||||
}
|
||||
} else {
|
||||
if (get_bit(l)) {
|
||||
if (m_params.enc() == SC_TC_ && l == m_params.iwl() - 1)
|
||||
m_val += scfx_pow2(l);
|
||||
else
|
||||
m_val -= scfx_pow2(l);
|
||||
}
|
||||
}
|
||||
|
||||
if (i >= j)
|
||||
++l;
|
||||
else
|
||||
--l;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
sc_fxnum_fast_observer *
|
||||
sc_fxnum_fast::lock_observer() const
|
||||
{
|
||||
SC_ASSERT_(m_observer != 0, "lock observer failed");
|
||||
sc_fxnum_fast_observer *tmp = m_observer;
|
||||
m_observer = 0;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void
|
||||
sc_fxnum_fast::unlock_observer(sc_fxnum_fast_observer *observer_) const
|
||||
{
|
||||
SC_ASSERT_(observer_ != 0, "unlock observer failed");
|
||||
m_observer = observer_;
|
||||
}
|
||||
|
||||
} // namespace sc_dt
|
||||
70
src/systemc/dt/fx/sc_fxnum_observer.cc
Normal file
70
src/systemc/dt/fx/sc_fxnum_observer.cc
Normal file
@@ -0,0 +1,70 @@
|
||||
/*****************************************************************************
|
||||
|
||||
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.cpp -
|
||||
|
||||
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.cpp,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.
|
||||
//
|
||||
|
||||
#include "systemc/ext/dt/fx/sc_fxnum_observer.hh"
|
||||
|
||||
namespace sc_dt
|
||||
{
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_fxnum_observer
|
||||
//
|
||||
// Abstract base class for fixed-point types observers; arbitrary precision.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
sc_fxnum_observer *(* sc_fxnum_observer::default_observer) () = 0;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_fxnum_fast_observer
|
||||
//
|
||||
// Abstract base class for fixed-point types observers; limited precision.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
sc_fxnum_fast_observer *(* sc_fxnum_fast_observer::default_observer) () = 0;
|
||||
|
||||
} // namespace sc_dt
|
||||
97
src/systemc/dt/fx/sc_fxtype_params.cc
Normal file
97
src/systemc/dt/fx/sc_fxtype_params.cc
Normal file
@@ -0,0 +1,97 @@
|
||||
/*****************************************************************************
|
||||
|
||||
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.cpp -
|
||||
|
||||
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.cpp,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.
|
||||
//
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "systemc/ext/dt/fx/sc_fxtype_params.hh"
|
||||
|
||||
namespace sc_dt
|
||||
{
|
||||
|
||||
template class sc_global<sc_fxtype_params>;
|
||||
template class sc_context<sc_fxtype_params>;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_fxtype_params
|
||||
//
|
||||
// Fixed-point type parameters class.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
const std::string
|
||||
sc_fxtype_params::to_string() const
|
||||
{
|
||||
std::stringstream ss;
|
||||
print(ss);
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void
|
||||
sc_fxtype_params::print(::std::ostream &os) const
|
||||
{
|
||||
os << "("
|
||||
<< m_wl << ","
|
||||
<< m_iwl << ","
|
||||
<< m_q_mode << ","
|
||||
<< m_o_mode << ","
|
||||
<< m_n_bits
|
||||
<< ")";
|
||||
}
|
||||
|
||||
void
|
||||
sc_fxtype_params::dump(::std::ostream &os) const
|
||||
{
|
||||
os << "sc_fxtype_params" << ::std::endl;
|
||||
os << "(" << ::std::endl;
|
||||
os << "wl = " << m_wl << ::std::endl;
|
||||
os << "iwl = " << m_iwl << ::std::endl;
|
||||
os << "q_mode = " << m_q_mode << ::std::endl;
|
||||
os << "o_mode = " << m_o_mode << ::std::endl;
|
||||
os << "n_bits = " << m_n_bits << ::std::endl;
|
||||
os << ")" << ::std::endl;
|
||||
}
|
||||
|
||||
} // namespace sc_dt
|
||||
810
src/systemc/dt/fx/sc_fxval.cc
Normal file
810
src/systemc/dt/fx/sc_fxval.cc
Normal file
@@ -0,0 +1,810 @@
|
||||
/*****************************************************************************
|
||||
|
||||
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.cpp -
|
||||
|
||||
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.cpp,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.
|
||||
//
|
||||
|
||||
#include <cctype>
|
||||
#include <cfloat>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "systemc/ext/dt/fx/sc_fxval.hh"
|
||||
|
||||
namespace sc_dt
|
||||
{
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_fxval
|
||||
//
|
||||
// Fixed-point value type; arbitrary precision.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// explicit conversion to character string
|
||||
|
||||
const std::string
|
||||
sc_fxval::to_string() const
|
||||
{
|
||||
return std::string(m_rep->to_string(SC_DEC, -1, SC_E));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxval::to_string(sc_numrep numrep) const
|
||||
{
|
||||
return std::string(m_rep->to_string(numrep, -1, SC_E));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxval::to_string(sc_numrep numrep, bool w_prefix) const
|
||||
{
|
||||
return std::string(m_rep->to_string(numrep, (w_prefix ? 1 : 0), SC_E));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxval::to_string(sc_fmt fmt) const
|
||||
{
|
||||
return std::string(m_rep->to_string(SC_DEC, -1, fmt));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxval::to_string(sc_numrep numrep, sc_fmt fmt) const
|
||||
{
|
||||
return std::string(m_rep->to_string(numrep, -1, fmt));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxval::to_string(sc_numrep numrep, bool w_prefix, sc_fmt fmt) const
|
||||
{
|
||||
return std::string(m_rep->to_string(numrep, (w_prefix ? 1 : 0), fmt));
|
||||
}
|
||||
|
||||
|
||||
const std::string
|
||||
sc_fxval::to_dec() const
|
||||
{
|
||||
return std::string(m_rep->to_string(SC_DEC, -1, SC_E));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxval::to_bin() const
|
||||
{
|
||||
return std::string(m_rep->to_string(SC_BIN, -1, SC_E));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxval::to_oct() const
|
||||
{
|
||||
return std::string(m_rep->to_string(SC_OCT, -1, SC_E));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxval::to_hex() const
|
||||
{
|
||||
return std::string(m_rep->to_string(SC_HEX, -1, SC_E));
|
||||
}
|
||||
|
||||
|
||||
// print or dump content
|
||||
|
||||
void sc_fxval::print(::std::ostream &os) const { m_rep->print(os); }
|
||||
|
||||
void
|
||||
sc_fxval::scan(::std::istream &is)
|
||||
{
|
||||
std::string s;
|
||||
is >> s;
|
||||
*this = s.c_str();
|
||||
}
|
||||
|
||||
void
|
||||
sc_fxval::dump(::std::ostream &os) const
|
||||
{
|
||||
os << "sc_fxval" << ::std::endl;
|
||||
os << "(" << ::std::endl;
|
||||
os << "rep = ";
|
||||
m_rep->dump(os);
|
||||
// TO BE COMPLETED
|
||||
// os << "r_flag = " << m_r_flag << ::std::endl;
|
||||
// os << "observer = ";
|
||||
// if (m_observer != 0)
|
||||
// m_observer->dump(os);
|
||||
// else
|
||||
// os << "0" << ::std::endl;
|
||||
os << ")" << ::std::endl;
|
||||
}
|
||||
|
||||
// protected methods and friend functions
|
||||
sc_fxval_observer *
|
||||
sc_fxval::lock_observer() const
|
||||
{
|
||||
SC_ASSERT_(m_observer != 0, "lock observer failed");
|
||||
sc_fxval_observer *tmp = m_observer;
|
||||
m_observer = 0;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void
|
||||
sc_fxval::unlock_observer(sc_fxval_observer *observer_) const
|
||||
{
|
||||
SC_ASSERT_(observer_ != 0, "unlock observer failed");
|
||||
m_observer = observer_;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_fxval_fast
|
||||
//
|
||||
// Fixed-point value types; limited precision.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
static void
|
||||
print_dec(scfx_string &s, scfx_ieee_double id, int w_prefix, sc_fmt fmt)
|
||||
{
|
||||
if (id.negative() != 0) {
|
||||
id.negative(0);
|
||||
s += '-';
|
||||
}
|
||||
|
||||
if (w_prefix == 1) {
|
||||
scfx_print_prefix(s, SC_DEC);
|
||||
}
|
||||
|
||||
if (id.is_zero()) {
|
||||
s += '0';
|
||||
return;
|
||||
}
|
||||
|
||||
// split 'id' into its integer and fractional part
|
||||
double int_part;
|
||||
double frac_part = std::modf(static_cast<double>(id), &int_part);
|
||||
|
||||
int i;
|
||||
|
||||
// print integer part
|
||||
int int_digits = 0;
|
||||
int int_zeros = 0;
|
||||
|
||||
if (int_part != 0.0) {
|
||||
int_digits = (int)std::ceil(std::log10(int_part + 1.0));
|
||||
|
||||
int len = s.length();
|
||||
s.append(int_digits);
|
||||
|
||||
bool zero_digits = (frac_part == 0.0 && fmt != SC_F);
|
||||
|
||||
for (i = int_digits + len - 1; i >= len; i--) {
|
||||
unsigned int remainder = (unsigned int)std::fmod(int_part, 10.0);
|
||||
s[i] = static_cast<char>('0' + remainder);
|
||||
|
||||
if (zero_digits) {
|
||||
if (remainder == 0)
|
||||
int_zeros++;
|
||||
else
|
||||
zero_digits = false;
|
||||
}
|
||||
|
||||
int_part /= 10.0;
|
||||
}
|
||||
|
||||
// discard trailing zeros from int_part
|
||||
s.discard(int_zeros);
|
||||
|
||||
if (s[len] == '0') {
|
||||
// int_digits was overestimated by one
|
||||
s.remove(len);
|
||||
--int_digits;
|
||||
}
|
||||
}
|
||||
|
||||
// print fractional part
|
||||
int frac_digits = 0;
|
||||
int frac_zeros = 0;
|
||||
|
||||
if (frac_part != 0.0) {
|
||||
s += '.';
|
||||
|
||||
bool zero_digits = (int_digits == 0 && fmt != SC_F);
|
||||
|
||||
frac_zeros = (int)std::floor(-std::log10(frac_part + DBL_EPSILON));
|
||||
|
||||
frac_part *= std::pow(10.0, frac_zeros);
|
||||
|
||||
frac_digits = frac_zeros;
|
||||
if (!zero_digits) {
|
||||
for (i = 0; i < frac_zeros; i++)
|
||||
s += '0';
|
||||
frac_zeros = 0;
|
||||
}
|
||||
|
||||
while (frac_part != 0.0) {
|
||||
frac_part *= 10.0;
|
||||
int n = static_cast<int>(frac_part);
|
||||
|
||||
if (zero_digits) {
|
||||
if (n == 0)
|
||||
frac_zeros++;
|
||||
else
|
||||
zero_digits = false;
|
||||
}
|
||||
|
||||
if (!zero_digits)
|
||||
s += static_cast<char>('0' + n);
|
||||
|
||||
frac_part -= n;
|
||||
frac_digits++;
|
||||
}
|
||||
}
|
||||
|
||||
// print exponent
|
||||
if (fmt != SC_F) {
|
||||
if (frac_digits == 0)
|
||||
scfx_print_exp(s, int_zeros);
|
||||
else if (int_digits == 0)
|
||||
scfx_print_exp(s, -frac_zeros);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
print_other(scfx_string &s, const scfx_ieee_double &id, sc_numrep numrep,
|
||||
int w_prefix, sc_fmt fmt, const scfx_params *params)
|
||||
{
|
||||
scfx_ieee_double id2 = id;
|
||||
|
||||
sc_numrep numrep2 = numrep;
|
||||
|
||||
bool numrep_is_sm = (numrep == SC_BIN_SM ||
|
||||
numrep == SC_OCT_SM ||
|
||||
numrep == SC_HEX_SM);
|
||||
|
||||
if (numrep_is_sm) {
|
||||
if (id2.negative() != 0) {
|
||||
s += '-';
|
||||
id2.negative(0);
|
||||
}
|
||||
switch (numrep) {
|
||||
case SC_BIN_SM:
|
||||
numrep2 = SC_BIN_US;
|
||||
break;
|
||||
case SC_OCT_SM:
|
||||
numrep2 = SC_OCT_US;
|
||||
break;
|
||||
case SC_HEX_SM:
|
||||
numrep2 = SC_HEX_US;
|
||||
break;
|
||||
default:
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
if (w_prefix != 0) {
|
||||
scfx_print_prefix(s, numrep);
|
||||
}
|
||||
|
||||
numrep = numrep2;
|
||||
|
||||
sc_fxval_fast a(id2);
|
||||
|
||||
int msb, lsb;
|
||||
|
||||
if (params != 0) {
|
||||
msb = params->iwl() - 1;
|
||||
lsb = params->iwl() - params->wl();
|
||||
|
||||
if (params->enc() == SC_TC_ &&
|
||||
(numrep == SC_BIN_US ||
|
||||
numrep == SC_OCT_US ||
|
||||
numrep == SC_HEX_US) &&
|
||||
!numrep_is_sm &&
|
||||
params->wl() > 1) {
|
||||
--msb;
|
||||
} else if (params->enc() == SC_US_ &&
|
||||
(numrep == SC_BIN ||
|
||||
numrep == SC_OCT ||
|
||||
numrep == SC_HEX ||
|
||||
numrep == SC_CSD)) {
|
||||
++msb;
|
||||
}
|
||||
} else {
|
||||
if (a.is_zero()) {
|
||||
msb = 0;
|
||||
lsb = 0;
|
||||
} else {
|
||||
msb = id2.exponent() + 1;
|
||||
while (a.get_bit(msb) == a.get_bit(msb - 1))
|
||||
--msb;
|
||||
|
||||
if (numrep == SC_BIN_US ||
|
||||
numrep == SC_OCT_US ||
|
||||
numrep == SC_HEX_US) {
|
||||
--msb;
|
||||
}
|
||||
|
||||
lsb = id2.exponent() - 52;
|
||||
while (!a.get_bit(lsb))
|
||||
++lsb;
|
||||
}
|
||||
}
|
||||
|
||||
int step;
|
||||
|
||||
switch (numrep) {
|
||||
case SC_BIN:
|
||||
case SC_BIN_US:
|
||||
case SC_CSD:
|
||||
step = 1;
|
||||
break;
|
||||
case SC_OCT:
|
||||
case SC_OCT_US:
|
||||
step = 3;
|
||||
break;
|
||||
case SC_HEX:
|
||||
case SC_HEX_US:
|
||||
step = 4;
|
||||
break;
|
||||
default:
|
||||
SC_REPORT_FATAL("assertion failed", "unexpected sc_numrep");
|
||||
sc_core::sc_abort();
|
||||
}
|
||||
|
||||
msb = (int)std::ceil(double(msb + 1) / step) * step - 1;
|
||||
|
||||
lsb = (int)std::floor(double(lsb) / step) * step;
|
||||
|
||||
if (msb < 0) {
|
||||
s += '.';
|
||||
if (fmt == SC_F) {
|
||||
int sign = (id2.negative() != 0) ? (1 << step) - 1 : 0;
|
||||
for (int i = (msb + 1) / step; i < 0; i++) {
|
||||
if (sign < 10)
|
||||
s += static_cast<char>(sign + '0');
|
||||
else
|
||||
s += static_cast<char>(sign + 'a' - 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int i = msb;
|
||||
while (i >= lsb) {
|
||||
int value = 0;
|
||||
for (int j = step - 1; j >= 0; --j) {
|
||||
value += static_cast<int>(a.get_bit(i)) << j;
|
||||
--i;
|
||||
}
|
||||
if (value < 10)
|
||||
s += static_cast<char>(value + '0');
|
||||
else
|
||||
s += static_cast<char>(value + 'a' - 10);
|
||||
if (i == -1)
|
||||
s += '.';
|
||||
}
|
||||
|
||||
if (lsb > 0 && fmt == SC_F) {
|
||||
for (int i = lsb / step; i > 0; i--)
|
||||
s += '0';
|
||||
}
|
||||
|
||||
if (s[s.length() - 1] == '.')
|
||||
s.discard(1);
|
||||
|
||||
if (fmt != SC_F) {
|
||||
if (msb < 0)
|
||||
scfx_print_exp(s, (msb + 1) / step);
|
||||
else if (lsb > 0)
|
||||
scfx_print_exp(s, lsb / step);
|
||||
}
|
||||
|
||||
if (numrep == SC_CSD)
|
||||
scfx_tc2csd(s, w_prefix);
|
||||
}
|
||||
|
||||
const char *
|
||||
to_string(const scfx_ieee_double &id, sc_numrep numrep, int w_prefix,
|
||||
sc_fmt fmt, const scfx_params *params=0)
|
||||
{
|
||||
static scfx_string s;
|
||||
|
||||
s.clear();
|
||||
|
||||
if (id.is_nan()) {
|
||||
scfx_print_nan(s);
|
||||
} else if (id.is_inf()) {
|
||||
scfx_print_inf(s, static_cast<bool>(id.negative()));
|
||||
} else if (id.negative() && !id.is_zero() &&
|
||||
(numrep == SC_BIN_US ||
|
||||
numrep == SC_OCT_US ||
|
||||
numrep == SC_HEX_US)) {
|
||||
s += "negative";
|
||||
} else if (numrep == SC_DEC) {
|
||||
sc_dt::print_dec(s, id, w_prefix, fmt);
|
||||
} else {
|
||||
sc_dt::print_other(s, id, numrep, w_prefix, fmt, params);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
// explicit conversion to character string
|
||||
const std::string
|
||||
sc_fxval_fast::to_string() const
|
||||
{
|
||||
return std::string(sc_dt::to_string(m_val, SC_DEC, -1, SC_E));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxval_fast::to_string(sc_numrep numrep) const
|
||||
{
|
||||
return std::string(sc_dt::to_string(m_val, numrep, -1, SC_E));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxval_fast::to_string(sc_numrep numrep, bool w_prefix) const
|
||||
{
|
||||
return std::string(sc_dt::to_string(m_val, numrep, (w_prefix ? 1 : 0),
|
||||
SC_E));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxval_fast::to_string(sc_fmt fmt) const
|
||||
{
|
||||
return std::string(sc_dt::to_string(m_val, SC_DEC, -1, fmt));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxval_fast::to_string(sc_numrep numrep, sc_fmt fmt) const
|
||||
{
|
||||
return std::string(sc_dt::to_string(m_val, numrep, -1, fmt));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxval_fast::to_string(sc_numrep numrep, bool w_prefix, sc_fmt fmt) const
|
||||
{
|
||||
return std::string(sc_dt::to_string(m_val, numrep, (w_prefix ? 1 : 0),
|
||||
fmt));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxval_fast::to_dec() const
|
||||
{
|
||||
return std::string(sc_dt::to_string(m_val, SC_DEC, -1, SC_E));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxval_fast::to_bin() const
|
||||
{
|
||||
return std::string(sc_dt::to_string(m_val, SC_BIN, -1, SC_E));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxval_fast::to_oct() const
|
||||
{
|
||||
return std::string(sc_dt::to_string(m_val, SC_OCT, -1, SC_E));
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_fxval_fast::to_hex() const
|
||||
{
|
||||
return std::string(sc_dt::to_string(m_val, SC_HEX, -1, SC_E));
|
||||
}
|
||||
|
||||
|
||||
// print or dump content
|
||||
|
||||
void
|
||||
sc_fxval_fast::print(::std::ostream &os) const
|
||||
{
|
||||
os << sc_dt::to_string(m_val, SC_DEC, -1, SC_E);
|
||||
}
|
||||
|
||||
void
|
||||
sc_fxval_fast::scan(::std::istream &is)
|
||||
{
|
||||
std::string s;
|
||||
is >> s;
|
||||
*this = s.c_str();
|
||||
}
|
||||
|
||||
void
|
||||
sc_fxval_fast::dump(::std::ostream &os) const
|
||||
{
|
||||
os << "sc_fxval_fast" << ::std::endl;
|
||||
os << "(" << ::std::endl;
|
||||
os << "val = " << m_val << ::std::endl;
|
||||
// TO BE COMPLETED
|
||||
// os << "r_flag = " << m_r_flag << ::std::endl;
|
||||
// os << "observer = ";
|
||||
// if (m_observer != 0)
|
||||
// m_observer->dump(os);
|
||||
// else
|
||||
// os << "0" << ::std::endl;
|
||||
os << ")" << ::std::endl;
|
||||
}
|
||||
|
||||
|
||||
// internal use only;
|
||||
bool
|
||||
sc_fxval_fast::get_bit(int i) const
|
||||
{
|
||||
scfx_ieee_double id(m_val);
|
||||
if (id.is_zero() || id.is_nan() || id.is_inf())
|
||||
return false;
|
||||
|
||||
// convert to two's complement
|
||||
unsigned int m0 = id.mantissa0();
|
||||
unsigned int m1 = id.mantissa1();
|
||||
|
||||
if (id.is_normal())
|
||||
m0 += 1U << 20;
|
||||
|
||||
if (id.negative() != 0) {
|
||||
m0 = ~ m0;
|
||||
m1 = ~ m1;
|
||||
unsigned int tmp = m1;
|
||||
m1 += 1U;
|
||||
if (m1 <= tmp)
|
||||
m0 += 1U;
|
||||
}
|
||||
|
||||
// get the right bit
|
||||
int j = i - id.exponent();
|
||||
if ((j += 20) >= 32)
|
||||
return ((m0 & 1U << 31) != 0);
|
||||
else if (j >= 0)
|
||||
return ((m0 & 1U << j) != 0);
|
||||
else if ((j += 32) >= 0)
|
||||
return ((m1 & 1U << j) != 0);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// protected methods and friend functions
|
||||
sc_fxval_fast_observer *
|
||||
sc_fxval_fast::lock_observer() const
|
||||
{
|
||||
SC_ASSERT_(m_observer != 0, "lock observer failed");
|
||||
sc_fxval_fast_observer *tmp = m_observer;
|
||||
m_observer = 0;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void
|
||||
sc_fxval_fast::unlock_observer(sc_fxval_fast_observer *observer_) const
|
||||
{
|
||||
SC_ASSERT_(observer_ != 0, "unlock observer failed");
|
||||
m_observer = observer_;
|
||||
}
|
||||
|
||||
#define SCFX_FAIL_IF_(cnd) \
|
||||
{ \
|
||||
if ((cnd)) \
|
||||
return static_cast<double>(scfx_ieee_double::nan()); \
|
||||
}
|
||||
|
||||
double
|
||||
sc_fxval_fast::from_string(const char *s)
|
||||
{
|
||||
SCFX_FAIL_IF_(s == 0 || *s == 0);
|
||||
|
||||
scfx_string s2;
|
||||
s2 += s;
|
||||
s2 += '\0';
|
||||
|
||||
bool sign_char;
|
||||
int sign = scfx_parse_sign(s, sign_char);
|
||||
|
||||
sc_numrep numrep = scfx_parse_prefix(s);
|
||||
|
||||
int base = 0;
|
||||
|
||||
switch (numrep) {
|
||||
case SC_DEC:
|
||||
{
|
||||
base = 10;
|
||||
if (scfx_is_nan(s)) // special case: NaN
|
||||
return static_cast<double>(scfx_ieee_double::nan());
|
||||
if (scfx_is_inf(s)) // special case: Infinity
|
||||
return static_cast<double>(scfx_ieee_double::inf(sign));
|
||||
break;
|
||||
}
|
||||
case SC_BIN:
|
||||
case SC_BIN_US:
|
||||
{
|
||||
SCFX_FAIL_IF_(sign_char);
|
||||
base = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
case SC_BIN_SM:
|
||||
{
|
||||
base = 2;
|
||||
break;
|
||||
}
|
||||
case SC_OCT:
|
||||
case SC_OCT_US:
|
||||
{
|
||||
SCFX_FAIL_IF_(sign_char);
|
||||
base = 8;
|
||||
break;
|
||||
}
|
||||
case SC_OCT_SM:
|
||||
{
|
||||
base = 8;
|
||||
break;
|
||||
}
|
||||
case SC_HEX:
|
||||
case SC_HEX_US:
|
||||
{
|
||||
SCFX_FAIL_IF_(sign_char);
|
||||
base = 16;
|
||||
break;
|
||||
}
|
||||
case SC_HEX_SM:
|
||||
{
|
||||
base = 16;
|
||||
break;
|
||||
}
|
||||
case SC_CSD:
|
||||
{
|
||||
SCFX_FAIL_IF_(sign_char);
|
||||
base = 2;
|
||||
scfx_csd2tc(s2);
|
||||
s = (const char*) s2 + 4;
|
||||
numrep = SC_BIN;
|
||||
break;
|
||||
}
|
||||
default:;// Martin, what is default???
|
||||
}
|
||||
|
||||
//
|
||||
// find end of mantissa and count the digits and points
|
||||
//
|
||||
|
||||
const char *end = s;
|
||||
bool based_point = false;
|
||||
int int_digits = 0;
|
||||
int frac_digits = 0;
|
||||
|
||||
while (*end) {
|
||||
if (scfx_exp_start(end))
|
||||
break;
|
||||
|
||||
if (*end == '.') {
|
||||
SCFX_FAIL_IF_(based_point);
|
||||
based_point = true;
|
||||
} else {
|
||||
SCFX_FAIL_IF_(!scfx_is_digit(*end, numrep));
|
||||
if (based_point)
|
||||
frac_digits++;
|
||||
else
|
||||
int_digits++;
|
||||
}
|
||||
|
||||
end++;
|
||||
}
|
||||
|
||||
SCFX_FAIL_IF_(int_digits == 0 && frac_digits == 0);
|
||||
|
||||
// [ exponent ]
|
||||
int exponent = 0;
|
||||
if (*end) {
|
||||
for (const char *e = end + 2; *e; e++)
|
||||
SCFX_FAIL_IF_(!scfx_is_digit(*e, SC_DEC));
|
||||
exponent = std::atoi(end + 1);
|
||||
}
|
||||
|
||||
//
|
||||
// convert the mantissa
|
||||
//
|
||||
double integer = 0.0;
|
||||
if (int_digits != 0) {
|
||||
bool first_digit = true;
|
||||
|
||||
for (; s < end; s++) {
|
||||
if (*s == '.')
|
||||
break;
|
||||
|
||||
if (first_digit) {
|
||||
integer = scfx_to_digit(*s, numrep);
|
||||
switch (numrep) {
|
||||
case SC_BIN:
|
||||
case SC_OCT:
|
||||
case SC_HEX:
|
||||
{
|
||||
if (integer >= (base >> 1))
|
||||
integer -= base; // two's complement
|
||||
break;
|
||||
}
|
||||
default:
|
||||
;
|
||||
}
|
||||
first_digit = false;
|
||||
} else {
|
||||
integer *= base;
|
||||
integer += scfx_to_digit(*s, numrep);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// [ . fraction ]
|
||||
double fraction = 0.0;
|
||||
if (frac_digits != 0) {
|
||||
s++; // skip '.'
|
||||
|
||||
bool first_digit = (int_digits == 0);
|
||||
double scale = 1.0;
|
||||
for (; s < end; s++) {
|
||||
scale /= base;
|
||||
|
||||
if (first_digit) {
|
||||
fraction = scfx_to_digit(*s, numrep);
|
||||
switch (numrep) {
|
||||
case SC_BIN:
|
||||
case SC_OCT:
|
||||
case SC_HEX:
|
||||
{
|
||||
if (fraction >= (base >> 1))
|
||||
fraction -= base; // two's complement
|
||||
break;
|
||||
}
|
||||
default:
|
||||
;
|
||||
}
|
||||
fraction *= scale;
|
||||
first_digit = false;
|
||||
} else {
|
||||
fraction += scfx_to_digit(*s, numrep) * scale;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double exp =
|
||||
(exponent != 0) ? std::pow((double) base, (double) exponent) : 1;
|
||||
|
||||
return (sign * (integer + fraction) * exp);
|
||||
}
|
||||
|
||||
#undef SCFX_FAIL_IF_
|
||||
|
||||
} // namespace sc_dt
|
||||
72
src/systemc/dt/fx/sc_fxval_observer.cc
Normal file
72
src/systemc/dt/fx/sc_fxval_observer.cc
Normal file
@@ -0,0 +1,72 @@
|
||||
/*****************************************************************************
|
||||
|
||||
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.cpp -
|
||||
|
||||
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.cpp,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.
|
||||
//
|
||||
|
||||
#include "systemc/ext/dt/fx/sc_fxval_observer.hh"
|
||||
|
||||
namespace sc_dt
|
||||
{
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_fxval_observer
|
||||
//
|
||||
// Abstract base class for fixed-point value type observers;
|
||||
// arbitrary precision.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
sc_fxval_observer *(* sc_fxval_observer::default_observer)() = 0;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_fxval_fast_observer
|
||||
//
|
||||
// Abstract base class for fixed-point value type observers;
|
||||
// limited precision.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
sc_fxval_fast_observer *(* sc_fxval_fast_observer::default_observer)() = 0;
|
||||
|
||||
} // namespace sc_dt
|
||||
117
src/systemc/dt/fx/scfx_mant.cc
Normal file
117
src/systemc/dt/fx/scfx_mant.cc
Normal file
@@ -0,0 +1,117 @@
|
||||
/*****************************************************************************
|
||||
|
||||
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.cpp -
|
||||
|
||||
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.cpp,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.
|
||||
//
|
||||
|
||||
#include "systemc/ext/dt/fx/scfx_mant.hh"
|
||||
|
||||
namespace sc_dt
|
||||
{
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// word memory management
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class word_list // Entry in free_words bucket.
|
||||
{
|
||||
public:
|
||||
word_list *m_next_p;
|
||||
};
|
||||
|
||||
static inline unsigned
|
||||
next_pow2_index(std::size_t size)
|
||||
{
|
||||
unsigned index = scfx_find_msb(size);
|
||||
// If this was a power of 2 we are one bucket too low.
|
||||
if (~(UINT64_ONE << index) & size)
|
||||
index++;
|
||||
// If this is a 64-bit machine and we are using 32-bit words go down
|
||||
// one slot size, as all the slots are 2x in size.
|
||||
if (index != 0 && (sizeof(word_list) != sizeof(word))) {
|
||||
index -= 1;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
static word_list *free_words[32] = { 0 };
|
||||
|
||||
word *
|
||||
scfx_mant::alloc_word(std::size_t size)
|
||||
{
|
||||
const int ALLOC_SIZE = 128;
|
||||
|
||||
unsigned slot_index = next_pow2_index(size);
|
||||
unsigned alloc_size = (UINT64_ONE << slot_index);
|
||||
|
||||
word_list*& slot = free_words[slot_index];
|
||||
|
||||
if (!slot) {
|
||||
slot = new word_list[ALLOC_SIZE * alloc_size];
|
||||
unsigned i;
|
||||
for (i = 0; i < alloc_size * (ALLOC_SIZE - 1) ; i += alloc_size) {
|
||||
slot[i].m_next_p = &slot[i + alloc_size];
|
||||
}
|
||||
slot[i].m_next_p = 0;
|
||||
}
|
||||
|
||||
word *result = (word *)slot;
|
||||
free_words[slot_index] = slot[0].m_next_p;
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
scfx_mant::free_word(word *array, std::size_t size)
|
||||
{
|
||||
if (array && size) {
|
||||
int slot_index = next_pow2_index(size);
|
||||
word_list *wl_p = (word_list *)array;
|
||||
|
||||
wl_p->m_next_p = free_words[slot_index];
|
||||
free_words[slot_index] = wl_p;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sc_dt
|
||||
129
src/systemc/dt/fx/scfx_pow10.cc
Normal file
129
src/systemc/dt/fx/scfx_pow10.cc
Normal file
@@ -0,0 +1,129 @@
|
||||
/*****************************************************************************
|
||||
|
||||
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.cpp -
|
||||
|
||||
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.cpp,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.
|
||||
//
|
||||
|
||||
#include "systemc/ext/dt/fx/scfx_pow10.hh"
|
||||
|
||||
namespace sc_dt
|
||||
{
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : scfx_pow10
|
||||
//
|
||||
// Class to compute (and cache) powers of 10 in arbitrary precision.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
scfx_pow10::scfx_pow10()
|
||||
{
|
||||
m_pos[0] = scfx_rep(10.0);
|
||||
m_neg[0] = scfx_rep(0.1);
|
||||
|
||||
for (int i = 1; i < SCFX_POW10_TABLE_SIZE; i++) {
|
||||
m_pos[i].set_nan();
|
||||
m_neg[i].set_nan();
|
||||
}
|
||||
}
|
||||
|
||||
scfx_pow10::~scfx_pow10() {}
|
||||
|
||||
const scfx_rep
|
||||
scfx_pow10::operator() (int i)
|
||||
{
|
||||
if (i == 0) {
|
||||
return scfx_rep(1.0);
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
int bit = scfx_find_msb(i);
|
||||
scfx_rep result = *pos(bit);
|
||||
if (bit) {
|
||||
while (--bit >= 0) {
|
||||
if ((1 << bit) & i) {
|
||||
scfx_rep *tmp = mult_scfx_rep(result, *pos(bit));
|
||||
result = *tmp;
|
||||
delete tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
i = -i;
|
||||
int bit = scfx_find_msb(i);
|
||||
scfx_rep result = *neg(bit);
|
||||
if (bit) {
|
||||
while (--bit >= 0) {
|
||||
if ((1 << bit) & i) {
|
||||
scfx_rep *tmp = mult_scfx_rep(result, *neg(bit));
|
||||
result = *tmp;
|
||||
delete tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
scfx_rep *
|
||||
scfx_pow10::pos(int i)
|
||||
{
|
||||
if (!m_pos[i].is_normal()) {
|
||||
multiply(m_pos[i], *pos(i - 1), *pos(i - 1));
|
||||
}
|
||||
return &m_pos[i];
|
||||
}
|
||||
|
||||
scfx_rep *
|
||||
scfx_pow10::neg(int i)
|
||||
{
|
||||
if (!m_neg[i].is_normal()) {
|
||||
multiply(m_neg[i], *neg(i - 1), *neg(i - 1));
|
||||
}
|
||||
return &m_neg[i];
|
||||
}
|
||||
|
||||
} // namespace sc_dt
|
||||
2651
src/systemc/dt/fx/scfx_rep.cc
Normal file
2651
src/systemc/dt/fx/scfx_rep.cc
Normal file
File diff suppressed because it is too large
Load Diff
162
src/systemc/dt/fx/scfx_utils.cc
Normal file
162
src/systemc/dt/fx/scfx_utils.cc
Normal file
@@ -0,0 +1,162 @@
|
||||
/*****************************************************************************
|
||||
|
||||
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.cpp -
|
||||
|
||||
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.cpp,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.
|
||||
//
|
||||
|
||||
#include "systemc/ext/dt/fx/scfx_utils.hh"
|
||||
|
||||
namespace sc_dt
|
||||
{
|
||||
|
||||
void
|
||||
scfx_tc2csd(scfx_string &s, int w_prefix)
|
||||
{
|
||||
if (w_prefix != 0) {
|
||||
SC_ASSERT_(s[0] == '0' && s[1] == 'c' &&
|
||||
s[2] == 's' && s[3] == 'd', "invalid prefix");
|
||||
}
|
||||
|
||||
scfx_string csd;
|
||||
|
||||
// copy bits from 's' into 'csd'; skip prefix, point, and exponent
|
||||
int i = 0;
|
||||
int j = (w_prefix != 0 ? 4 : 0);
|
||||
while (s[j]) {
|
||||
if (s[j] == '0' || s[j] == '1')
|
||||
csd[i ++] = s[j];
|
||||
else if (s[j] != '.')
|
||||
break;
|
||||
++j;
|
||||
}
|
||||
csd[i] = '\0';
|
||||
|
||||
// convert 'csd' from two's complement to csd
|
||||
--i;
|
||||
while (i >= 0) {
|
||||
if (csd[i] == '0') {
|
||||
--i;
|
||||
} else {
|
||||
if (i > 0 && csd[i - 1] == '0') {
|
||||
--i;
|
||||
} else if (i == 0) {
|
||||
csd[i--] = '-';
|
||||
} else {
|
||||
csd[i--] = '-';
|
||||
while (i >= 0 && csd[i] == '1')
|
||||
csd[i--] = '0';
|
||||
if (i > 0)
|
||||
csd[i] = '1';
|
||||
else if (i == 0)
|
||||
csd[i--] = '1';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// copy bits from 'csd' back into 's'
|
||||
i = 0;
|
||||
j = (w_prefix != 0 ? 4 : 0);
|
||||
while (csd[i]) {
|
||||
if (s[j] == '.')
|
||||
++j;
|
||||
s[j++] = csd[i++];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
scfx_csd2tc(scfx_string &csd)
|
||||
{
|
||||
SC_ASSERT_(csd[0] == '0' && csd[1] == 'c' &&
|
||||
csd[2] == 's' && csd[3] == 'd', "invalid prefix");
|
||||
|
||||
scfx_string s;
|
||||
|
||||
// copy bits from 'csd' into 's'; skip prefix, point, and exponent
|
||||
int i = 0;
|
||||
s[i++] = '0';
|
||||
int j = 4;
|
||||
while (csd[j]) {
|
||||
if (csd[j] == '-' || csd[j] == '0' || csd[j] == '1')
|
||||
s[i++] = csd[j];
|
||||
else if (csd[j] != '.')
|
||||
break;
|
||||
++j;
|
||||
}
|
||||
s[i] = '\0';
|
||||
|
||||
// convert 's' from csd to two's complement
|
||||
int len = i;
|
||||
i = 1;
|
||||
while (i < len) {
|
||||
while (i < len && s[i] != '-')
|
||||
i++;
|
||||
if (i < len) {
|
||||
j = i++;
|
||||
s[j--] = '1';
|
||||
while (j >= 0 && s[j] == '0')
|
||||
s[j--] = '1';
|
||||
if (j >= 0)
|
||||
s[j] = '0';
|
||||
}
|
||||
}
|
||||
|
||||
// copy bits from 's' back into 'csd'
|
||||
j = csd.length();
|
||||
csd[j + 1] = '\0';
|
||||
while (j > 4) {
|
||||
csd[j] = csd[j - 1];
|
||||
--j;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
j = 4;
|
||||
while (s[i]) {
|
||||
if (csd[j] == '.')
|
||||
++j;
|
||||
csd[j++] = s[i++];
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sc_dt
|
||||
38
src/systemc/dt/int/SConscript
Normal file
38
src/systemc/dt/int/SConscript
Normal file
@@ -0,0 +1,38 @@
|
||||
# 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
|
||||
|
||||
Import('*')
|
||||
|
||||
if env['USE_SYSTEMC']:
|
||||
Source('sc_int_base.cc')
|
||||
Source('sc_int_mask.cc')
|
||||
Source('sc_length_param.cc')
|
||||
Source('sc_nbexterns.cc')
|
||||
Source('sc_nbutils.cc')
|
||||
Source('sc_signed.cc')
|
||||
Source('sc_uint_base.cc')
|
||||
Source('sc_unsigned.cc')
|
||||
706
src/systemc/dt/int/sc_int_base.cc
Normal file
706
src/systemc/dt/int/sc_int_base.cc
Normal file
@@ -0,0 +1,706 @@
|
||||
/*****************************************************************************
|
||||
|
||||
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_base.cpp -- contains interface definitions between sc_int and
|
||||
sc_signed, sc_unsigned, and definitions for sc_int_subref.
|
||||
|
||||
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_int_base.cpp,v $
|
||||
// Revision 1.5 2011/02/18 20:19:14 acg
|
||||
// Andy Goodrich: updating Copyright notice.
|
||||
//
|
||||
// Revision 1.4 2010/02/04 22:23:29 acg
|
||||
// Andy Goodrich: fixed bug in concatenation reads for part selections,
|
||||
// the mask being used was 32 bits and should have been 64 bits.
|
||||
//
|
||||
// Revision 1.3 2008/06/19 17:47:56 acg
|
||||
// Andy Goodrich: fixes for bugs. See 2.2.1 RELEASENOTES.
|
||||
//
|
||||
// Revision 1.2 2007/11/04 21:27:00 acg
|
||||
// Andy Goodrich: changes to make sure the proper value is returned from
|
||||
// concat_get_data().
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "systemc/ext/dt/bit/sc_bv_base.hh"
|
||||
#include "systemc/ext/dt/bit/sc_lv_base.hh"
|
||||
#include "systemc/ext/dt/fx/sc_fix.hh"
|
||||
#include "systemc/ext/dt/fx/scfx_other_defs.hh"
|
||||
#include "systemc/ext/dt/int/sc_int_base.hh"
|
||||
#include "systemc/ext/dt/int/sc_signed.hh"
|
||||
#include "systemc/ext/dt/int/sc_uint_base.hh"
|
||||
#include "systemc/ext/dt/int/sc_unsigned.hh"
|
||||
#include "systemc/ext/dt/misc/sc_concatref.hh"
|
||||
|
||||
// explicit template instantiations
|
||||
namespace sc_core
|
||||
{
|
||||
|
||||
template class sc_vpool<sc_dt::sc_int_bitref>;
|
||||
template class sc_vpool<sc_dt::sc_int_subref>;
|
||||
|
||||
} // namespace sc_core
|
||||
|
||||
namespace sc_dt
|
||||
{
|
||||
|
||||
// to avoid code bloat in sc_int_concref<T1,T2>
|
||||
|
||||
void
|
||||
sc_int_concref_invalid_length(int length)
|
||||
{
|
||||
std::stringstream msg;
|
||||
msg << "sc_int_concref<T1,T2> initialization: length = " << length <<
|
||||
"violates 1 <= length <= " << SC_INTWIDTH;
|
||||
SC_REPORT_ERROR("out of bounds", msg.str().c_str());
|
||||
sc_core::sc_abort(); // can't recover from here
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_int_bitref
|
||||
//
|
||||
// Proxy class for sc_int bit selection (r-value and l-value).
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
sc_core::sc_vpool<sc_int_bitref> sc_int_bitref::m_pool(9);
|
||||
|
||||
// concatenation methods:
|
||||
|
||||
// #### OPTIMIZE
|
||||
void sc_int_bitref::concat_set(int64 src, int low_i)
|
||||
{
|
||||
sc_int_base aa(1);
|
||||
*this = aa = (low_i < 64) ? src >> low_i : src >> 63;
|
||||
}
|
||||
|
||||
void sc_int_bitref::concat_set(const sc_signed &src, int low_i)
|
||||
{
|
||||
sc_int_base aa(1);
|
||||
if (low_i < src.length())
|
||||
*this = aa = 1 & (src >> low_i);
|
||||
else
|
||||
*this = aa = (src < 0) ? (int_type)-1 : 0;
|
||||
}
|
||||
|
||||
void sc_int_bitref::concat_set(const sc_unsigned &src, int low_i)
|
||||
{
|
||||
sc_int_base aa(1);
|
||||
if (low_i < src.length())
|
||||
*this = aa = 1 & (src >> low_i);
|
||||
else
|
||||
*this = aa = 0;
|
||||
}
|
||||
|
||||
void sc_int_bitref::concat_set(uint64 src, int low_i)
|
||||
{
|
||||
sc_int_base aa(1);
|
||||
*this = aa = (low_i < 64) ? src >> low_i : 0;
|
||||
}
|
||||
|
||||
|
||||
// other methods
|
||||
void
|
||||
sc_int_bitref::scan(::std::istream &is)
|
||||
{
|
||||
bool b;
|
||||
is >> b;
|
||||
*this = b;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_int_subref_r
|
||||
//
|
||||
// Proxy class for sc_int part selection (l-value).
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool
|
||||
sc_int_subref_r::concat_get_ctrl(sc_digit *dst_p, int low_i) const
|
||||
{
|
||||
int dst_i; // Word in dst_p now processing.
|
||||
int end_i; // Highest order word in dst_p to process.
|
||||
int high_i; // Index of high order bit in dst_p to set.
|
||||
uint_type mask; // Mask for bits to extract or keep.
|
||||
|
||||
dst_i = low_i / BITS_PER_DIGIT;
|
||||
high_i = low_i + (m_left - m_right);
|
||||
end_i = high_i / BITS_PER_DIGIT;
|
||||
mask = ~mask_int[m_left][m_right];
|
||||
|
||||
// PROCESS THE FIRST WORD:
|
||||
dst_p[dst_i] = (sc_digit)(dst_p[dst_i] & mask);
|
||||
switch (end_i - dst_i) {
|
||||
// BITS ARE ACROSS TWO WORDS:
|
||||
case 1:
|
||||
dst_i++;
|
||||
dst_p[dst_i] = 0;
|
||||
break;
|
||||
|
||||
// BITS ARE ACROSS THREE WORDS:
|
||||
case 2:
|
||||
dst_i++;
|
||||
dst_p[dst_i++] = 0;
|
||||
dst_p[dst_i] = 0;
|
||||
break;
|
||||
|
||||
// BITS ARE ACROSS FOUR WORDS:
|
||||
case 3:
|
||||
dst_i++;
|
||||
dst_p[dst_i++] = 0;
|
||||
dst_p[dst_i++] = 0;
|
||||
dst_p[dst_i] = 0;
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
sc_int_subref_r::concat_get_data(sc_digit *dst_p, int low_i) const
|
||||
{
|
||||
int dst_i; // Word in dst_p now processing.
|
||||
int end_i; // Highest order word in dst_p to process.
|
||||
int high_i; // Index of high order bit in dst_p to set.
|
||||
int left_shift; // Left shift for val.
|
||||
uint_type mask; // Mask for bits to extract or keep.
|
||||
bool non_zero; // True if value inserted is non-zero.
|
||||
uint_type val; // Selection value extracted from m_obj_p.
|
||||
|
||||
dst_i = low_i / BITS_PER_DIGIT;
|
||||
left_shift = low_i % BITS_PER_DIGIT;
|
||||
high_i = low_i + (m_left-m_right);
|
||||
end_i = high_i / BITS_PER_DIGIT;
|
||||
mask = ~mask_int[m_left][m_right];
|
||||
val = (m_obj_p->m_val & mask) >> m_right;
|
||||
non_zero = val != 0;
|
||||
|
||||
// PROCESS THE FIRST WORD:
|
||||
mask = ~(~UINT_ZERO << left_shift);
|
||||
dst_p[dst_i] = (sc_digit)((dst_p[dst_i] & mask) |
|
||||
((val << left_shift) & DIGIT_MASK));
|
||||
|
||||
switch (end_i - dst_i) {
|
||||
// BITS ARE ACROSS TWO WORDS:
|
||||
case 1:
|
||||
dst_i++;
|
||||
val >>= (BITS_PER_DIGIT - left_shift);
|
||||
dst_p[dst_i] = (sc_digit)(val & DIGIT_MASK);
|
||||
break;
|
||||
|
||||
// BITS ARE ACROSS THREE WORDS:
|
||||
case 2:
|
||||
dst_i++;
|
||||
val >>= (BITS_PER_DIGIT - left_shift);
|
||||
dst_p[dst_i++] = (sc_digit)(val & DIGIT_MASK);
|
||||
val >>= BITS_PER_DIGIT;
|
||||
dst_p[dst_i] = (sc_digit)val;
|
||||
break;
|
||||
|
||||
// BITS ARE ACROSS FOUR WORDS:
|
||||
case 3:
|
||||
dst_i++;
|
||||
val >>= (BITS_PER_DIGIT - left_shift);
|
||||
dst_p[dst_i++] = (sc_digit)(val & DIGIT_MASK);
|
||||
val >>= BITS_PER_DIGIT;
|
||||
dst_p[dst_i++] = (sc_digit)(val & DIGIT_MASK);
|
||||
val >>= BITS_PER_DIGIT;
|
||||
dst_p[dst_i] = (sc_digit)val;
|
||||
break;
|
||||
}
|
||||
return non_zero;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_int_subref
|
||||
//
|
||||
// Proxy class for sc_int part selection (r-value and l-value).
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
sc_core::sc_vpool<sc_int_subref> sc_int_subref::m_pool(9);
|
||||
|
||||
// assignment operators
|
||||
|
||||
sc_int_subref &
|
||||
sc_int_subref::operator = (int_type v)
|
||||
{
|
||||
int_type val = m_obj_p->m_val;
|
||||
uint_type mask = mask_int[m_left][m_right];
|
||||
val &= mask;
|
||||
val |= (v << m_right) & ~mask;
|
||||
m_obj_p->m_val = val;
|
||||
m_obj_p->extend_sign();
|
||||
return *this;
|
||||
}
|
||||
|
||||
sc_int_subref &
|
||||
sc_int_subref::operator = (const sc_signed &a)
|
||||
{
|
||||
sc_int_base aa(length());
|
||||
return (*this = aa = a);
|
||||
}
|
||||
|
||||
sc_int_subref &
|
||||
sc_int_subref::operator = (const sc_unsigned &a)
|
||||
{
|
||||
sc_int_base aa(length());
|
||||
return (*this = aa = a);
|
||||
}
|
||||
|
||||
sc_int_subref &
|
||||
sc_int_subref::operator = (const sc_bv_base &a)
|
||||
{
|
||||
sc_int_base aa(length());
|
||||
return (*this = aa = a);
|
||||
}
|
||||
|
||||
sc_int_subref &
|
||||
sc_int_subref::operator = (const sc_lv_base &a)
|
||||
{
|
||||
sc_int_base aa(length());
|
||||
return (*this = aa = a);
|
||||
}
|
||||
|
||||
|
||||
// concatenation methods:
|
||||
// #### OPTIMIZE
|
||||
void
|
||||
sc_int_subref::concat_set(int64 src, int low_i)
|
||||
{
|
||||
sc_int_base aa(length());
|
||||
*this = aa = (low_i < 64) ? src >> low_i : src >> 63;
|
||||
}
|
||||
|
||||
void
|
||||
sc_int_subref::concat_set(const sc_signed &src, int low_i)
|
||||
{
|
||||
sc_int_base aa(length());
|
||||
if (low_i < src.length())
|
||||
*this = aa = src >> low_i;
|
||||
else
|
||||
*this = (src < 0) ? (int_type)-1 : 0;
|
||||
}
|
||||
|
||||
void
|
||||
sc_int_subref::concat_set(const sc_unsigned &src, int low_i)
|
||||
{
|
||||
sc_int_base aa(length());
|
||||
if (low_i < src.length())
|
||||
*this = aa = src >> low_i;
|
||||
else
|
||||
*this = 0;
|
||||
}
|
||||
|
||||
void
|
||||
sc_int_subref::concat_set(uint64 src, int low_i)
|
||||
{
|
||||
sc_int_base aa (length());
|
||||
*this = aa = (low_i < 64) ? src >> low_i : 0;
|
||||
}
|
||||
|
||||
|
||||
// other methods
|
||||
void
|
||||
sc_int_subref::scan(::std::istream &is)
|
||||
{
|
||||
std::string s;
|
||||
is >> s;
|
||||
*this = s.c_str();
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_int_base
|
||||
//
|
||||
// Base class for sc_int.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// support methods
|
||||
void
|
||||
sc_int_base::invalid_length() const
|
||||
{
|
||||
std::stringstream msg;
|
||||
msg << "sc_int[_base] initialization: length = " << m_len <<
|
||||
" violates 1 <= length <= " << SC_INTWIDTH;
|
||||
SC_REPORT_ERROR("out of bounds", msg.str().c_str());
|
||||
sc_core::sc_abort(); // can't recover from here
|
||||
}
|
||||
|
||||
void
|
||||
sc_int_base::invalid_index(int i) const
|
||||
{
|
||||
std::stringstream msg;
|
||||
msg << "sc_int[_base] bit selection: index = " << i <<
|
||||
" violates 0 <= index <= " << (m_len - 1);
|
||||
SC_REPORT_ERROR("out of bounds", msg.str().c_str());
|
||||
sc_core::sc_abort(); // can't recover from here
|
||||
}
|
||||
|
||||
void
|
||||
sc_int_base::invalid_range(int l, int r) const
|
||||
{
|
||||
std::stringstream msg;
|
||||
msg << "sc_int[_base] part selection: " <<
|
||||
"left = " << l << ", right = " << r << " violates " <<
|
||||
(m_len-1) << " >= left >= right >= 0";
|
||||
SC_REPORT_ERROR("out of bounds", msg.str().c_str());
|
||||
sc_core::sc_abort(); // can't recover from here
|
||||
}
|
||||
|
||||
void
|
||||
sc_int_base::check_value() const
|
||||
{
|
||||
int_type limit = (int_type)1 << (m_len - 1);
|
||||
if (m_val < -limit || m_val >= limit) {
|
||||
std::stringstream msg;
|
||||
msg << "sc_int[_base]: value does not fit into a length of " << m_len;
|
||||
SC_REPORT_WARNING("out of bounds", msg.str().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// constructors
|
||||
sc_int_base::sc_int_base(const sc_bv_base &v) :
|
||||
m_val(0), m_len(v.length()), m_ulen(SC_INTWIDTH - m_len)
|
||||
{
|
||||
check_length();
|
||||
*this = v;
|
||||
}
|
||||
sc_int_base::sc_int_base(const sc_lv_base &v) :
|
||||
m_val(0), m_len(v.length()), m_ulen(SC_INTWIDTH - m_len)
|
||||
{
|
||||
check_length();
|
||||
*this = v;
|
||||
}
|
||||
sc_int_base::sc_int_base(const sc_uint_subref_r &v) :
|
||||
m_val(0), m_len(v.length()), m_ulen(SC_INTWIDTH - m_len)
|
||||
{
|
||||
check_length();
|
||||
*this = v.to_uint64();
|
||||
}
|
||||
sc_int_base::sc_int_base(const sc_signed_subref_r &v) :
|
||||
m_val(0), m_len(v.length()), m_ulen(SC_INTWIDTH - m_len)
|
||||
{
|
||||
check_length();
|
||||
*this = v.to_uint64();
|
||||
}
|
||||
sc_int_base::sc_int_base(const sc_unsigned_subref_r &v) :
|
||||
m_val(0), m_len(v.length()), m_ulen(SC_INTWIDTH - m_len)
|
||||
{
|
||||
check_length();
|
||||
*this = v.to_uint64();
|
||||
}
|
||||
|
||||
sc_int_base::sc_int_base(const sc_signed &a) :
|
||||
m_val(0), m_len(a.length()), m_ulen(SC_INTWIDTH - m_len)
|
||||
{
|
||||
check_length();
|
||||
*this = a.to_int64();
|
||||
}
|
||||
|
||||
sc_int_base::sc_int_base(const sc_unsigned &a) :
|
||||
m_val(0), m_len(a.length()), m_ulen(SC_INTWIDTH - m_len)
|
||||
{
|
||||
check_length();
|
||||
*this = a.to_int64();
|
||||
}
|
||||
|
||||
|
||||
// assignment operators
|
||||
sc_int_base &
|
||||
sc_int_base::operator = (const sc_signed &a)
|
||||
{
|
||||
int minlen = sc_min(m_len, a.length());
|
||||
int i = 0;
|
||||
for (; i < minlen; ++i) {
|
||||
set(i, a.test(i));
|
||||
}
|
||||
bool sgn = a.sign();
|
||||
for (; i < m_len; ++i) {
|
||||
// sign extension
|
||||
set(i, sgn);
|
||||
}
|
||||
extend_sign();
|
||||
return *this;
|
||||
}
|
||||
|
||||
sc_int_base &
|
||||
sc_int_base::operator = (const sc_unsigned &a)
|
||||
{
|
||||
int minlen = sc_min(m_len, a.length());
|
||||
int i = 0;
|
||||
for (; i < minlen; ++i) {
|
||||
set(i, a.test(i));
|
||||
}
|
||||
for (; i < m_len; ++i) {
|
||||
// zero extension
|
||||
set(i, 0);
|
||||
}
|
||||
extend_sign();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
sc_int_base &
|
||||
sc_int_base::operator = (const sc_bv_base &a)
|
||||
{
|
||||
int minlen = sc_min(m_len, a.length());
|
||||
int i = 0;
|
||||
for (; i < minlen; ++i) {
|
||||
set(i, a.get_bit(i));
|
||||
}
|
||||
for (; i < m_len; ++i) {
|
||||
// zero extension
|
||||
set(i, 0);
|
||||
}
|
||||
extend_sign();
|
||||
return *this;
|
||||
}
|
||||
|
||||
sc_int_base &
|
||||
sc_int_base::operator = (const sc_lv_base &a)
|
||||
{
|
||||
int minlen = sc_min(m_len, a.length());
|
||||
int i = 0;
|
||||
for (; i < minlen; ++i) {
|
||||
set(i, sc_logic(a.get_bit(i)).to_bool());
|
||||
}
|
||||
for (; i < m_len; ++i) {
|
||||
// zero extension
|
||||
set(i, 0);
|
||||
}
|
||||
extend_sign();
|
||||
return *this;
|
||||
}
|
||||
|
||||
sc_int_base &
|
||||
sc_int_base::operator = (const char *a)
|
||||
{
|
||||
if (a == 0) {
|
||||
SC_REPORT_ERROR("conversion failed",
|
||||
"character string is zero");
|
||||
} else if (*a == 0) {
|
||||
SC_REPORT_ERROR("conversion failed",
|
||||
"character string is empty");
|
||||
} else try {
|
||||
int len = m_len;
|
||||
sc_fix aa(a, len, len, SC_TRN, SC_WRAP, 0, SC_ON);
|
||||
return this->operator = (aa);
|
||||
} catch(const sc_core::sc_report &) {
|
||||
std::stringstream msg;
|
||||
msg << "character string '" << a << "' is not valid";
|
||||
SC_REPORT_ERROR("conversion failed", msg.str().c_str());
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// explicit conversion to character string
|
||||
const std::string
|
||||
sc_int_base::to_string(sc_numrep numrep) const
|
||||
{
|
||||
int len = m_len;
|
||||
sc_fix aa(*this, len, len, SC_TRN, SC_WRAP, 0, SC_ON);
|
||||
return aa.to_string(numrep);
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_int_base::to_string(sc_numrep numrep, bool w_prefix) const
|
||||
{
|
||||
int len = m_len;
|
||||
sc_fix aa(*this, len, len, SC_TRN, SC_WRAP, 0, SC_ON);
|
||||
return aa.to_string(numrep, w_prefix);
|
||||
}
|
||||
|
||||
|
||||
// reduce methods
|
||||
bool sc_int_base::and_reduce() const { return (m_val == int_type(-1)); }
|
||||
bool sc_int_base::or_reduce() const { return (m_val != int_type(0)); }
|
||||
|
||||
bool
|
||||
sc_int_base::xor_reduce() const
|
||||
{
|
||||
uint_type mask = ~UINT_ZERO;
|
||||
uint_type val = m_val & (mask >> m_ulen);
|
||||
int n = SC_INTWIDTH;
|
||||
do {
|
||||
n >>= 1;
|
||||
mask >>= n;
|
||||
val = ((val & (mask << n)) >> n) ^ (val & mask);
|
||||
} while (n != 1);
|
||||
return (val != uint_type(0));
|
||||
}
|
||||
|
||||
bool
|
||||
sc_int_base::concat_get_ctrl(sc_digit *dst_p, int low_i) const
|
||||
{
|
||||
int dst_i; // Word in dst_p now processing.
|
||||
int end_i; // Highest order word in dst_p to process.
|
||||
int left_shift; // Left shift for val.
|
||||
uint_type mask; // Mask for bits to extract or keep.
|
||||
|
||||
dst_i = low_i / BITS_PER_DIGIT;
|
||||
left_shift = low_i % BITS_PER_DIGIT;
|
||||
end_i = (low_i + (m_len - 1)) / BITS_PER_DIGIT;
|
||||
|
||||
mask = ~(~UINT_ZERO << left_shift);
|
||||
dst_p[dst_i] = (sc_digit)(dst_p[dst_i] & mask);
|
||||
dst_i++;
|
||||
for (; dst_i <= end_i; dst_i++)
|
||||
dst_p[dst_i] = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//"sc_int_base::concat_get_data"
|
||||
//
|
||||
// This method transfers the value of this object instance to the supplied
|
||||
// array of sc_unsigned digits starting with the bit specified by low_i within
|
||||
// the array of digits.
|
||||
//
|
||||
// Notes:
|
||||
// (1) we don't worry about masking the high order data we transfer since
|
||||
// concat_get_data() is called from low order bit to high order bit. So
|
||||
// the bits above where we place ours will be filled in by someone else.
|
||||
//
|
||||
// dst_p -> array of sc_unsigned digits to be filled in.
|
||||
// low_i = first bit within dst_p to be set.
|
||||
//-----------------------------------------------------------------------------
|
||||
bool
|
||||
sc_int_base::concat_get_data(sc_digit *dst_p, int low_i) const
|
||||
{
|
||||
int dst_i; // Word in dst_p now processing.
|
||||
int end_i; // Highest order word in dst_p to process.
|
||||
int high_i; // Index of high order bit in dst_p to set.
|
||||
int left_shift; // Left shift for val.
|
||||
uint_type mask; // Mask for bits to extract or keep.
|
||||
bool non_zero; // True if value inserted is non-zero.
|
||||
uint_type val; // Value for this object.
|
||||
|
||||
dst_i = low_i / BITS_PER_DIGIT;
|
||||
left_shift = low_i % BITS_PER_DIGIT;
|
||||
high_i = low_i + (m_len - 1);
|
||||
end_i = high_i / BITS_PER_DIGIT;
|
||||
val = m_val;
|
||||
non_zero = val != 0;
|
||||
|
||||
// MASK OFF DATA TO BE TRANSFERRED BASED ON WIDTH:
|
||||
if (m_len < 64) {
|
||||
mask = ~(~UINT_ZERO << m_len);
|
||||
val &= mask;
|
||||
}
|
||||
|
||||
// PROCESS THE FIRST WORD:
|
||||
mask = (~UINT_ZERO << left_shift);
|
||||
dst_p[dst_i] = (sc_digit)((dst_p[dst_i] & ~mask) |
|
||||
((val <<left_shift) & DIGIT_MASK));
|
||||
switch (end_i - dst_i) {
|
||||
// BITS ARE ACROSS TWO WORDS:
|
||||
case 1:
|
||||
dst_i++;
|
||||
val >>= (BITS_PER_DIGIT - left_shift);
|
||||
dst_p[dst_i] = (sc_digit)val;
|
||||
break;
|
||||
|
||||
// BITS ARE ACROSS THREE WORDS:
|
||||
case 2:
|
||||
dst_i++;
|
||||
val >>= (BITS_PER_DIGIT - left_shift);
|
||||
dst_p[dst_i++] = ((sc_digit)val) & DIGIT_MASK;
|
||||
val >>= BITS_PER_DIGIT;
|
||||
dst_p[dst_i] = (sc_digit)val;
|
||||
break;
|
||||
|
||||
// BITS ARE ACROSS FOUR WORDS:
|
||||
case 3:
|
||||
dst_i++;
|
||||
val >>= (BITS_PER_DIGIT - left_shift);
|
||||
dst_p[dst_i++] = (sc_digit)(val & DIGIT_MASK);
|
||||
val >>= BITS_PER_DIGIT;
|
||||
dst_p[dst_i++] = (sc_digit)(val & DIGIT_MASK);
|
||||
val >>= BITS_PER_DIGIT;
|
||||
dst_p[dst_i] = (sc_digit)val;
|
||||
break;
|
||||
}
|
||||
return non_zero;
|
||||
}
|
||||
|
||||
// #### OPTIMIZE
|
||||
void
|
||||
sc_int_base::concat_set(int64 src, int low_i)
|
||||
{
|
||||
*this = (low_i < 64) ? src >> low_i : src >> 63;
|
||||
}
|
||||
|
||||
void
|
||||
sc_int_base::concat_set(const sc_signed &src, int low_i)
|
||||
{
|
||||
if (low_i < src.length())
|
||||
*this = src >> low_i;
|
||||
else
|
||||
*this = (src < 0) ? (int_type)-1 : 0;
|
||||
}
|
||||
|
||||
void
|
||||
sc_int_base::concat_set(const sc_unsigned &src, int low_i)
|
||||
{
|
||||
if (low_i < src.length())
|
||||
*this = src >> low_i;
|
||||
else
|
||||
*this = 0;
|
||||
}
|
||||
|
||||
void
|
||||
sc_int_base::concat_set(uint64 src, int low_i)
|
||||
{
|
||||
*this = (low_i < 64) ? src >> low_i : 0;
|
||||
}
|
||||
|
||||
// other methods
|
||||
void
|
||||
sc_int_base::scan(::std::istream &is)
|
||||
{
|
||||
std::string s;
|
||||
is >> s;
|
||||
*this = s.c_str();
|
||||
}
|
||||
|
||||
} // namespace sc_dt;
|
||||
2268
src/systemc/dt/int/sc_int_mask.cc
Normal file
2268
src/systemc/dt/int/sc_int_mask.cc
Normal file
File diff suppressed because it is too large
Load Diff
91
src/systemc/dt/int/sc_length_param.cc
Normal file
91
src/systemc/dt/int/sc_length_param.cc
Normal file
@@ -0,0 +1,91 @@
|
||||
/*****************************************************************************
|
||||
|
||||
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.cpp -
|
||||
|
||||
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.cpp,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.
|
||||
//
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "systemc/ext/dt/int/sc_length_param.hh"
|
||||
|
||||
namespace sc_dt
|
||||
{
|
||||
|
||||
// explicit template instantiations
|
||||
template class sc_global<sc_length_param>;
|
||||
template class sc_context<sc_length_param>;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_length_param
|
||||
//
|
||||
// Length parameter type.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
const std::string
|
||||
sc_length_param::to_string() const
|
||||
{
|
||||
std::stringstream ss;
|
||||
print(ss);
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void
|
||||
sc_length_param::print(::std::ostream &os) const
|
||||
{
|
||||
os << "(" << m_len << ")";
|
||||
}
|
||||
|
||||
void
|
||||
sc_length_param::dump(::std::ostream &os) const
|
||||
{
|
||||
os << "sc_length_param" << ::std::endl;
|
||||
os << "(" << ::std::endl;
|
||||
os << "len = " << m_len << ::std::endl;
|
||||
os << ")" << ::std::endl;
|
||||
}
|
||||
|
||||
} // namespace sc_dt
|
||||
2617
src/systemc/dt/int/sc_nbcommon.inc
Normal file
2617
src/systemc/dt/int/sc_nbcommon.inc
Normal file
File diff suppressed because it is too large
Load Diff
739
src/systemc/dt/int/sc_nbexterns.cc
Normal file
739
src/systemc/dt/int/sc_nbexterns.cc
Normal file
@@ -0,0 +1,739 @@
|
||||
/*****************************************************************************
|
||||
|
||||
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.cpp -- 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.
|
||||
|
||||
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.cpp,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.
|
||||
//
|
||||
|
||||
#include "systemc/ext/dt/int/sc_nbexterns.hh"
|
||||
#include "systemc/ext/utils/functions.hh"
|
||||
|
||||
namespace sc_dt
|
||||
{
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// SECTION: External functions for PLUS operators.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Handles the cases 3 and 4 and returns the result in u.
|
||||
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)
|
||||
{
|
||||
vnd = vec_skip_leading_zeros(vnd, vd);
|
||||
|
||||
if (us == vs) { // case 3
|
||||
if (und >= vnd)
|
||||
vec_add_on(und, ud, vnd, vd);
|
||||
else
|
||||
vec_add_on2(und, ud, vnd, vd);
|
||||
|
||||
} else { // case 4
|
||||
// vec_cmp expects that und is the number of non-zero digits in ud.
|
||||
int new_und = vec_skip_leading_zeros(und, ud);
|
||||
int cmp_res = vec_cmp(new_und, ud, vnd, vd);
|
||||
|
||||
if (cmp_res == 0) { // u == v
|
||||
us = SC_ZERO;
|
||||
vec_zero(und, ud);
|
||||
return;
|
||||
}
|
||||
|
||||
if (cmp_res > 0) { // u > v
|
||||
vec_sub_on(und, ud, vnd, vd);
|
||||
} else { // u < v
|
||||
us = -us;
|
||||
vec_sub_on2(und, ud, vnd, vd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
|
||||
mul_on_help_signed and mul_on_help_unsigned have the same body except
|
||||
that CONVERT_SM_to_2C_to_SM and COPY_DIGITS are defined for signed and
|
||||
unsigned, respectively. This comment also applies to the
|
||||
signed/unsigned versions of div_on_help and mod_on_help. It is
|
||||
possible to take COPY_DIGITS out of these functions and create a
|
||||
single version of each of these helper functions; however, this will
|
||||
impose an onverhead on performance. In the versions below, any change
|
||||
in the signed version of a helper function must be carried to a
|
||||
corresponding change in the unsigned verion of the same function or
|
||||
vice versa.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// SECTION: External functions of MULTIPLICATION operators.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void
|
||||
mul_on_help_signed(small_type &us, int unb, int und, sc_digit *ud,
|
||||
int vnb, int vnd, const sc_digit *vd)
|
||||
{
|
||||
#define CONVERT_SM_to_2C_to_SM convert_signed_SM_to_2C_to_SM
|
||||
#define COPY_DIGITS copy_digits_signed
|
||||
{ // Body of mul_on_help
|
||||
int old_und = und;
|
||||
|
||||
und = vec_skip_leading_zeros(und, ud);
|
||||
vnd = vec_skip_leading_zeros(vnd, vd);
|
||||
|
||||
sc_digit ud0 = (*ud);
|
||||
sc_digit vd0 = (*vd);
|
||||
|
||||
if ((vnd == 1) && (vd0 == 1)) {
|
||||
us = CONVERT_SM_to_2C_to_SM(us, unb, old_und, ud);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((und == 1) && (ud0 == 1)) {
|
||||
COPY_DIGITS(us, unb, old_und, ud, vnb, vnd, vd);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((und == 1) && (vnd == 1) &&
|
||||
(ud0 < HALF_DIGIT_RADIX) && (vd0 < HALF_DIGIT_RADIX)) {
|
||||
|
||||
sc_digit d = ud0 * vd0;
|
||||
COPY_DIGITS(us, unb, old_und, ud, unb + vnb, 1, &d);
|
||||
return;
|
||||
}
|
||||
|
||||
int nd = und + vnd;
|
||||
|
||||
#ifdef SC_MAX_NBITS
|
||||
sc_digit d[MAX_NDIGITS];
|
||||
#else
|
||||
sc_digit *d = new sc_digit[nd];
|
||||
#endif
|
||||
|
||||
vec_zero(nd, d);
|
||||
|
||||
if ((und == 1) && (ud0 < HALF_DIGIT_RADIX))
|
||||
vec_mul_small(vnd, vd, ud0, d);
|
||||
else if ((vnd == 1) && (vd0 < HALF_DIGIT_RADIX))
|
||||
vec_mul_small(und, ud, vd0, d);
|
||||
else if (vnd < und)
|
||||
vec_mul(und, ud, vnd, vd, d);
|
||||
else
|
||||
vec_mul(vnd, vd, und, ud, d);
|
||||
|
||||
COPY_DIGITS(us, unb, old_und, ud, unb + vnb, nd, d);
|
||||
|
||||
#ifndef SC_MAX_NBITS
|
||||
delete [] d;
|
||||
#endif
|
||||
}
|
||||
#undef COPY_DIGITS
|
||||
#undef CONVERT_SM_to_2C_to_SM
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
mul_on_help_unsigned(small_type &us, int unb, int und, sc_digit *ud,
|
||||
int vnb, int vnd, const sc_digit *vd)
|
||||
{
|
||||
#define CONVERT_SM_to_2C_to_SM convert_unsigned_SM_to_2C_to_SM
|
||||
#define COPY_DIGITS copy_digits_unsigned
|
||||
{ // Body of mul_on_help
|
||||
int old_und = und;
|
||||
|
||||
und = vec_skip_leading_zeros(und, ud);
|
||||
vnd = vec_skip_leading_zeros(vnd, vd);
|
||||
|
||||
sc_digit ud0 = (*ud);
|
||||
sc_digit vd0 = (*vd);
|
||||
|
||||
if ((vnd == 1) && (vd0 == 1)) {
|
||||
us = CONVERT_SM_to_2C_to_SM(us, unb, old_und, ud);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((und == 1) && (ud0 == 1)) {
|
||||
COPY_DIGITS(us, unb, old_und, ud, vnb, vnd, vd);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((und == 1) && (vnd == 1) &&
|
||||
(ud0 < HALF_DIGIT_RADIX) && (vd0 < HALF_DIGIT_RADIX)) {
|
||||
|
||||
sc_digit d = ud0 * vd0;
|
||||
COPY_DIGITS(us, unb, old_und, ud, unb + vnb, 1, &d);
|
||||
return;
|
||||
}
|
||||
|
||||
int nd = und + vnd;
|
||||
|
||||
#ifdef SC_MAX_NBITS
|
||||
sc_digit d[MAX_NDIGITS];
|
||||
#else
|
||||
sc_digit *d = new sc_digit[nd];
|
||||
#endif
|
||||
|
||||
vec_zero(nd, d);
|
||||
|
||||
if ((und == 1) && (ud0 < HALF_DIGIT_RADIX))
|
||||
vec_mul_small(vnd, vd, ud0, d);
|
||||
else if ((vnd == 1) && (vd0 < HALF_DIGIT_RADIX))
|
||||
vec_mul_small(und, ud, vd0, d);
|
||||
else if (vnd < und)
|
||||
vec_mul(und, ud, vnd, vd, d);
|
||||
else
|
||||
vec_mul(vnd, vd, und, ud, d);
|
||||
|
||||
COPY_DIGITS(us, unb, old_und, ud, unb + vnb, nd, d);
|
||||
|
||||
#ifndef SC_MAX_NBITS
|
||||
delete [] d;
|
||||
#endif
|
||||
}
|
||||
#undef COPY_DIGITS
|
||||
#undef CONVERT_SM_to_2C_to_SM
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// SECTION: External functions for DIVISION operators.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void
|
||||
div_on_help_signed(small_type &us, int unb, int und, sc_digit *ud,
|
||||
int vnb, int vnd, const sc_digit *vd)
|
||||
{
|
||||
#define CONVERT_SM_to_2C_to_SM convert_signed_SM_to_2C_to_SM
|
||||
#define COPY_DIGITS copy_digits_signed
|
||||
{ // Body of div_on_help
|
||||
int old_und = und;
|
||||
|
||||
und = vec_skip_leading_zeros(und, ud);
|
||||
vnd = vec_skip_leading_zeros(vnd, vd);
|
||||
|
||||
int cmp_res = vec_cmp(und, ud, vnd, vd);
|
||||
|
||||
if (cmp_res < 0) { // u < v => u / v = 0 - case 4
|
||||
us = SC_ZERO;
|
||||
vec_zero(old_und, ud);
|
||||
return;
|
||||
}
|
||||
|
||||
sc_digit vd0 = (*vd);
|
||||
|
||||
if ((cmp_res > 0) && (vnd == 1) && (vd0 == 1)) {
|
||||
us = CONVERT_SM_to_2C_to_SM(us, unb, old_und, ud);
|
||||
return;
|
||||
}
|
||||
|
||||
// One extra digit for d is allocated to simplify vec_div_*().
|
||||
int nd = sc_max(und, vnd) + 1;
|
||||
|
||||
#ifdef SC_MAX_NBITS
|
||||
sc_digit d[MAX_NDIGITS + 1];
|
||||
#else
|
||||
sc_digit *d = new sc_digit[nd];
|
||||
#endif
|
||||
|
||||
vec_zero(nd, d);
|
||||
|
||||
// u = v => u / v = 1 - case 3
|
||||
if (cmp_res == 0)
|
||||
d[0] = 1;
|
||||
else if ((vnd == 1) && (und == 1))
|
||||
d[0] = (*ud) / vd0;
|
||||
else if ((vnd == 1) && (vd0 < HALF_DIGIT_RADIX))
|
||||
vec_div_small(und, ud, vd0, d);
|
||||
else
|
||||
vec_div_large(und, ud, vnd, vd, d);
|
||||
|
||||
COPY_DIGITS(us, unb, old_und, ud, sc_max(unb, vnb), nd - 1, d);
|
||||
|
||||
#ifndef SC_MAX_NBITS
|
||||
delete [] d;
|
||||
#endif
|
||||
}
|
||||
#undef COPY_DIGITS
|
||||
#undef CONVERT_SM_to_2C_to_SM
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
div_on_help_unsigned(small_type &us, int unb, int und, sc_digit *ud,
|
||||
int vnb, int vnd, const sc_digit *vd)
|
||||
{
|
||||
#define CONVERT_SM_to_2C_to_SM convert_unsigned_SM_to_2C_to_SM
|
||||
#define COPY_DIGITS copy_digits_unsigned
|
||||
{ // Body of div_on_help
|
||||
int old_und = und;
|
||||
|
||||
und = vec_skip_leading_zeros(und, ud);
|
||||
vnd = vec_skip_leading_zeros(vnd, vd);
|
||||
|
||||
int cmp_res = vec_cmp(und, ud, vnd, vd);
|
||||
|
||||
if (cmp_res < 0) { // u < v => u / v = 0 - case 4
|
||||
us = SC_ZERO;
|
||||
vec_zero(old_und, ud);
|
||||
return;
|
||||
}
|
||||
|
||||
sc_digit vd0 = (*vd);
|
||||
|
||||
if ((cmp_res > 0) && (vnd == 1) && (vd0 == 1)) {
|
||||
us = CONVERT_SM_to_2C_to_SM(us, unb, old_und, ud);
|
||||
return;
|
||||
}
|
||||
|
||||
// One extra digit for d is allocated to simplify vec_div_*().
|
||||
int nd = sc_max(und, vnd) + 1;
|
||||
|
||||
#ifdef SC_MAX_NBITS
|
||||
sc_digit d[MAX_NDIGITS + 1];
|
||||
#else
|
||||
sc_digit *d = new sc_digit[nd];
|
||||
#endif
|
||||
|
||||
vec_zero(nd, d);
|
||||
|
||||
// u = v => u / v = 1 - case 3
|
||||
if (cmp_res == 0)
|
||||
d[0] = 1;
|
||||
else if ((vnd == 1) && (und == 1))
|
||||
d[0] = (*ud) / vd0;
|
||||
else if ((vnd == 1) && (vd0 < HALF_DIGIT_RADIX))
|
||||
vec_div_small(und, ud, vd0, d);
|
||||
else
|
||||
vec_div_large(und, ud, vnd, vd, d);
|
||||
|
||||
COPY_DIGITS(us, unb, old_und, ud, sc_max(unb, vnb), nd - 1, d);
|
||||
|
||||
#ifndef SC_MAX_NBITS
|
||||
delete [] d;
|
||||
#endif
|
||||
}
|
||||
#undef COPY_DIGITS
|
||||
#undef CONVERT_SM_to_2C_to_SM
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// SECTION: External functions for MOD operators.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void
|
||||
mod_on_help_signed(small_type &us, int unb, int und, sc_digit *ud,
|
||||
int /* vnb */, int vnd, const sc_digit *vd)
|
||||
{
|
||||
#define COPY_DIGITS copy_digits_signed
|
||||
{ // Body of mod_on_help
|
||||
int old_und = und;
|
||||
|
||||
und = vec_skip_leading_zeros(und, ud);
|
||||
vnd = vec_skip_leading_zeros(vnd, vd);
|
||||
|
||||
int cmp_res = vec_cmp(und, ud, vnd, vd);
|
||||
|
||||
// u < v => u % v = u - case 4
|
||||
if (cmp_res < 0)
|
||||
return;
|
||||
|
||||
// u = v => u % v = 0 - case 3
|
||||
if (cmp_res == 0) {
|
||||
us = SC_ZERO;
|
||||
vec_zero(old_und, ud);
|
||||
return;
|
||||
}
|
||||
// else if u > v - case 5
|
||||
|
||||
sc_digit vd0 = (*vd);
|
||||
|
||||
if ((vnd == 1) && (vd0 == 1)) {
|
||||
us = SC_ZERO;
|
||||
vec_zero(old_und, ud);
|
||||
return;
|
||||
}
|
||||
|
||||
// One extra digit for d is allocated to simplify vec_div_*().
|
||||
int nd = sc_max(und, vnd) + 1;
|
||||
|
||||
#ifdef SC_MAX_NBITS
|
||||
sc_digit d[MAX_NDIGITS + 1];
|
||||
#else
|
||||
sc_digit *d = new sc_digit[nd];
|
||||
#endif
|
||||
|
||||
vec_zero(nd, d);
|
||||
|
||||
if ((vnd == 1) && (und == 1))
|
||||
d[0] = (*ud) % vd0;
|
||||
if ((vnd == 1) && (vd0 < HALF_DIGIT_RADIX))
|
||||
d[0] = vec_rem_small(und, ud, vd0);
|
||||
else
|
||||
vec_rem_large(und, ud, vnd, vd, d);
|
||||
|
||||
us = check_for_zero(us, nd - 1, d);
|
||||
|
||||
if (us == SC_ZERO)
|
||||
vec_zero(old_und, ud);
|
||||
else
|
||||
COPY_DIGITS(us, unb, old_und, ud, sc_min(unb, vnd), nd - 1, d);
|
||||
|
||||
#ifndef SC_MAX_NBITS
|
||||
delete [] d;
|
||||
#endif
|
||||
}
|
||||
#undef COPY_DIGITS
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
mod_on_help_unsigned(small_type &us, int unb, int und, sc_digit *ud,
|
||||
int /* vnb */, int vnd, const sc_digit *vd)
|
||||
{
|
||||
#define COPY_DIGITS copy_digits_unsigned
|
||||
{ // Body of mod_on_help
|
||||
int old_und = und;
|
||||
|
||||
und = vec_skip_leading_zeros(und, ud);
|
||||
vnd = vec_skip_leading_zeros(vnd, vd);
|
||||
|
||||
int cmp_res = vec_cmp(und, ud, vnd, vd);
|
||||
|
||||
// u < v => u % v = u - case 4
|
||||
if (cmp_res < 0)
|
||||
return;
|
||||
|
||||
// u = v => u % v = 0 - case 3
|
||||
if (cmp_res == 0) {
|
||||
us = SC_ZERO;
|
||||
vec_zero(old_und, ud);
|
||||
return;
|
||||
}
|
||||
|
||||
// else if u > v - case 5
|
||||
|
||||
sc_digit vd0 = (*vd);
|
||||
|
||||
if ((vnd == 1) && (vd0 == 1)) {
|
||||
us = SC_ZERO;
|
||||
vec_zero(old_und, ud);
|
||||
return;
|
||||
}
|
||||
|
||||
// One extra digit for d is allocated to simplify vec_div_*().
|
||||
int nd = sc_max(und, vnd) + 1;
|
||||
|
||||
#ifdef SC_MAX_NBITS
|
||||
sc_digit d[MAX_NDIGITS + 1];
|
||||
#else
|
||||
sc_digit *d = new sc_digit[nd];
|
||||
#endif
|
||||
|
||||
vec_zero(nd, d);
|
||||
|
||||
if ((vnd == 1) && (und == 1))
|
||||
d[0] = (*ud) % vd0;
|
||||
if ((vnd == 1) && (vd0 < HALF_DIGIT_RADIX))
|
||||
d[0] = vec_rem_small(und, ud, vd0);
|
||||
else
|
||||
vec_rem_large(und, ud, vnd, vd, d);
|
||||
|
||||
us = check_for_zero(us, nd - 1, d);
|
||||
|
||||
if (us == SC_ZERO)
|
||||
vec_zero(old_und, ud);
|
||||
else
|
||||
COPY_DIGITS(us, unb, old_und, ud, sc_min(unb, vnd), nd - 1, d);
|
||||
|
||||
#ifndef SC_MAX_NBITS
|
||||
delete [] d;
|
||||
#endif
|
||||
}
|
||||
#undef COPY_DIGITS
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// SECTION: External functions for AND operators.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Handles the cases 2-5 and returns the result in u.
|
||||
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)
|
||||
{
|
||||
sc_digit *x = ud;
|
||||
const sc_digit *y = vd;
|
||||
int xnd = und;
|
||||
int ynd = vnd;
|
||||
|
||||
// Truncate y.
|
||||
if (xnd < ynd)
|
||||
ynd = xnd;
|
||||
|
||||
const sc_digit *xend = (x + xnd);
|
||||
const sc_digit *yend = (y + ynd);
|
||||
|
||||
// x is longer than y.
|
||||
small_type s = mul_signs(us, vs);
|
||||
|
||||
if (s > 0) {
|
||||
if (us > 0) { // case 2
|
||||
while (y < yend)
|
||||
(*x++) &= (*y++);
|
||||
while (x < xend)
|
||||
(*x++) = 0;
|
||||
} else { // case 3
|
||||
sc_digit xcarry = 1;
|
||||
sc_digit ycarry = 1;
|
||||
while (y < yend) {
|
||||
xcarry += (~(*x) & DIGIT_MASK);
|
||||
ycarry += (~(*y++) & DIGIT_MASK);
|
||||
(*x++) = (xcarry & ycarry) & DIGIT_MASK;
|
||||
xcarry >>= BITS_PER_DIGIT;
|
||||
ycarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
while (x < xend) {
|
||||
xcarry += (~(*x) & DIGIT_MASK);
|
||||
ycarry += DIGIT_MASK;
|
||||
(*x++) = (xcarry & ycarry) & DIGIT_MASK;
|
||||
xcarry >>= BITS_PER_DIGIT;
|
||||
ycarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
if (us > 0) { // case 4
|
||||
sc_digit ycarry = 1;
|
||||
while (y < yend) {
|
||||
ycarry += (~(*y++) & DIGIT_MASK);
|
||||
(*x++) &= ycarry & DIGIT_MASK;
|
||||
ycarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
while (x < xend) {
|
||||
ycarry += DIGIT_MASK;
|
||||
(*x++) &= ycarry & DIGIT_MASK;
|
||||
ycarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
} else { // case 5
|
||||
sc_digit xcarry = 1;
|
||||
while (y < yend) {
|
||||
xcarry += (~(*x) & DIGIT_MASK);
|
||||
(*x++) = (xcarry & (*y++)) & DIGIT_MASK;
|
||||
xcarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
while (x < xend)
|
||||
(*x++) = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// SECTION: External functions for OR operators.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Handles the cases 3-5 and returns the result in u.
|
||||
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)
|
||||
{
|
||||
sc_digit *x = ud;
|
||||
const sc_digit *y = vd;
|
||||
int xnd = und;
|
||||
int ynd = vnd;
|
||||
|
||||
if (xnd < ynd)
|
||||
ynd = xnd;
|
||||
|
||||
const sc_digit *xend = (x + xnd);
|
||||
const sc_digit *yend = (y + ynd);
|
||||
|
||||
// x is longer than y.
|
||||
small_type s = mul_signs(us, vs);
|
||||
|
||||
if (s > 0) {
|
||||
if (us > 0) { // case 3
|
||||
while (y < yend)
|
||||
(*x++) |= (*y++);
|
||||
// No change for the rest of x.
|
||||
} else { // case 4
|
||||
sc_digit xcarry = 1;
|
||||
sc_digit ycarry = 1;
|
||||
while (y < yend) {
|
||||
xcarry += (~(*x) & DIGIT_MASK);
|
||||
ycarry += (~(*y++) & DIGIT_MASK);
|
||||
(*x++) = (xcarry | ycarry) & DIGIT_MASK;
|
||||
xcarry >>= BITS_PER_DIGIT;
|
||||
ycarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
while (x < xend) {
|
||||
xcarry += (~(*x) & DIGIT_MASK);
|
||||
ycarry += DIGIT_MASK;
|
||||
(*x++) = (xcarry | ycarry) & DIGIT_MASK;
|
||||
xcarry >>= BITS_PER_DIGIT;
|
||||
ycarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (us > 0) { // case 5
|
||||
sc_digit ycarry = 1;
|
||||
while (y < yend) {
|
||||
ycarry += (~(*y++) & DIGIT_MASK);
|
||||
(*x) = ((*x) | ycarry) & DIGIT_MASK;
|
||||
x++;
|
||||
ycarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
while (x < xend) {
|
||||
ycarry += DIGIT_MASK;
|
||||
(*x) = ((*x) | ycarry) & DIGIT_MASK;
|
||||
x++;
|
||||
ycarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
} else { // case 6
|
||||
sc_digit xcarry = 1;
|
||||
while (y < yend) {
|
||||
xcarry += (~(*x) & DIGIT_MASK);
|
||||
(*x++) = (xcarry | (*y++)) & DIGIT_MASK;
|
||||
xcarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
while (x < xend) {
|
||||
xcarry += (~(*x) & DIGIT_MASK);
|
||||
(*x++) = xcarry & DIGIT_MASK;
|
||||
xcarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// SECTION: External functions for XOR operators.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Handles the cases 3-5 and returns the result in u.
|
||||
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)
|
||||
{
|
||||
sc_digit *x = ud;
|
||||
const sc_digit *y = vd;
|
||||
int xnd = und;
|
||||
int ynd = vnd;
|
||||
|
||||
if (xnd < ynd)
|
||||
ynd = xnd;
|
||||
|
||||
const sc_digit *xend = (x + xnd);
|
||||
const sc_digit *yend = (y + ynd);
|
||||
|
||||
// x is longer than y.
|
||||
small_type s = mul_signs(us, vs);
|
||||
|
||||
if (s > 0) {
|
||||
if (us > 0) { // case 3
|
||||
while (y < yend) {
|
||||
(*x) = ((*x) ^ (*y)) & DIGIT_MASK;
|
||||
x++;
|
||||
y++;
|
||||
}
|
||||
// No change for the rest of x.
|
||||
} else { // case 4
|
||||
sc_digit xcarry = 1;
|
||||
sc_digit ycarry = 1;
|
||||
while (y < yend) {
|
||||
xcarry += (~(*x) & DIGIT_MASK);
|
||||
ycarry += (~(*y++) & DIGIT_MASK);
|
||||
(*x++) = (xcarry ^ ycarry) & DIGIT_MASK;
|
||||
xcarry >>= BITS_PER_DIGIT;
|
||||
ycarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
while (x < xend) {
|
||||
xcarry += (~(*x) & DIGIT_MASK);
|
||||
ycarry += DIGIT_MASK;
|
||||
(*x++) = (xcarry ^ ycarry) & DIGIT_MASK;
|
||||
xcarry >>= BITS_PER_DIGIT;
|
||||
ycarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (us > 0) { // case 5
|
||||
sc_digit ycarry = 1;
|
||||
while (y < yend) {
|
||||
ycarry += (~(*y++) & DIGIT_MASK);
|
||||
(*x) = ((*x) ^ ycarry) & DIGIT_MASK;
|
||||
x++;
|
||||
ycarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
while (x < xend) {
|
||||
ycarry += DIGIT_MASK;
|
||||
(*x) = ((*x) ^ ycarry) & DIGIT_MASK;
|
||||
x++;
|
||||
ycarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
} else { // case 6
|
||||
sc_digit xcarry = 1;
|
||||
while (y < yend) {
|
||||
xcarry += (~(*x) & DIGIT_MASK);
|
||||
(*x++) = (xcarry ^ (*y++)) & DIGIT_MASK;
|
||||
xcarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
while (x < xend) {
|
||||
xcarry += (~(*x) & DIGIT_MASK);
|
||||
(*x++) = xcarry & DIGIT_MASK;
|
||||
xcarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sc_dt
|
||||
582
src/systemc/dt/int/sc_nbfriends.inc
Normal file
582
src/systemc/dt/int/sc_nbfriends.inc
Normal file
@@ -0,0 +1,582 @@
|
||||
/*****************************************************************************
|
||||
|
||||
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_nbfriends.inc -- Friend functions for both sc_signed and sc_unsigned
|
||||
classes. The vec_* functions are called through either
|
||||
these functions or those in sc_nbexterns.cpp. These
|
||||
functions perform their work on two inputs u and v, and
|
||||
return the result object. The functions in
|
||||
sc_nbexterns.cpp perform their work on one of their
|
||||
inputs.
|
||||
|
||||
The functions here try to use faster algorithms in case
|
||||
the input numbers are small. The bitwise functions (and,
|
||||
or, and xor) need the 2's complement representations of
|
||||
their inputs. Instead of complementing their inputs
|
||||
first and then processing, they complement their inputs
|
||||
while processing without allocating extra temporary
|
||||
memory.
|
||||
|
||||
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:
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Naming conventions:
|
||||
// For sc_signed or sc_unsigned number u:
|
||||
// us : u's sign, unb : u's number of bits,
|
||||
// und : u's number of digits, ud : u's digits array.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// SECTION: Friend functions for PLUS operators.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Handles cases 3 and 4 and returns the result.
|
||||
CLASS_TYPE
|
||||
ADD_HELPER(small_type us, int unb, int und, const sc_digit *ud,
|
||||
small_type vs, int vnb, int vnd, const sc_digit *vd)
|
||||
{
|
||||
und = vec_skip_leading_zeros(und, ud);
|
||||
vnd = vec_skip_leading_zeros(vnd, vd);
|
||||
|
||||
int nb = sc_max(unb, vnb);
|
||||
int nd = sc_max(und, vnd) + 1;
|
||||
|
||||
#ifdef SC_MAX_NBITS
|
||||
test_bound(nb);
|
||||
sc_digit d[MAX_NDIGITS];
|
||||
#else
|
||||
sc_digit *d = new sc_digit[nd];
|
||||
#endif
|
||||
|
||||
d[nd - 1] = d[nd - 2] = 0;
|
||||
|
||||
// case 3
|
||||
if (us == vs) {
|
||||
|
||||
++nb;
|
||||
|
||||
if ((und == 1) && (vnd == 1)) {
|
||||
sc_digit carry = (*ud) + (*vd);
|
||||
d[0] = carry & DIGIT_MASK;
|
||||
d[1] = carry >> BITS_PER_DIGIT;
|
||||
} else if (und >= vnd) {
|
||||
vec_add(und, ud, vnd, vd, d);
|
||||
} else {
|
||||
vec_add(vnd, vd, und, ud, d);
|
||||
}
|
||||
} else {
|
||||
// case 4
|
||||
int cmp_res = vec_cmp(und, ud, vnd, vd);
|
||||
|
||||
if (cmp_res == 0) { // u == v
|
||||
#ifndef SC_MAX_NBITS
|
||||
delete[] d;
|
||||
#endif
|
||||
return CLASS_TYPE();
|
||||
}
|
||||
|
||||
if (cmp_res > 0) { // u > v
|
||||
if ((und == 1) && (vnd == 1))
|
||||
d[0] = (*ud) - (*vd);
|
||||
else
|
||||
vec_sub(und, ud, vnd, vd, d);
|
||||
} else { // u < v
|
||||
us = -us;
|
||||
if ((und == 1) && (vnd == 1))
|
||||
d[0] = (*vd) - (*ud);
|
||||
else
|
||||
vec_sub(vnd, vd, und, ud, d);
|
||||
}
|
||||
}
|
||||
return CLASS_TYPE(us, nb, nd, d);
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// SECTION: Friend functions of MULTIPLICATION operators.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Handles the case 4 and returns the result.
|
||||
CLASS_TYPE
|
||||
MUL_HELPER(small_type s, int unb, int und, const sc_digit *ud,
|
||||
int vnb, int vnd, const sc_digit *vd)
|
||||
{
|
||||
und = vec_skip_leading_zeros(und, ud);
|
||||
vnd = vec_skip_leading_zeros(vnd, vd);
|
||||
|
||||
int nb = unb + vnb;
|
||||
int nd = und + vnd;
|
||||
|
||||
#ifdef SC_MAX_NBITS
|
||||
test_bound(nb);
|
||||
sc_digit d[MAX_NDIGITS];
|
||||
#else
|
||||
sc_digit *d = new sc_digit[nd];
|
||||
#endif
|
||||
|
||||
vec_zero(nd, d);
|
||||
|
||||
sc_digit ud0 = (*ud);
|
||||
sc_digit vd0 = (*vd);
|
||||
|
||||
if ((vnd == 1) && (vd0 == 1)) {
|
||||
vec_copy(und, d, ud);
|
||||
} else if ((und == 1) && (ud0 == 1)) {
|
||||
vec_copy(vnd, d, vd);
|
||||
} else if ((und == 1) && (vnd == 1) &&
|
||||
(ud0 < HALF_DIGIT_RADIX) && (vd0 < HALF_DIGIT_RADIX)) {
|
||||
d[0] = ud0 * vd0;
|
||||
} else if ((und == 1) && (ud0 < HALF_DIGIT_RADIX)) {
|
||||
vec_mul_small(vnd, vd, ud0, d);
|
||||
} else if ((vnd == 1) && (vd0 < HALF_DIGIT_RADIX)) {
|
||||
vec_mul_small(und, ud, vd0, d);
|
||||
} else if (vnd < und) {
|
||||
vec_mul(und, ud, vnd, vd, d);
|
||||
} else {
|
||||
vec_mul(vnd, vd, und, ud, d);
|
||||
}
|
||||
return CLASS_TYPE(s, nb, nd, d);
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// SECTION: Friend functions for DIVISION operators.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Handles the cases 3-4 and returns the result.
|
||||
CLASS_TYPE
|
||||
DIV_HELPER(small_type s, int unb, int und, const sc_digit *ud,
|
||||
int vnb, int vnd, const sc_digit *vd)
|
||||
{
|
||||
und = vec_skip_leading_zeros(und, ud);
|
||||
vnd = vec_skip_leading_zeros(vnd, vd);
|
||||
|
||||
int cmp_res = vec_cmp(und, ud, vnd, vd);
|
||||
|
||||
// u < v => u / v = 0 - case 4
|
||||
if (cmp_res < 0)
|
||||
return CLASS_TYPE();
|
||||
|
||||
// One extra digit for d is allocated to simplify vec_div_*().
|
||||
int nd = sc_max(und, vnd) + 1;
|
||||
|
||||
#ifdef SC_MAX_NBITS
|
||||
sc_digit d[MAX_NDIGITS + 1];
|
||||
#else
|
||||
sc_digit *d = new sc_digit[nd];
|
||||
#endif
|
||||
|
||||
vec_zero(nd, d);
|
||||
sc_digit vd0 = (*vd);
|
||||
|
||||
// u = v => u / v = 1 - case 3
|
||||
if (cmp_res == 0) {
|
||||
d[0] = 1;
|
||||
// else if u > v - case 5
|
||||
} else if ((vnd == 1) && (vd0 == 1)) {
|
||||
vec_copy(und, d, ud);
|
||||
} else if ((vnd == 1) && (und == 1)) {
|
||||
d[0] = (*ud) / vd0;
|
||||
} else if ((vnd == 1) && (vd0 < HALF_DIGIT_RADIX)) {
|
||||
vec_div_small(und, ud, vd0, d);
|
||||
} else {
|
||||
vec_div_large(und, ud, vnd, vd, d);
|
||||
}
|
||||
|
||||
return CLASS_TYPE(s, sc_max(unb, vnb), nd - 1, d);
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// SECTION: Friend functions for MOD operators.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Handles the cases 3-4 and returns the result.
|
||||
CLASS_TYPE
|
||||
MOD_HELPER(small_type us, int unb, int und, const sc_digit *ud,
|
||||
int vnb, int vnd, const sc_digit *vd)
|
||||
{
|
||||
und = vec_skip_leading_zeros(und, ud);
|
||||
vnd = vec_skip_leading_zeros(vnd, vd);
|
||||
|
||||
int cmp_res = vec_cmp(und, ud, vnd, vd);
|
||||
// u = v => u % v = 0 - case 3
|
||||
if (cmp_res == 0)
|
||||
return CLASS_TYPE();
|
||||
|
||||
sc_digit vd0 = (*vd);
|
||||
if ((cmp_res > 0) && (vnd == 1) && (vd0 == 1))
|
||||
return CLASS_TYPE();
|
||||
|
||||
// One extra digit for d is allocated to simplify vec_div_*().
|
||||
int nd = sc_max(und, vnd) + 1;
|
||||
|
||||
#ifdef SC_MAX_NBITS
|
||||
sc_digit d[MAX_NDIGITS + 1];
|
||||
#else
|
||||
sc_digit *d = new sc_digit[nd];
|
||||
#endif
|
||||
|
||||
vec_zero(nd, d);
|
||||
|
||||
// u < v => u % v = u - case 4
|
||||
if (cmp_res < 0) {
|
||||
vec_copy(und, d, ud);
|
||||
// else if u > v - case 5
|
||||
} else if ((vnd == 1) && (und == 1)) {
|
||||
d[0] = (*ud) % vd0;
|
||||
} else if ((vnd == 1) && (vd0 < HALF_DIGIT_RADIX)) {
|
||||
d[0] = vec_rem_small(und, ud, vd0);
|
||||
} else {
|
||||
vec_rem_large(und, ud, vnd, vd, d);
|
||||
}
|
||||
|
||||
us = check_for_zero(us, nd - 1, d);
|
||||
|
||||
if (us == SC_ZERO) {
|
||||
#ifndef SC_MAX_NBITS
|
||||
delete[] d;
|
||||
#endif
|
||||
return CLASS_TYPE();
|
||||
} else {
|
||||
return CLASS_TYPE(us, sc_min(unb, vnb), nd - 1, d);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// SECTION: Friend functions for AND operators.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Handles the cases 2-5 and returns the result.
|
||||
CLASS_TYPE
|
||||
AND_HELPER(small_type us, int unb, int und, const sc_digit *ud,
|
||||
small_type vs, int vnb, int vnd, const sc_digit *vd)
|
||||
{
|
||||
int nb = sc_max(unb, vnb);
|
||||
int nd = sc_max(und, vnd);
|
||||
|
||||
#ifdef SC_MAX_NBITS
|
||||
sc_digit dbegin[MAX_NDIGITS];
|
||||
#else
|
||||
sc_digit *dbegin = new sc_digit[nd];
|
||||
#endif
|
||||
|
||||
sc_digit *d = dbegin;
|
||||
|
||||
const sc_digit *x;
|
||||
const sc_digit *y;
|
||||
int xnd;
|
||||
int ynd;
|
||||
small_type xs;
|
||||
small_type ys;
|
||||
|
||||
if (und >= vnd) {
|
||||
x = ud;
|
||||
y = vd;
|
||||
xnd = und;
|
||||
ynd = vnd;
|
||||
xs = us;
|
||||
ys = vs;
|
||||
} else {
|
||||
y = ud;
|
||||
x = vd;
|
||||
ynd = und;
|
||||
xnd = vnd;
|
||||
ys = us;
|
||||
xs = vs;
|
||||
}
|
||||
|
||||
const sc_digit *xend = (x + xnd);
|
||||
const sc_digit *yend = (y + ynd);
|
||||
|
||||
// x is longer than y.
|
||||
small_type s = mul_signs(xs, ys);
|
||||
if (s > 0) {
|
||||
if (xs > 0) { // case 2
|
||||
while (y < yend)
|
||||
(*d++) = (*x++) & (*y++);
|
||||
while (x++ < xend)
|
||||
(*d++) = 0;
|
||||
} else { // case 3
|
||||
sc_digit xcarry = 1;
|
||||
sc_digit ycarry = 1;
|
||||
while (y < yend) {
|
||||
xcarry += (~(*x++) & DIGIT_MASK);
|
||||
ycarry += (~(*y++) & DIGIT_MASK);
|
||||
(*d++) = (xcarry & ycarry) & DIGIT_MASK;
|
||||
xcarry >>= BITS_PER_DIGIT;
|
||||
ycarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
while (x < xend) {
|
||||
xcarry += (~(*x++) & DIGIT_MASK);
|
||||
ycarry += DIGIT_MASK;
|
||||
(*d++) = (xcarry & ycarry) & DIGIT_MASK;
|
||||
xcarry >>= BITS_PER_DIGIT;
|
||||
ycarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (xs > 0) { // case 4
|
||||
sc_digit ycarry = 1;
|
||||
while (y < yend) {
|
||||
ycarry += (~(*y++) & DIGIT_MASK);
|
||||
(*d++) = ((*x++) & ycarry) & DIGIT_MASK;
|
||||
ycarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
while (x < xend) {
|
||||
ycarry += DIGIT_MASK;
|
||||
(*d++) = ((*x++) & ycarry) & DIGIT_MASK;
|
||||
ycarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
} else { // case 5
|
||||
sc_digit xcarry = 1;
|
||||
while (y < yend) {
|
||||
xcarry += (~(*x++) & DIGIT_MASK);
|
||||
(*d++) = (xcarry & (*y++)) & DIGIT_MASK;
|
||||
xcarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
while (x++ < xend)
|
||||
(*d++) = 0;
|
||||
}
|
||||
}
|
||||
s = convert_signed_2C_to_SM(nb, nd, dbegin);
|
||||
return CLASS_TYPE(s, nb, nd, dbegin);
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// SECTION: Friend functions for OR operators.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Handles the cases 3-5 and returns the result.
|
||||
CLASS_TYPE
|
||||
OR_HELPER(small_type us, int unb, int und, const sc_digit *ud,
|
||||
small_type vs, int vnb, int vnd, const sc_digit *vd)
|
||||
{
|
||||
int nb = sc_max(unb, vnb);
|
||||
int nd = sc_max(und, vnd);
|
||||
|
||||
#ifdef SC_MAX_NBITS
|
||||
sc_digit dbegin[MAX_NDIGITS];
|
||||
#else
|
||||
sc_digit *dbegin = new sc_digit[nd];
|
||||
#endif
|
||||
sc_digit *d = dbegin;
|
||||
const sc_digit *x;
|
||||
const sc_digit *y;
|
||||
int xnd;
|
||||
int ynd;
|
||||
small_type xs;
|
||||
small_type ys;
|
||||
|
||||
if (und >= vnd) {
|
||||
x = ud;
|
||||
y = vd;
|
||||
xnd = und;
|
||||
ynd = vnd;
|
||||
xs = us;
|
||||
ys = vs;
|
||||
} else {
|
||||
y = ud;
|
||||
x = vd;
|
||||
ynd = und;
|
||||
xnd = vnd;
|
||||
ys = us;
|
||||
xs = vs;
|
||||
}
|
||||
|
||||
const sc_digit *xend = (x + xnd);
|
||||
const sc_digit *yend = (y + ynd);
|
||||
|
||||
// x is longer than y.
|
||||
small_type s = mul_signs(xs, ys);
|
||||
if (s > 0) {
|
||||
if (xs > 0) { // case 3
|
||||
while (y < yend)
|
||||
(*d++) = (*x++) | (*y++);
|
||||
while (x < xend)
|
||||
(*d++) = (*x++);
|
||||
} else { // case 4
|
||||
sc_digit xcarry = 1;
|
||||
sc_digit ycarry = 1;
|
||||
while (y < yend) {
|
||||
xcarry += (~(*x++) & DIGIT_MASK);
|
||||
ycarry += (~(*y++) & DIGIT_MASK);
|
||||
(*d++) = (xcarry | ycarry) & DIGIT_MASK;
|
||||
xcarry >>= BITS_PER_DIGIT;
|
||||
ycarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
while (x < xend) {
|
||||
xcarry += (~(*x++) & DIGIT_MASK);
|
||||
ycarry += DIGIT_MASK;
|
||||
(*d++) = (xcarry | ycarry) & DIGIT_MASK;
|
||||
xcarry >>= BITS_PER_DIGIT;
|
||||
ycarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (xs > 0) { // case 5
|
||||
sc_digit ycarry = 1;
|
||||
while (y < yend) {
|
||||
ycarry += (~(*y++) & DIGIT_MASK);
|
||||
(*d++) = ((*x++) | ycarry) & DIGIT_MASK;
|
||||
ycarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
while (x < xend) {
|
||||
ycarry += DIGIT_MASK;
|
||||
(*d++) = ((*x++) | ycarry) & DIGIT_MASK;
|
||||
ycarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
} else { // case 6
|
||||
sc_digit xcarry = 1;
|
||||
while (y < yend) {
|
||||
xcarry += (~(*x++) & DIGIT_MASK);
|
||||
(*d++) = (xcarry | (*y++)) & DIGIT_MASK;
|
||||
xcarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
while (x < xend) {
|
||||
xcarry += (~(*x++) & DIGIT_MASK);
|
||||
(*d++) = xcarry & DIGIT_MASK;
|
||||
xcarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
}
|
||||
}
|
||||
s = convert_signed_2C_to_SM(nb, nd, dbegin);
|
||||
return CLASS_TYPE(s, nb, nd, dbegin);
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// SECTION: Friend functions for XOR operators.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Handles the cases 3-5 and returns the result.
|
||||
CLASS_TYPE
|
||||
XOR_HELPER(small_type us, int unb, int und, const sc_digit *ud,
|
||||
small_type vs, int vnb, int vnd, const sc_digit *vd)
|
||||
{
|
||||
int nb = sc_max(unb, vnb);
|
||||
int nd = sc_max(und, vnd);
|
||||
|
||||
#ifdef SC_MAX_NBITS
|
||||
sc_digit dbegin[MAX_NDIGITS];
|
||||
#else
|
||||
sc_digit *dbegin = new sc_digit[nd];
|
||||
#endif
|
||||
|
||||
sc_digit *d = dbegin;
|
||||
|
||||
const sc_digit *x;
|
||||
const sc_digit *y;
|
||||
int xnd;
|
||||
int ynd;
|
||||
small_type xs;
|
||||
small_type ys;
|
||||
|
||||
if (und >= vnd) {
|
||||
x = ud;
|
||||
y = vd;
|
||||
xnd = und;
|
||||
ynd = vnd;
|
||||
xs = us;
|
||||
ys = vs;
|
||||
} else {
|
||||
y = ud;
|
||||
x = vd;
|
||||
ynd = und;
|
||||
xnd = vnd;
|
||||
ys = us;
|
||||
xs = vs;
|
||||
}
|
||||
|
||||
const sc_digit *xend = (x + xnd);
|
||||
const sc_digit *yend = (y + ynd);
|
||||
|
||||
// x is longer than y.
|
||||
small_type s = mul_signs(xs, ys);
|
||||
if (s > 0) {
|
||||
if (xs > 0) { // case 3
|
||||
while (y < yend)
|
||||
(*d++) = ((*x++) ^ (*y++)) & DIGIT_MASK;
|
||||
while (x < xend)
|
||||
(*d++) = (*x++);
|
||||
} else { // case 4
|
||||
sc_digit xcarry = 1;
|
||||
sc_digit ycarry = 1;
|
||||
while (y < yend) {
|
||||
xcarry += (~(*x++) & DIGIT_MASK);
|
||||
ycarry += (~(*y++) & DIGIT_MASK);
|
||||
(*d++) = (xcarry ^ ycarry) & DIGIT_MASK;
|
||||
xcarry >>= BITS_PER_DIGIT;
|
||||
ycarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
while (x < xend) {
|
||||
xcarry += (~(*x++) & DIGIT_MASK);
|
||||
ycarry += DIGIT_MASK;
|
||||
(*d++) = (xcarry ^ ycarry) & DIGIT_MASK;
|
||||
xcarry >>= BITS_PER_DIGIT;
|
||||
ycarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (xs > 0) { // case 5
|
||||
sc_digit ycarry = 1;
|
||||
while (y < yend) {
|
||||
ycarry += (~(*y++) & DIGIT_MASK);
|
||||
(*d++) = ((*x++) ^ ycarry) & DIGIT_MASK;
|
||||
ycarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
while (x < xend) {
|
||||
ycarry += DIGIT_MASK;
|
||||
(*d++) = ((*x++) ^ ycarry) & DIGIT_MASK;
|
||||
ycarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
} else { // case 6
|
||||
sc_digit xcarry = 1;
|
||||
while (y < yend) {
|
||||
xcarry += (~(*x++) & DIGIT_MASK);
|
||||
(*d++) = (xcarry ^ (*y++)) & DIGIT_MASK;
|
||||
xcarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
while (x < xend) {
|
||||
xcarry += (~(*x++) & DIGIT_MASK);
|
||||
(*d++) = xcarry & DIGIT_MASK;
|
||||
xcarry >>= BITS_PER_DIGIT;
|
||||
}
|
||||
}
|
||||
}
|
||||
s = convert_signed_2C_to_SM(nb, nd, dbegin);
|
||||
return CLASS_TYPE(s, nb, nd, dbegin);
|
||||
}
|
||||
1749
src/systemc/dt/int/sc_nbutils.cc
Normal file
1749
src/systemc/dt/int/sc_nbutils.cc
Normal file
File diff suppressed because it is too large
Load Diff
3982
src/systemc/dt/int/sc_signed.cc
Normal file
3982
src/systemc/dt/int/sc_signed.cc
Normal file
File diff suppressed because it is too large
Load Diff
163
src/systemc/dt/int/sc_signed_bitref.inc
Normal file
163
src/systemc/dt/int/sc_signed_bitref.inc
Normal file
@@ -0,0 +1,163 @@
|
||||
/*****************************************************************************
|
||||
|
||||
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_signed_bitref.h -- Proxy class that is declared in sc_signed.h.
|
||||
|
||||
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:
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_signed_bitref_r
|
||||
//
|
||||
// Proxy class for sc_signed bit selection (r-value only).
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// implicit conversion to uint64
|
||||
|
||||
sc_signed_bitref_r::operator uint64 () const
|
||||
{
|
||||
return m_obj_p->test(m_index);
|
||||
}
|
||||
|
||||
bool
|
||||
sc_signed_bitref_r::operator ! () const
|
||||
{
|
||||
return (!m_obj_p->test(m_index));
|
||||
}
|
||||
|
||||
bool
|
||||
sc_signed_bitref_r::operator ~ () const
|
||||
{
|
||||
return (!m_obj_p->test(m_index));
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_signed_bitref
|
||||
//
|
||||
// Proxy class for sc_signed bit selection (r-value and l-value).
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// assignment operators
|
||||
|
||||
const sc_signed_bitref &
|
||||
sc_signed_bitref::operator = (const sc_signed_bitref_r &b)
|
||||
{
|
||||
m_obj_p->set(m_index, (bool)b);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const sc_signed_bitref &
|
||||
sc_signed_bitref::operator = (const sc_signed_bitref &b)
|
||||
{
|
||||
m_obj_p->set(m_index, (bool)b);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const sc_signed_bitref &
|
||||
sc_signed_bitref::operator = (bool b)
|
||||
{
|
||||
m_obj_p->set(m_index, b);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
const sc_signed_bitref &
|
||||
sc_signed_bitref::operator &= (bool b)
|
||||
{
|
||||
if (!b) {
|
||||
m_obj_p->clear(m_index);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
const sc_signed_bitref &
|
||||
sc_signed_bitref::operator |= (bool b)
|
||||
{
|
||||
if (b) {
|
||||
m_obj_p->set(m_index);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
const sc_signed_bitref &
|
||||
sc_signed_bitref::operator ^= (bool b)
|
||||
{
|
||||
if (b) {
|
||||
m_obj_p->invert(m_index);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// #### OPTIMIZE
|
||||
void
|
||||
sc_signed_bitref::concat_set(int64 src, int low_i)
|
||||
{
|
||||
bool value = 1 & ((low_i < 64) ? (src >> low_i) : (src >> 63));
|
||||
m_obj_p->set(low_i, value);
|
||||
}
|
||||
|
||||
void
|
||||
sc_signed_bitref::concat_set(const sc_signed &src, int low_i)
|
||||
{
|
||||
if (low_i < src.length())
|
||||
m_obj_p->set(low_i, src.test(low_i));
|
||||
else
|
||||
m_obj_p->set(low_i, src < 0);
|
||||
}
|
||||
|
||||
void
|
||||
sc_signed_bitref::concat_set(const sc_unsigned &src, int low_i)
|
||||
{
|
||||
if (low_i < src.length())
|
||||
m_obj_p->set(low_i, src.test(low_i));
|
||||
else
|
||||
m_obj_p->set(low_i, 0);
|
||||
}
|
||||
|
||||
void
|
||||
sc_signed_bitref::concat_set(uint64 src, int low_i)
|
||||
{
|
||||
bool value = 1 & ((low_i < 64) ? (src >> low_i) : 0);
|
||||
m_obj_p->set(low_i, value);
|
||||
}
|
||||
|
||||
|
||||
// other methods
|
||||
void
|
||||
sc_signed_bitref::scan(::std::istream &is)
|
||||
{
|
||||
bool b;
|
||||
is >> b;
|
||||
*this = b;
|
||||
}
|
||||
402
src/systemc/dt/int/sc_signed_subref.inc
Normal file
402
src/systemc/dt/int/sc_signed_subref.inc
Normal file
@@ -0,0 +1,402 @@
|
||||
/*****************************************************************************
|
||||
|
||||
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_signed_subref.h -- Proxy class that is declared in sc_signed.h.
|
||||
|
||||
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:
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_signed_subref_r
|
||||
//
|
||||
// Proxy class for sc_signed part selection (r-value only).
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// concatenation support
|
||||
|
||||
uint64
|
||||
sc_signed_subref_r::concat_get_uint64() const
|
||||
{
|
||||
sc_unsigned a(m_obj_p, m_left, m_right);
|
||||
return a.to_uint64();
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
sc_signed_subref_r::concat_get_ctrl(sc_digit *dst_p, int low_i) const
|
||||
{
|
||||
sc_unsigned a(m_obj_p, m_left, m_right);
|
||||
return a.concat_get_ctrl(dst_p, low_i);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
sc_signed_subref_r::concat_get_data(sc_digit *dst_p, int low_i) const
|
||||
{
|
||||
sc_unsigned a(m_obj_p, m_left, m_right);
|
||||
return a.concat_get_data(dst_p, low_i);
|
||||
}
|
||||
|
||||
|
||||
// implicit conversion to sc_signed
|
||||
sc_signed_subref_r::operator sc_unsigned () const
|
||||
{
|
||||
return sc_unsigned(m_obj_p, m_left, m_right);
|
||||
}
|
||||
|
||||
|
||||
// explicit conversions
|
||||
int
|
||||
sc_signed_subref_r::to_int() const
|
||||
{
|
||||
sc_unsigned a(m_obj_p, m_left, m_right);
|
||||
return a.to_int();
|
||||
}
|
||||
|
||||
unsigned int
|
||||
sc_signed_subref_r::to_uint() const
|
||||
{
|
||||
sc_unsigned a(m_obj_p, m_left, m_right);
|
||||
return a.to_uint();
|
||||
}
|
||||
|
||||
long
|
||||
sc_signed_subref_r::to_long() const
|
||||
{
|
||||
sc_unsigned a(m_obj_p, m_left, m_right);
|
||||
return a.to_long();
|
||||
}
|
||||
|
||||
unsigned long
|
||||
sc_signed_subref_r::to_ulong() const
|
||||
{
|
||||
sc_unsigned a(m_obj_p, m_left, m_right);
|
||||
return a.to_ulong();
|
||||
}
|
||||
|
||||
int64
|
||||
sc_signed_subref_r::to_int64() const
|
||||
{
|
||||
sc_unsigned a(m_obj_p, m_left, m_right);
|
||||
return a.to_int64();
|
||||
}
|
||||
|
||||
uint64
|
||||
sc_signed_subref_r::to_uint64() const
|
||||
{
|
||||
sc_unsigned a(m_obj_p, m_left, m_right);
|
||||
return a.to_uint64();
|
||||
}
|
||||
|
||||
double
|
||||
sc_signed_subref_r::to_double() const
|
||||
{
|
||||
sc_unsigned a(m_obj_p, m_left, m_right);
|
||||
return a.to_double();
|
||||
}
|
||||
|
||||
|
||||
// explicit conversion to character string
|
||||
const std::string
|
||||
sc_signed_subref_r::to_string(sc_numrep numrep) const
|
||||
{
|
||||
sc_unsigned a(length());
|
||||
a = *this;
|
||||
return a.to_string(numrep);
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_signed_subref_r::to_string(sc_numrep numrep, bool w_prefix) const
|
||||
{
|
||||
sc_unsigned a(length());
|
||||
a = *this;
|
||||
return a.to_string(numrep, w_prefix);
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_signed_subref
|
||||
//
|
||||
// Proxy class for sc_signed part selection (r-value and l-value).
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// assignment operators
|
||||
|
||||
const sc_signed_subref &
|
||||
sc_signed_subref::operator = (const sc_signed_subref_r &a)
|
||||
{
|
||||
return operator = ((sc_unsigned)(a));
|
||||
}
|
||||
|
||||
const sc_signed_subref &
|
||||
sc_signed_subref::operator = (const sc_signed_subref &v)
|
||||
{
|
||||
if (this == &v) {
|
||||
return *this;
|
||||
}
|
||||
return operator = ((sc_unsigned)(v));
|
||||
}
|
||||
|
||||
const sc_signed_subref &
|
||||
sc_signed_subref::operator = (const sc_signed &v)
|
||||
{
|
||||
int i;
|
||||
int l = sc_min(m_left, v.nbits - 1 + m_right);
|
||||
|
||||
for (i = m_right; i <= l; ++i)
|
||||
m_obj_p->set(i, v.test(i - m_right));
|
||||
for (; i <= m_left; i++)
|
||||
m_obj_p->set(i, v.test(l));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
const sc_signed_subref &
|
||||
sc_signed_subref::operator = (const sc_unsigned_subref_r &v)
|
||||
{
|
||||
return operator = ((sc_unsigned)(v));
|
||||
}
|
||||
|
||||
const sc_signed_subref &
|
||||
sc_signed_subref::operator = (const sc_unsigned &v)
|
||||
{
|
||||
int i;
|
||||
int l = sc_min(m_left, v.nbits - 1 + m_right);
|
||||
|
||||
for (i = m_right; i <= l; ++i)
|
||||
m_obj_p->set(i, v.test(i - m_right));
|
||||
for (; i <= m_left; i++)
|
||||
m_obj_p->set(i, 0);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const sc_signed_subref &
|
||||
sc_signed_subref::operator = (unsigned long v)
|
||||
{
|
||||
for (int i = m_right; i <= m_left; ++i) {
|
||||
m_obj_p->set(i, static_cast<bool>(v & 1));
|
||||
v >>= 1;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
const sc_signed_subref &
|
||||
sc_signed_subref::operator = (long v)
|
||||
{
|
||||
unsigned long v2 = (unsigned long)v;
|
||||
for (int i = m_right; i <= m_left; ++i) {
|
||||
m_obj_p->set(i, static_cast<bool>(v2 & 1));
|
||||
v2 >>= 1;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
const sc_signed_subref &
|
||||
sc_signed_subref::operator = (uint64 v)
|
||||
{
|
||||
for (int i = m_right; i <= m_left; ++i) {
|
||||
m_obj_p->set(i, static_cast<bool>(v & 1));
|
||||
v >>= 1;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
const sc_signed_subref &
|
||||
sc_signed_subref::operator = (int64 v)
|
||||
{
|
||||
uint64 v2 = (uint64)v;
|
||||
for (int i = m_right; i <= m_left; ++i) {
|
||||
m_obj_p->set(i, static_cast<bool>(v2 & 1));
|
||||
v2 >>= 1;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
const sc_signed_subref &
|
||||
sc_signed_subref::operator = (double v)
|
||||
{
|
||||
is_bad_double(v);
|
||||
|
||||
int nb = m_left - m_right + 1;
|
||||
int nd = DIV_CEIL(nb);
|
||||
|
||||
#ifdef SC_MAX_NBITS
|
||||
sc_digit d[MAX_NDIGITS];
|
||||
#else
|
||||
sc_digit *d = new sc_digit[nd];
|
||||
#endif
|
||||
|
||||
if (v < 0)
|
||||
v = -v;
|
||||
|
||||
int i = 0;
|
||||
|
||||
while (std::floor(v) && (i < nd)) {
|
||||
#ifndef _WIN32
|
||||
d[i++] = (sc_digit) std::floor(remainder(v, DIGIT_RADIX));
|
||||
#else
|
||||
d[i++] = (sc_digit) std::floor(std::fmod(v, DIGIT_RADIX));
|
||||
#endif
|
||||
v /= DIGIT_RADIX;
|
||||
}
|
||||
|
||||
vec_zero(i, nd, d);
|
||||
sc_digit val = 1; // Bit value.
|
||||
int j = 0; // Current digit in d.
|
||||
i = 0; // Current bit in d.
|
||||
while (i < nb) {
|
||||
m_obj_p->set(i + m_right, (bool)(d[j] & val));
|
||||
++i;
|
||||
if (i % BITS_PER_DIGIT == 0) {
|
||||
val = 1;
|
||||
++j;
|
||||
} else {
|
||||
val <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef SC_MAX_NBITS
|
||||
delete [] d;
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
const sc_signed_subref &
|
||||
sc_signed_subref::operator = (const sc_int_base &a)
|
||||
{
|
||||
return operator = ((int64)a);
|
||||
}
|
||||
|
||||
const sc_signed_subref &
|
||||
sc_signed_subref::operator = (const sc_uint_base &a)
|
||||
{
|
||||
return operator = ((uint64)a);
|
||||
}
|
||||
|
||||
// concatenation methods
|
||||
|
||||
|
||||
void
|
||||
sc_signed_subref::concat_set(int64 src, int low_i)
|
||||
{
|
||||
int i;
|
||||
int l;
|
||||
bool sign = src < 0;
|
||||
|
||||
if (low_i < 64) {
|
||||
src = src >> low_i;
|
||||
l = sc_min(m_left, (63 - low_i) + m_right);
|
||||
for (i = m_right; i <= l; ++i) {
|
||||
m_obj_p->set(i, src & 1);
|
||||
src = src >> 1;
|
||||
}
|
||||
for (; i <= m_left; i++)
|
||||
m_obj_p->set(i, sign);
|
||||
} else {
|
||||
for (i = m_right; i <= m_left; ++i)
|
||||
m_obj_p->set(i, sign);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
sc_signed_subref::concat_set(const sc_signed &src, int low_i)
|
||||
{
|
||||
int i;
|
||||
int l;
|
||||
int src_i;
|
||||
bool sign = src.test(src.nbits - 1);
|
||||
l = src.nbits - (low_i + 1);
|
||||
if (l >= 0) {
|
||||
l = sc_min(m_left, l + m_right);
|
||||
src_i = low_i;
|
||||
for (i = m_right; i <= l; ++i, src_i++) {
|
||||
m_obj_p->set(i, src.test(src_i));
|
||||
}
|
||||
for (; i <= m_left; i++)
|
||||
m_obj_p->set(i, sign);
|
||||
} else {
|
||||
for (i = m_right; i <= m_left; ++i)
|
||||
m_obj_p->set(i, sign);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
sc_signed_subref::concat_set(const sc_unsigned &src, int low_i)
|
||||
{
|
||||
int i;
|
||||
int l;
|
||||
int src_i;
|
||||
l = src.nbits - (low_i + 2);
|
||||
if (l >= 0) {
|
||||
l = sc_min(m_left, l + m_right);
|
||||
src_i = low_i;
|
||||
for (i = m_right; i <= l; ++i, src_i++) {
|
||||
m_obj_p->set(i, src.test(src_i));
|
||||
}
|
||||
for (; i <= m_left; i++)
|
||||
m_obj_p->set(false);
|
||||
} else {
|
||||
for (i = m_right; i <= m_left; ++i)
|
||||
m_obj_p->set(false);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
sc_signed_subref::concat_set(uint64 src, int low_i)
|
||||
{
|
||||
int i;
|
||||
int l;
|
||||
|
||||
if (low_i < 64) {
|
||||
src = src >> low_i;
|
||||
l = sc_min(m_left, (63 - low_i) + m_right);
|
||||
for (i = m_right; i <= l; ++i) {
|
||||
m_obj_p->set(i, src & 1);
|
||||
src = src >> 1;
|
||||
}
|
||||
for (; i <= m_left; i++)
|
||||
m_obj_p->set(false);
|
||||
} else {
|
||||
for (i = m_right; i <= m_left; ++i)
|
||||
m_obj_p->set(false);
|
||||
}
|
||||
}
|
||||
|
||||
// other methods
|
||||
void
|
||||
sc_signed_subref::scan(::std::istream &is)
|
||||
{
|
||||
std::string s;
|
||||
is >> s;
|
||||
*this = s.c_str();
|
||||
}
|
||||
708
src/systemc/dt/int/sc_uint_base.cc
Normal file
708
src/systemc/dt/int/sc_uint_base.cc
Normal file
@@ -0,0 +1,708 @@
|
||||
/*****************************************************************************
|
||||
|
||||
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_base.cpp -- contains interface definitions between sc_uint and
|
||||
sc_signed, sc_unsigned, and definitions for sc_uint_subref.
|
||||
|
||||
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_uint_base.cpp,v $
|
||||
// Revision 1.5 2011/02/18 20:19:15 acg
|
||||
// Andy Goodrich: updating Copyright notice.
|
||||
//
|
||||
// Revision 1.4 2010/02/04 22:23:29 acg
|
||||
// Andy Goodrich: fixed bug in concatenation reads for part selections,
|
||||
// the mask being used was 32 bits and should have been 64 bits.
|
||||
//
|
||||
// Revision 1.3 2008/06/19 17:47:57 acg
|
||||
// Andy Goodrich: fixes for bugs. See 2.2.1 RELEASENOTES.
|
||||
//
|
||||
// Revision 1.2 2007/11/04 21:27:00 acg
|
||||
// Andy Goodrich: changes to make sure the proper value is returned from
|
||||
// concat_get_data().
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "systemc/ext/dt/bit/sc_bv_base.hh"
|
||||
#include "systemc/ext/dt/bit/sc_lv_base.hh"
|
||||
#include "systemc/ext/dt/fx/sc_ufix.hh"
|
||||
#include "systemc/ext/dt/fx/scfx_other_defs.hh"
|
||||
#include "systemc/ext/dt/int/sc_signed.hh"
|
||||
#include "systemc/ext/dt/int/sc_uint_base.hh"
|
||||
#include "systemc/ext/dt/int/sc_unsigned.hh"
|
||||
#include "systemc/ext/dt/misc/sc_concatref.hh"
|
||||
|
||||
// explicit template instantiations
|
||||
namespace sc_core
|
||||
{
|
||||
|
||||
template class sc_vpool<sc_dt::sc_uint_bitref>;
|
||||
template class sc_vpool<sc_dt::sc_uint_subref>;
|
||||
|
||||
} // namespace sc_core
|
||||
|
||||
namespace sc_dt
|
||||
{
|
||||
|
||||
// to avoid code bloat in sc_uint_concat<T1,T2>
|
||||
|
||||
void
|
||||
sc_uint_concref_invalid_length(int length)
|
||||
{
|
||||
std::stringstream msg;
|
||||
msg << "sc_uint_concref<T1,T2> initialization: length = " << length <<
|
||||
"violates 1 <= length <= " << SC_INTWIDTH;
|
||||
SC_REPORT_ERROR("out of bounds", msg.str().c_str());
|
||||
sc_core::sc_abort(); // can't recover from here
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_uint_bitref
|
||||
//
|
||||
// Proxy class for sc_uint bit selection (r-value and l-value).
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
sc_core::sc_vpool<sc_uint_bitref> sc_uint_bitref::m_pool(9);
|
||||
|
||||
// concatenation methods:
|
||||
|
||||
// #### OPTIMIZE
|
||||
void
|
||||
sc_uint_bitref::concat_set(int64 src, int low_i)
|
||||
{
|
||||
sc_uint_base aa(1);
|
||||
*this = aa = (low_i < 64) ? src >> low_i : src >> 63;
|
||||
}
|
||||
|
||||
void
|
||||
sc_uint_bitref::concat_set(const sc_signed &src, int low_i)
|
||||
{
|
||||
sc_uint_base aa(1);
|
||||
if (low_i < src.length())
|
||||
*this = aa = 1 & (src >> low_i);
|
||||
else
|
||||
*this = aa = (src < 0) ? (int_type)-1 : 0;
|
||||
}
|
||||
|
||||
void
|
||||
sc_uint_bitref::concat_set(const sc_unsigned &src, int low_i)
|
||||
{
|
||||
sc_uint_base aa(1);
|
||||
if (low_i < src.length())
|
||||
*this = aa = 1 & (src >> low_i);
|
||||
else
|
||||
*this = aa = 0;
|
||||
}
|
||||
|
||||
void
|
||||
sc_uint_bitref::concat_set(uint64 src, int low_i)
|
||||
{
|
||||
sc_uint_base aa(1);
|
||||
*this = aa = (low_i < 64) ? src >> low_i : 0;
|
||||
}
|
||||
|
||||
|
||||
// other methods
|
||||
void
|
||||
sc_uint_bitref::scan(::std::istream &is)
|
||||
{
|
||||
bool b;
|
||||
is >> b;
|
||||
*this = b;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_uint_subref_r
|
||||
//
|
||||
// Proxy class for sc_uint part selection (l-value).
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool
|
||||
sc_uint_subref_r::concat_get_ctrl(sc_digit *dst_p, int low_i) const
|
||||
{
|
||||
int dst_i; // Word in dst_p now processing.
|
||||
int end_i; // Highest order word in dst_p to process.
|
||||
int left_shift; // Left shift for val.
|
||||
uint_type mask; // Mask for bits to extract or keep.
|
||||
|
||||
dst_i = low_i / BITS_PER_DIGIT;
|
||||
left_shift = low_i % BITS_PER_DIGIT;
|
||||
end_i = (low_i + (m_left-m_right)) / BITS_PER_DIGIT;
|
||||
|
||||
mask = ~(~UINT_ZERO << left_shift);
|
||||
dst_p[dst_i] = (sc_digit)((dst_p[dst_i] & mask));
|
||||
|
||||
dst_i++;
|
||||
for (; dst_i <= end_i; dst_i++)
|
||||
dst_p[dst_i] = 0;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
sc_uint_subref_r::concat_get_data(sc_digit *dst_p, int low_i) const
|
||||
{
|
||||
int dst_i; // Word in dst_p now processing.
|
||||
int end_i; // Highest order word in dst_p to process.
|
||||
int high_i; // Index of high order bit in dst_p to set.
|
||||
int left_shift; // Left shift for val.
|
||||
uint_type mask; // Mask for bits to extract or keep.
|
||||
bool result; // True if inserting non-zero value.
|
||||
uint_type val; // Selection value extracted from m_obj_p.
|
||||
|
||||
dst_i = low_i / BITS_PER_DIGIT;
|
||||
left_shift = low_i % BITS_PER_DIGIT;
|
||||
high_i = low_i + (m_left-m_right);
|
||||
end_i = high_i / BITS_PER_DIGIT;
|
||||
mask = ~mask_int[m_left][m_right];
|
||||
val = (m_obj_p->m_val & mask) >> m_right;
|
||||
result = val != 0;
|
||||
|
||||
// PROCESS THE FIRST WORD:
|
||||
mask = ~(~UINT_ZERO << left_shift);
|
||||
dst_p[dst_i] = (sc_digit)(((dst_p[dst_i] & mask)) |
|
||||
((val << left_shift) & DIGIT_MASK));
|
||||
|
||||
switch (end_i - dst_i) {
|
||||
// BITS ARE ACROSS TWO WORDS:
|
||||
case 1:
|
||||
dst_i++;
|
||||
val >>= (BITS_PER_DIGIT-left_shift);
|
||||
dst_p[dst_i] = (sc_digit)val;
|
||||
break;
|
||||
|
||||
// BITS ARE ACROSS THREE WORDS:
|
||||
case 2:
|
||||
dst_i++;
|
||||
val >>= (BITS_PER_DIGIT-left_shift);
|
||||
dst_p[dst_i++] = (sc_digit)(val & DIGIT_MASK);
|
||||
val >>= BITS_PER_DIGIT;
|
||||
dst_p[dst_i] = (sc_digit)val;
|
||||
break;
|
||||
|
||||
// BITS ARE ACROSS THREE WORDS:
|
||||
case 3:
|
||||
dst_i++;
|
||||
val >>= (BITS_PER_DIGIT-left_shift);
|
||||
dst_p[dst_i++] = (sc_digit)(val & DIGIT_MASK);
|
||||
val >>= BITS_PER_DIGIT;
|
||||
dst_p[dst_i++] = (sc_digit)(val & DIGIT_MASK);
|
||||
val >>= BITS_PER_DIGIT;
|
||||
dst_p[dst_i] = (sc_digit)val;
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_uint_subref
|
||||
//
|
||||
// Proxy class for sc_uint part selection (r-value and l-value).
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
sc_core::sc_vpool<sc_uint_subref> sc_uint_subref::m_pool(9);
|
||||
|
||||
// assignment operators
|
||||
|
||||
sc_uint_subref &
|
||||
sc_uint_subref::operator = (uint_type v)
|
||||
{
|
||||
uint_type val = m_obj_p->m_val;
|
||||
uint_type mask = mask_int[m_left][m_right];
|
||||
val &= mask;
|
||||
val |= (v << m_right) & ~mask;
|
||||
m_obj_p->m_val = val;
|
||||
m_obj_p->extend_sign();
|
||||
return *this;
|
||||
}
|
||||
|
||||
sc_uint_subref &
|
||||
sc_uint_subref::operator = (const sc_signed &a)
|
||||
{
|
||||
sc_uint_base aa(length());
|
||||
return (*this = aa = a);
|
||||
}
|
||||
|
||||
sc_uint_subref &
|
||||
sc_uint_subref::operator = (const sc_unsigned &a)
|
||||
{
|
||||
sc_uint_base aa(length());
|
||||
return (*this = aa = a);
|
||||
}
|
||||
|
||||
sc_uint_subref &
|
||||
sc_uint_subref::operator = (const sc_bv_base &a)
|
||||
{
|
||||
sc_uint_base aa(length());
|
||||
return (*this = aa = a);
|
||||
}
|
||||
|
||||
sc_uint_subref &
|
||||
sc_uint_subref::operator = (const sc_lv_base &a)
|
||||
{
|
||||
sc_uint_base aa(length());
|
||||
return (*this = aa = a);
|
||||
}
|
||||
|
||||
// concatenation methods:
|
||||
|
||||
// #### OPTIMIZE
|
||||
void
|
||||
sc_uint_subref::concat_set(int64 src, int low_i)
|
||||
{
|
||||
sc_uint_base aa(length());
|
||||
*this = aa = (low_i < 64) ? src >> low_i : src >> 63;
|
||||
}
|
||||
|
||||
void
|
||||
sc_uint_subref::concat_set(const sc_signed &src, int low_i)
|
||||
{
|
||||
sc_uint_base aa(length());
|
||||
if (low_i < src.length())
|
||||
*this = aa = src >> low_i;
|
||||
else
|
||||
*this = aa = (src < 0) ? (int_type)-1 : 0;
|
||||
}
|
||||
|
||||
void
|
||||
sc_uint_subref::concat_set(const sc_unsigned &src, int low_i)
|
||||
{
|
||||
sc_uint_base aa(length());
|
||||
if (low_i < src.length())
|
||||
*this = aa = src >> low_i;
|
||||
else
|
||||
*this = aa = 0;
|
||||
}
|
||||
|
||||
void
|
||||
sc_uint_subref::concat_set(uint64 src, int low_i)
|
||||
{
|
||||
sc_uint_base aa(length());
|
||||
*this = aa = (low_i < 64) ? src >> low_i : 0;
|
||||
}
|
||||
|
||||
// other methods
|
||||
void
|
||||
sc_uint_subref::scan(::std::istream &is)
|
||||
{
|
||||
std::string s;
|
||||
is >> s;
|
||||
*this = s.c_str();
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_uint_base
|
||||
//
|
||||
// Base class for sc_uint.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// support methods
|
||||
|
||||
void
|
||||
sc_uint_base::invalid_length() const
|
||||
{
|
||||
std::stringstream msg;
|
||||
msg << "sc_uint[_base] initialization: length = " << m_len <<
|
||||
" violates 1 <= length <= " << SC_INTWIDTH;
|
||||
SC_REPORT_ERROR("out of bounds", msg.str().c_str());
|
||||
sc_core::sc_abort(); // can't recover from here}
|
||||
}
|
||||
|
||||
void
|
||||
sc_uint_base::invalid_index(int i) const
|
||||
{
|
||||
std::stringstream msg;
|
||||
msg << "sc_uint[_base] bit selection: index = " << i <<
|
||||
" violates 0 <= index <= " << (m_len - 1);
|
||||
SC_REPORT_ERROR("out of bounds", msg.str().c_str());
|
||||
sc_core::sc_abort(); // can't recover from here
|
||||
}
|
||||
|
||||
void
|
||||
sc_uint_base::invalid_range(int l, int r) const
|
||||
{
|
||||
std::stringstream msg;
|
||||
msg << "sc_uint[_base] part selection: " <<
|
||||
"left = " << l << ", right = " << r << " violates " <<
|
||||
(m_len - 1) << " >= left >= right >= 0";
|
||||
SC_REPORT_ERROR("out of bounds", msg.str().c_str());
|
||||
sc_core::sc_abort(); // can't recover from here
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
sc_uint_base::check_value() const
|
||||
{
|
||||
uint_type limit = (~UINT_ZERO >> m_ulen);
|
||||
if (m_val > limit) {
|
||||
std::stringstream msg;
|
||||
msg << "sc_uint[_base]: value does not fit into a length of " << m_len;
|
||||
SC_REPORT_WARNING("out of bounds", msg.str().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// constructors
|
||||
sc_uint_base::sc_uint_base(const sc_bv_base &v) :
|
||||
m_val(0), m_len(v.length()), m_ulen(SC_INTWIDTH - m_len)
|
||||
{
|
||||
check_length();
|
||||
*this = v;
|
||||
}
|
||||
sc_uint_base::sc_uint_base(const sc_lv_base &v) :
|
||||
m_val(0), m_len(v.length()), m_ulen(SC_INTWIDTH - m_len)
|
||||
{
|
||||
check_length();
|
||||
*this = v;
|
||||
}
|
||||
sc_uint_base::sc_uint_base(const sc_int_subref_r &v) :
|
||||
m_val(0), m_len(v.length()), m_ulen(SC_INTWIDTH - m_len)
|
||||
{
|
||||
check_length();
|
||||
*this = v.to_uint64();
|
||||
}
|
||||
sc_uint_base::sc_uint_base(const sc_signed_subref_r &v) :
|
||||
m_val(0), m_len(v.length()), m_ulen(SC_INTWIDTH - m_len)
|
||||
{
|
||||
check_length();
|
||||
*this = v.to_uint64();
|
||||
}
|
||||
sc_uint_base::sc_uint_base(const sc_unsigned_subref_r &v) :
|
||||
m_val(0), m_len(v.length()), m_ulen(SC_INTWIDTH - m_len)
|
||||
{
|
||||
check_length();
|
||||
*this = v.to_uint64();
|
||||
}
|
||||
|
||||
sc_uint_base::sc_uint_base(const sc_signed &a) :
|
||||
m_val(0), m_len(a.length()), m_ulen(SC_INTWIDTH - m_len)
|
||||
{
|
||||
check_length();
|
||||
*this = a.to_uint64();
|
||||
}
|
||||
|
||||
sc_uint_base::sc_uint_base(const sc_unsigned &a) :
|
||||
m_val(0), m_len(a.length()), m_ulen(SC_INTWIDTH - m_len)
|
||||
{
|
||||
check_length();
|
||||
*this = a.to_uint64();
|
||||
}
|
||||
|
||||
// assignment operators
|
||||
|
||||
sc_uint_base &
|
||||
sc_uint_base::operator = (const sc_signed &a)
|
||||
{
|
||||
int minlen = sc_min(m_len, a.length());
|
||||
int i = 0;
|
||||
for (; i < minlen; ++i) {
|
||||
set(i, a.test(i));
|
||||
}
|
||||
bool sgn = a.sign();
|
||||
for (; i < m_len; ++i) {
|
||||
// sign extension
|
||||
set(i, sgn);
|
||||
}
|
||||
extend_sign();
|
||||
return *this;
|
||||
}
|
||||
|
||||
sc_uint_base &
|
||||
sc_uint_base::operator = (const sc_unsigned &a)
|
||||
{
|
||||
int minlen = sc_min(m_len, a.length());
|
||||
int i = 0;
|
||||
for (; i < minlen; ++i) {
|
||||
set(i, a.test(i));
|
||||
}
|
||||
for (; i < m_len; ++i) {
|
||||
// zero extension
|
||||
set(i, 0);
|
||||
}
|
||||
extend_sign();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
sc_uint_base &
|
||||
sc_uint_base::operator = (const sc_bv_base &a)
|
||||
{
|
||||
int minlen = sc_min(m_len, a.length());
|
||||
int i = 0;
|
||||
for (; i < minlen; ++i) {
|
||||
set(i, a.get_bit(i));
|
||||
}
|
||||
for (; i < m_len; ++i) {
|
||||
// zero extension
|
||||
set(i, 0);
|
||||
}
|
||||
extend_sign();
|
||||
return *this;
|
||||
}
|
||||
|
||||
sc_uint_base &
|
||||
sc_uint_base::operator = (const sc_lv_base &a)
|
||||
{
|
||||
int minlen = sc_min(m_len, a.length());
|
||||
int i = 0;
|
||||
for (; i < minlen; ++i) {
|
||||
set(i, sc_logic(a.get_bit(i)).to_bool());
|
||||
}
|
||||
for (; i < m_len; ++i) {
|
||||
// zero extension
|
||||
set(i, 0);
|
||||
}
|
||||
extend_sign();
|
||||
return *this;
|
||||
}
|
||||
|
||||
sc_uint_base &
|
||||
sc_uint_base::operator = (const char *a)
|
||||
{
|
||||
if (a == 0) {
|
||||
SC_REPORT_ERROR("conversion failed",
|
||||
"character string is zero");
|
||||
} else if (*a == 0) {
|
||||
SC_REPORT_ERROR("conversion failed",
|
||||
"character string is empty");
|
||||
} else try {
|
||||
int len = m_len;
|
||||
sc_ufix aa(a, len, len, SC_TRN, SC_WRAP, 0, SC_ON);
|
||||
return this->operator = (aa);
|
||||
} catch(const sc_core::sc_report &) {
|
||||
std::stringstream msg;
|
||||
msg << "character string '" << a << "' is not valid";
|
||||
SC_REPORT_ERROR("conversion failed", msg.str().c_str());
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
// explicit conversion to character string
|
||||
const std::string
|
||||
sc_uint_base::to_string(sc_numrep numrep) const
|
||||
{
|
||||
int len = m_len;
|
||||
sc_ufix aa(*this, len, len, SC_TRN, SC_WRAP, 0, SC_ON);
|
||||
return aa.to_string(numrep);
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_uint_base::to_string(sc_numrep numrep, bool w_prefix) const
|
||||
{
|
||||
int len = m_len;
|
||||
sc_ufix aa(*this, len, len, SC_TRN, SC_WRAP, 0, SC_ON);
|
||||
return aa.to_string(numrep, w_prefix);
|
||||
}
|
||||
|
||||
|
||||
// reduce methods
|
||||
bool
|
||||
sc_uint_base::and_reduce() const
|
||||
{
|
||||
return (m_val == (~UINT_ZERO >> m_ulen));
|
||||
}
|
||||
|
||||
bool
|
||||
sc_uint_base::or_reduce() const
|
||||
{
|
||||
return (m_val != uint_type(0));
|
||||
}
|
||||
|
||||
bool
|
||||
sc_uint_base::xor_reduce() const
|
||||
{
|
||||
uint_type mask = ~UINT_ZERO;
|
||||
uint_type val = m_val;
|
||||
int n = SC_INTWIDTH;
|
||||
do {
|
||||
n >>= 1;
|
||||
mask >>= n;
|
||||
val = ((val & (mask << n)) >> n) ^ (val & mask);
|
||||
} while (n != 1);
|
||||
return (val != uint_type(0));
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
sc_uint_base::concat_get_ctrl(sc_digit *dst_p, int low_i) const
|
||||
{
|
||||
int dst_i; // Word in dst_p now processing.
|
||||
int end_i; // Highest order word in dst_p to process.
|
||||
int left_shift; // Left shift for val.
|
||||
uint_type mask; // Mask for bits to extract or keep.
|
||||
|
||||
dst_i = low_i / BITS_PER_DIGIT;
|
||||
left_shift = low_i % BITS_PER_DIGIT;
|
||||
end_i = (low_i + (m_len - 1)) / BITS_PER_DIGIT;
|
||||
|
||||
// PROCESS THE FIRST WORD:
|
||||
mask = ~(~UINT_ZERO << left_shift);
|
||||
dst_p[dst_i] = (sc_digit)((dst_p[dst_i] & mask));
|
||||
|
||||
dst_i++;
|
||||
for (; dst_i <= end_i; dst_i++)
|
||||
dst_p[dst_i] = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//"sc_uint_base::concat_get_data"
|
||||
//
|
||||
// This method transfers the value of this object instance to the supplied
|
||||
// array of sc_unsigned digits starting with the bit specified by low_i within
|
||||
// the array of digits.
|
||||
//
|
||||
// Notes:
|
||||
// (1) we don't worry about masking the high order data we transfer since
|
||||
// concat_get_data() is called from low order bit to high order bit. So
|
||||
// the bits above where we place ours will be filled in by someone else.
|
||||
//
|
||||
// dst_p -> array of sc_unsigned digits to be filled in.
|
||||
// low_i = first bit within dst_p to be set.
|
||||
//-----------------------------------------------------------------------------
|
||||
bool
|
||||
sc_uint_base::concat_get_data(sc_digit *dst_p, int low_i) const
|
||||
{
|
||||
int dst_i; // Word in dst_p now processing.
|
||||
int end_i; // Highest order word in dst_p to process.
|
||||
int high_i; // Index of high order bit in dst_p to set.
|
||||
int left_shift; // Left shift for val.
|
||||
uint_type mask; // Mask for bits to extract or keep.
|
||||
bool result; // True if inserting non-zero value.
|
||||
uint_type val; // Value for this object.
|
||||
|
||||
dst_i = low_i / BITS_PER_DIGIT;
|
||||
left_shift = low_i % BITS_PER_DIGIT;
|
||||
high_i = low_i + (m_len - 1);
|
||||
end_i = high_i / BITS_PER_DIGIT;
|
||||
val = m_val;
|
||||
result = val != 0;
|
||||
|
||||
// MASK OFF DATA TO BE TRANSFERRED BASE ON WIDTH:
|
||||
if (m_len < 64) {
|
||||
mask = ~(~UINT_ZERO << m_len);
|
||||
val &= mask;
|
||||
}
|
||||
|
||||
// PROCESS THE FIRST WORD:
|
||||
mask = ~(~UINT_ZERO << left_shift);
|
||||
dst_p[dst_i] = (sc_digit)(((dst_p[dst_i] & mask)) |
|
||||
((val << left_shift) & DIGIT_MASK));
|
||||
|
||||
switch (end_i - dst_i) {
|
||||
// BITS ARE ACROSS TWO WORDS:
|
||||
case 1:
|
||||
dst_i++;
|
||||
val >>= (BITS_PER_DIGIT - left_shift);
|
||||
dst_p[dst_i] = (sc_digit)val;
|
||||
break;
|
||||
|
||||
// BITS ARE ACROSS THREE WORDS:
|
||||
case 2:
|
||||
dst_i++;
|
||||
val >>= (BITS_PER_DIGIT - left_shift);
|
||||
dst_p[dst_i++] = (sc_digit)(val & DIGIT_MASK);
|
||||
val >>= BITS_PER_DIGIT;
|
||||
dst_p[dst_i] = (sc_digit)val;
|
||||
break;
|
||||
|
||||
// BITS ARE ACROSS FOUR WORDS:
|
||||
case 3:
|
||||
dst_i++;
|
||||
val >>= (BITS_PER_DIGIT - left_shift);
|
||||
dst_p[dst_i++] = (sc_digit)(val & DIGIT_MASK);
|
||||
val >>= BITS_PER_DIGIT;
|
||||
dst_p[dst_i++] = (sc_digit)(val & DIGIT_MASK);
|
||||
val >>= BITS_PER_DIGIT;
|
||||
dst_p[dst_i] = (sc_digit)val;
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// #### OPTIMIZE
|
||||
void
|
||||
sc_uint_base::concat_set(int64 src, int low_i)
|
||||
{
|
||||
*this = (low_i < 64) ? src >> low_i : src >> 63;
|
||||
}
|
||||
|
||||
void
|
||||
sc_uint_base::concat_set(const sc_signed &src, int low_i)
|
||||
{
|
||||
if (low_i < src.length())
|
||||
*this = src >> low_i;
|
||||
else
|
||||
*this = (src < 0) ? (int_type)-1 : 0;
|
||||
}
|
||||
|
||||
void
|
||||
sc_uint_base::concat_set(const sc_unsigned &src, int low_i)
|
||||
{
|
||||
if (low_i < src.length())
|
||||
*this = src >> low_i;
|
||||
else
|
||||
*this = 0;
|
||||
}
|
||||
|
||||
void
|
||||
sc_uint_base::concat_set(uint64 src, int low_i)
|
||||
{
|
||||
*this = (low_i < 64) ? src >> low_i : 0;
|
||||
}
|
||||
|
||||
|
||||
// other methods
|
||||
void
|
||||
sc_uint_base::scan(::std::istream &is)
|
||||
{
|
||||
std::string s;
|
||||
is >> s;
|
||||
*this = s.c_str();
|
||||
}
|
||||
|
||||
} // namespace sc_dt
|
||||
2259
src/systemc/dt/int/sc_unsigned.cc
Normal file
2259
src/systemc/dt/int/sc_unsigned.cc
Normal file
File diff suppressed because it is too large
Load Diff
162
src/systemc/dt/int/sc_unsigned_bitref.inc
Normal file
162
src/systemc/dt/int/sc_unsigned_bitref.inc
Normal file
@@ -0,0 +1,162 @@
|
||||
/*****************************************************************************
|
||||
|
||||
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_unsigned_bitref.h -- Proxy class that is declared in sc_unsigned.h.
|
||||
|
||||
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:
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_unsigned_bitref_r
|
||||
//
|
||||
// Proxy class for sc_unsigned bit selection (r-value only).
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// implicit conversion to uint64
|
||||
|
||||
sc_unsigned_bitref_r::operator uint64 () const
|
||||
{
|
||||
return m_obj_p->test(m_index);
|
||||
}
|
||||
|
||||
bool
|
||||
sc_unsigned_bitref_r::operator ! () const
|
||||
{
|
||||
return (!m_obj_p->test(m_index));
|
||||
}
|
||||
|
||||
bool
|
||||
sc_unsigned_bitref_r::operator ~ () const
|
||||
{
|
||||
return (!m_obj_p->test(m_index));
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_unsigned_bitref
|
||||
//
|
||||
// Proxy class for sc_unsigned bit selection (r-value and l-value).
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// assignment operators
|
||||
|
||||
const sc_unsigned_bitref &
|
||||
sc_unsigned_bitref::operator = (const sc_unsigned_bitref_r &b)
|
||||
{
|
||||
m_obj_p->set(m_index, (bool)b);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const sc_unsigned_bitref &
|
||||
sc_unsigned_bitref::operator = (const sc_unsigned_bitref &b)
|
||||
{
|
||||
m_obj_p->set(m_index, (bool)b);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const sc_unsigned_bitref &
|
||||
sc_unsigned_bitref::operator = (bool b)
|
||||
{
|
||||
m_obj_p->set(m_index, b);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
const sc_unsigned_bitref &
|
||||
sc_unsigned_bitref::operator &= (bool b)
|
||||
{
|
||||
if (!b) {
|
||||
m_obj_p->clear(m_index);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
const sc_unsigned_bitref &
|
||||
sc_unsigned_bitref::operator |= (bool b)
|
||||
{
|
||||
if (b) {
|
||||
m_obj_p->set(m_index);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
const sc_unsigned_bitref &
|
||||
sc_unsigned_bitref::operator ^= (bool b)
|
||||
{
|
||||
if (b) {
|
||||
m_obj_p->invert(m_index);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// #### OPTIMIZE
|
||||
void
|
||||
sc_unsigned_bitref::concat_set(int64 src, int low_i)
|
||||
{
|
||||
bool value = 1 & ((low_i < 64) ? (src >> low_i) : (src >> 63));
|
||||
m_obj_p->set(low_i, value);
|
||||
}
|
||||
|
||||
void
|
||||
sc_unsigned_bitref::concat_set(const sc_signed &src, int low_i)
|
||||
{
|
||||
if (low_i < src.length())
|
||||
m_obj_p->set(low_i, src.test(low_i));
|
||||
else
|
||||
m_obj_p->set(low_i, src < 0);
|
||||
}
|
||||
|
||||
void
|
||||
sc_unsigned_bitref::concat_set(const sc_unsigned &src, int low_i)
|
||||
{
|
||||
if (low_i < src.nbits)
|
||||
m_obj_p->set(low_i, src.test(low_i));
|
||||
else
|
||||
m_obj_p->set(low_i, 0);
|
||||
}
|
||||
|
||||
void
|
||||
sc_unsigned_bitref::concat_set(uint64 src, int low_i)
|
||||
{
|
||||
bool value = ((low_i < 64) ? (src >> low_i) & 1 : 0);
|
||||
m_obj_p->set(low_i, value);
|
||||
}
|
||||
|
||||
// other methods
|
||||
void
|
||||
sc_unsigned_bitref::scan(::std::istream &is)
|
||||
{
|
||||
bool b;
|
||||
is >> b;
|
||||
*this = b;
|
||||
}
|
||||
394
src/systemc/dt/int/sc_unsigned_subref.inc
Normal file
394
src/systemc/dt/int/sc_unsigned_subref.inc
Normal file
@@ -0,0 +1,394 @@
|
||||
/*****************************************************************************
|
||||
|
||||
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_unsigned_subref.h -- Proxy class that is declared in sc_unsigned.h.
|
||||
|
||||
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:
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_unsigned_subref_r
|
||||
//
|
||||
// Proxy class for sc_unsigned part selection (r-value only).
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// concatenation support
|
||||
|
||||
uint64
|
||||
sc_unsigned_subref_r::concat_get_uint64() const // #### Speed up!
|
||||
{
|
||||
sc_unsigned a(m_obj_p, m_left, m_right);
|
||||
return a.to_uint64();
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
sc_unsigned_subref_r::concat_get_ctrl(sc_digit *dst_p, int low_i) const
|
||||
// #### Speed up!
|
||||
{
|
||||
sc_unsigned a(m_obj_p, m_left, m_right);
|
||||
return a.concat_get_ctrl(dst_p, low_i);
|
||||
}
|
||||
|
||||
bool
|
||||
sc_unsigned_subref_r::concat_get_data(sc_digit *dst_p, int low_i) const
|
||||
// #### Speed up!
|
||||
{
|
||||
sc_unsigned a(m_obj_p, m_left, m_right);
|
||||
return a.concat_get_data(dst_p, low_i);
|
||||
}
|
||||
|
||||
// implicit conversion to sc_unsigned
|
||||
sc_unsigned_subref_r::operator sc_unsigned () const
|
||||
{
|
||||
return sc_unsigned(m_obj_p, m_left, m_right);
|
||||
}
|
||||
|
||||
|
||||
// explicit conversions
|
||||
int
|
||||
sc_unsigned_subref_r::to_int() const
|
||||
{
|
||||
sc_unsigned a(m_obj_p, m_left, m_right);
|
||||
return a.to_int();
|
||||
}
|
||||
|
||||
unsigned int
|
||||
sc_unsigned_subref_r::to_uint() const
|
||||
{
|
||||
sc_unsigned a(m_obj_p, m_left, m_right);
|
||||
return a.to_uint();
|
||||
}
|
||||
|
||||
long
|
||||
sc_unsigned_subref_r::to_long() const
|
||||
{
|
||||
sc_unsigned a(m_obj_p, m_left, m_right);
|
||||
return a.to_long();
|
||||
}
|
||||
|
||||
unsigned long
|
||||
sc_unsigned_subref_r::to_ulong() const
|
||||
{
|
||||
sc_unsigned a(m_obj_p, m_left, m_right);
|
||||
return a.to_ulong();
|
||||
}
|
||||
|
||||
int64
|
||||
sc_unsigned_subref_r::to_int64() const
|
||||
{
|
||||
sc_unsigned a(m_obj_p, m_left, m_right);
|
||||
return a.to_int64();
|
||||
}
|
||||
|
||||
uint64
|
||||
sc_unsigned_subref_r::to_uint64() const
|
||||
{
|
||||
sc_unsigned a(m_obj_p, m_left, m_right);
|
||||
return a.to_uint64();
|
||||
}
|
||||
|
||||
double
|
||||
sc_unsigned_subref_r::to_double() const
|
||||
{
|
||||
sc_unsigned a(m_obj_p, m_left, m_right);
|
||||
return a.to_double();
|
||||
}
|
||||
|
||||
|
||||
// explicit conversion to character string
|
||||
const std::string
|
||||
sc_unsigned_subref_r::to_string(sc_numrep numrep) const
|
||||
{
|
||||
sc_unsigned a(length());
|
||||
a = *this;
|
||||
return a.to_string(numrep);
|
||||
}
|
||||
|
||||
const std::string
|
||||
sc_unsigned_subref_r::to_string(sc_numrep numrep, bool w_prefix) const
|
||||
{
|
||||
sc_unsigned a(length());
|
||||
a = *this;
|
||||
return a.to_string(numrep, w_prefix);
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CLASS : sc_unsigned_subref
|
||||
//
|
||||
// Proxy class for sc_unsigned part selection (r-value and l-value).
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// assignment operators
|
||||
|
||||
const sc_unsigned_subref &
|
||||
sc_unsigned_subref::operator = (const sc_unsigned_subref_r &a)
|
||||
{
|
||||
return operator = ((sc_unsigned)(a));
|
||||
}
|
||||
|
||||
const sc_unsigned_subref &
|
||||
sc_unsigned_subref::operator = (const sc_unsigned_subref &a)
|
||||
{
|
||||
if (this == &a) {
|
||||
return *this;
|
||||
}
|
||||
return operator = ((sc_unsigned)(a));
|
||||
}
|
||||
|
||||
const sc_unsigned_subref &
|
||||
sc_unsigned_subref::operator = (const sc_unsigned &v)
|
||||
{
|
||||
int i;
|
||||
int l = sc_min(m_left, v.nbits - 1 + m_right);
|
||||
|
||||
for (i = m_right; i <= l; ++i)
|
||||
m_obj_p->set(i, v.test(i - m_right));
|
||||
for (; i <= m_left; i++)
|
||||
m_obj_p->set(i, v.test(l));
|
||||
return *this;
|
||||
}
|
||||
|
||||
const sc_unsigned_subref &
|
||||
sc_unsigned_subref::operator = (const sc_signed_subref_r &v)
|
||||
{
|
||||
return operator = ((sc_unsigned)(v));
|
||||
}
|
||||
|
||||
const sc_unsigned_subref &
|
||||
sc_unsigned_subref::operator = (const sc_signed &v)
|
||||
{
|
||||
int i;
|
||||
int l = sc_min(m_left, v.nbits - 1 + m_right);
|
||||
|
||||
for (i = m_right; i <= l; ++i)
|
||||
m_obj_p->set(i, v.test(i - m_right));
|
||||
for (; i <= m_left; i++)
|
||||
m_obj_p->set(i, 0);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const sc_unsigned_subref &
|
||||
sc_unsigned_subref::operator = (unsigned long v)
|
||||
{
|
||||
for (int i = m_right; i <= m_left; ++i) {
|
||||
m_obj_p->set(i, static_cast<bool>(v & 1));
|
||||
v >>= 1;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
const sc_unsigned_subref &
|
||||
sc_unsigned_subref::operator = (long v)
|
||||
{
|
||||
unsigned long v2 = (unsigned long)v;
|
||||
for (int i = m_right; i <= m_left; ++i) {
|
||||
m_obj_p->set(i, static_cast<bool>(v2 & 1));
|
||||
v2 >>= 1;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
const sc_unsigned_subref &
|
||||
sc_unsigned_subref::operator = (uint64 v)
|
||||
{
|
||||
for (int i = m_right; i <= m_left; ++i) {
|
||||
m_obj_p->set(i, static_cast<bool>(v & 1));
|
||||
v >>= 1;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
const sc_unsigned_subref &
|
||||
sc_unsigned_subref::operator = (int64 v)
|
||||
{
|
||||
uint64 v2 = (uint64)v;
|
||||
for (int i = m_right; i <= m_left; ++i) {
|
||||
m_obj_p->set(i, static_cast<bool>(v2 & 1));
|
||||
v2 >>= 1;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
const sc_unsigned_subref &
|
||||
sc_unsigned_subref::operator = (double v)
|
||||
{
|
||||
is_bad_double(v);
|
||||
|
||||
int nb = m_left - m_right + 1;
|
||||
int nd = DIV_CEIL(nb);
|
||||
|
||||
#ifdef SC_MAX_NBITS
|
||||
sc_digit d[MAX_NDIGITS];
|
||||
#else
|
||||
sc_digit *d = new sc_digit[nd];
|
||||
#endif
|
||||
|
||||
if (v < 0)
|
||||
v = -v;
|
||||
|
||||
int i = 0;
|
||||
while (std::floor(v) && (i < nd)) {
|
||||
d[i++] = (sc_digit) std::floor(remainder(v, DIGIT_RADIX));
|
||||
v /= DIGIT_RADIX;
|
||||
}
|
||||
vec_zero(i, nd, d);
|
||||
|
||||
sc_digit val = 1; // Bit value.
|
||||
int j = 0; // Current digit in d.
|
||||
|
||||
i = 0; // Current bit in d.
|
||||
while (i < nb) {
|
||||
m_obj_p->set(i + m_right, (bool)(d[j] & val));
|
||||
++i;
|
||||
if (i % BITS_PER_DIGIT == 0) {
|
||||
val = 1;
|
||||
++j;
|
||||
} else {
|
||||
val <<= 1;
|
||||
}
|
||||
}
|
||||
#ifndef SC_MAX_NBITS
|
||||
delete [] d;
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
const sc_unsigned_subref &
|
||||
sc_unsigned_subref::operator = (const sc_int_base &a)
|
||||
{
|
||||
return operator = ((int64)a);
|
||||
}
|
||||
|
||||
const sc_unsigned_subref &
|
||||
sc_unsigned_subref::operator = (const sc_uint_base &a)
|
||||
{
|
||||
return operator = ((uint64)a);
|
||||
}
|
||||
|
||||
// concatenation methods
|
||||
void
|
||||
sc_unsigned_subref::concat_set(int64 src, int low_i)
|
||||
{
|
||||
int i;
|
||||
int l;
|
||||
bool sign = src < 0;
|
||||
|
||||
if (low_i < 64) {
|
||||
src = src >> low_i;
|
||||
l = sc_min(m_left, (63 - low_i) + m_right);
|
||||
for (i = m_right; i <= l; ++i) {
|
||||
m_obj_p->set(i, src & 1);
|
||||
src = src >> 1;
|
||||
}
|
||||
for (; i <= m_left; i++)
|
||||
m_obj_p->set(sign);
|
||||
} else {
|
||||
for (i = m_right; i <= m_left; ++i)
|
||||
m_obj_p->set(sign);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
sc_unsigned_subref::concat_set(const sc_signed &src, int low_i)
|
||||
{
|
||||
int i;
|
||||
int l;
|
||||
int src_i;
|
||||
bool sign = src.test(src.nbits - 1);
|
||||
l = src.nbits - (low_i + 1);
|
||||
if (l >= 0) {
|
||||
src_i = low_i;
|
||||
l = sc_min(m_left, l + m_right);
|
||||
for (i = m_right; i <= l; ++i, src_i++) {
|
||||
m_obj_p->set(i, src.test(src_i));
|
||||
}
|
||||
for (; i <= m_left; i++)
|
||||
m_obj_p->set(i, sign);
|
||||
} else {
|
||||
for (i = m_right; i <= m_left; ++i)
|
||||
m_obj_p->set(i, sign);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
sc_unsigned_subref::concat_set(const sc_unsigned &src, int low_i)
|
||||
{
|
||||
int i;
|
||||
int l;
|
||||
int src_i;
|
||||
l = src.nbits - (low_i + 2);
|
||||
if (l >= 0) {
|
||||
src_i = low_i;
|
||||
l = sc_min(m_left, l + m_right);
|
||||
for (i = m_right; i <= l; ++i, src_i++) {
|
||||
m_obj_p->set(i, src.test(src_i));
|
||||
}
|
||||
for (; i <= m_left; i++)
|
||||
m_obj_p->set(i, false);
|
||||
} else {
|
||||
for (i = m_right; i <= m_left; ++i)
|
||||
m_obj_p->set(i, false);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
sc_unsigned_subref::concat_set(uint64 src, int low_i)
|
||||
{
|
||||
int i;
|
||||
int l;
|
||||
|
||||
if (low_i < 64) {
|
||||
src = src >> low_i;
|
||||
l = sc_min(m_left, (63 - low_i) + m_right);
|
||||
for (i = m_right; i <= l; ++i) {
|
||||
m_obj_p->set(i, src & 1);
|
||||
src = src >> 1;
|
||||
}
|
||||
for (; i <= m_left; i++)
|
||||
m_obj_p->set(false);
|
||||
} else {
|
||||
for (i = m_right; i <= m_left; ++i)
|
||||
m_obj_p->set(false);
|
||||
}
|
||||
}
|
||||
|
||||
// other methods
|
||||
void
|
||||
sc_unsigned_subref::scan(::std::istream &is)
|
||||
{
|
||||
std::string s;
|
||||
is >> s;
|
||||
*this = s.c_str();
|
||||
}
|
||||
32
src/systemc/dt/misc/SConscript
Normal file
32
src/systemc/dt/misc/SConscript
Normal file
@@ -0,0 +1,32 @@
|
||||
# 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
|
||||
|
||||
Import('*')
|
||||
|
||||
if env['USE_SYSTEMC']:
|
||||
Source('sc_concatref.cc')
|
||||
Source('sc_value_base.cc')
|
||||
66
src/systemc/dt/misc/sc_concatref.cc
Normal file
66
src/systemc/dt/misc/sc_concatref.cc
Normal file
@@ -0,0 +1,66 @@
|
||||
/*****************************************************************************
|
||||
|
||||
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.cpp -- Concatenation support.
|
||||
|
||||
Original Author: Andy Goodrich, Forte Design Systems, Inc.
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
MODIFICATION LOG - modifiers, enter your name, affiliation, date and
|
||||
changes you are making here.
|
||||
|
||||
Name, Affiliation, Date:
|
||||
Description of Modification:
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
// $Log: sc_concatref.cpp,v $
|
||||
// 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.
|
||||
//
|
||||
|
||||
#include "systemc/ext/dt/misc/sc_concatref.hh"
|
||||
#include "systemc/ext/dt/sc_temporary.hh"
|
||||
|
||||
// STORAGE POOLS USED BY sc_concatref:
|
||||
namespace sc_core
|
||||
{
|
||||
|
||||
template class sc_vpool<sc_dt::sc_concatref>;
|
||||
template class sc_vpool<sc_dt::sc_concat_bool>;
|
||||
sc_byte_heap sc_temp_heap(0x300000);
|
||||
|
||||
} // namespace sc_core
|
||||
|
||||
namespace sc_dt
|
||||
{
|
||||
|
||||
sc_core::sc_vpool<sc_concat_bool> sc_concat_bool::m_pool(9);
|
||||
sc_core::sc_vpool<sc_concatref> sc_concatref::m_pool(9);
|
||||
|
||||
} // namespace sc_dt
|
||||
137
src/systemc/dt/misc/sc_value_base.cc
Normal file
137
src/systemc/dt/misc/sc_value_base.cc
Normal file
@@ -0,0 +1,137 @@
|
||||
/*****************************************************************************
|
||||
|
||||
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.cpp -- Base class for all SystemC data 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.cpp,v $
|
||||
// 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: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.
|
||||
//
|
||||
|
||||
#include <cctype>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "systemc/ext/dt/misc/sc_value_base.hh"
|
||||
#include "systemc/ext/utils/sc_report_handler.hh"
|
||||
|
||||
namespace sc_dt
|
||||
{
|
||||
|
||||
void
|
||||
sc_value_base::concat_clear_data(bool /* to_ones */)
|
||||
{
|
||||
static const char error_message[] =
|
||||
"concat_clear_data method not supported by this type";
|
||||
SC_REPORT_ERROR("operation failed", error_message);
|
||||
}
|
||||
|
||||
bool
|
||||
sc_value_base::concat_get_ctrl(sc_digit * /*dst_p*/, int /*low_i*/) const
|
||||
{
|
||||
static const char error_message[] =
|
||||
"concat_get_ctrl method not supported by this type";
|
||||
SC_REPORT_ERROR("operation failed", error_message);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
sc_value_base::concat_get_data(sc_digit * /*dst_p*/, int /*low_i*/) const
|
||||
{
|
||||
static const char error_message[] =
|
||||
"concat_get_data method not supported by this type";
|
||||
SC_REPORT_ERROR("operation failed", error_message);
|
||||
return false;
|
||||
}
|
||||
|
||||
sc_dt::uint64
|
||||
sc_value_base::concat_get_uint64() const
|
||||
{
|
||||
static const char error_message[] =
|
||||
"concat_get_uint64 method not supported by this type";
|
||||
SC_REPORT_ERROR("operation failed", error_message);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
sc_value_base::concat_length(bool * /*xz_present_p*/) const
|
||||
{
|
||||
static const char error_message[] =
|
||||
"concat_length method not supported by this type";
|
||||
SC_REPORT_ERROR("operation failed", error_message);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
sc_value_base::concat_set(int64 /*src*/, int /*low_i*/)
|
||||
{
|
||||
static const char error_message[] =
|
||||
"concat_set(int64) method not supported by this type";
|
||||
SC_REPORT_ERROR("operation failed", error_message);
|
||||
}
|
||||
|
||||
void
|
||||
sc_value_base::concat_set(const sc_signed &/*src*/, int /*low_i*/)
|
||||
{
|
||||
static const char error_message[] =
|
||||
"concat_set(sc_signed) method not supported by this type";
|
||||
SC_REPORT_ERROR("operation failed", error_message);
|
||||
}
|
||||
|
||||
void
|
||||
sc_value_base::concat_set(const sc_unsigned &/*src*/, int /*low_i*/)
|
||||
{
|
||||
static const char error_message[] =
|
||||
"concat_set(sc_unsigned) method not supported by this type";
|
||||
SC_REPORT_ERROR("operation failed", error_message);
|
||||
}
|
||||
|
||||
void
|
||||
sc_value_base::concat_set(uint64 /*src*/, int /*low_i*/)
|
||||
{
|
||||
static const char error_message[] =
|
||||
"concat_set(uint64) method not supported by this type";
|
||||
SC_REPORT_ERROR("operation failed", error_message);
|
||||
}
|
||||
|
||||
} // namespace sc_dt
|
||||
Reference in New Issue
Block a user