David, All,
In SystemC, if the SC_INCLUDE_FX macro is defined then arithmetic operations with sc_int/sc_uint throw up compile errors because of ambiguity with operators defined for sc_fxval and sc_fxval_fast.
The issue is demonstrated with the simple program below.
#define SC_INCLUDE_FX
#include <systemc.h>
int sc_main(int argc, char * argv[])
{
sc_int<20> x, y;
#ifdef WORK_AROUND
y = (sc_int<20>)x + (sc_int<20>)y;
#else
y = x + 1; <----------------- compile error on this line
#endif
sc_start(25);
return 0;
}
"$TESTDIR/simple.cpp", line 11: error: more than
one operator "+" matches these operands:
built-in operator "arithmetic + arithmetic"
function "sc_dt::operator+(const sc_dt::sc_int_base &, const
sc_dt::sc_fxval &)"
function "sc_dt::operator+(const sc_dt::sc_int_base &, const
sc_dt::sc_fxval_fast &)"
operand types are: sc_dt::sc_int<20> + int
y = x + 1;
I've discussed this with Andy Goodrich. The compile error is happening because the sc_int class does not provide explicit operators for sc_int and native C++ data types, but rely on the automatic conversion of a sc_int to long long, and then for the native operators to kick in - this is for performance reasons, such that sc_int math is faster because the native hardware gets used rather than executing an overloaded operator. If the fixed point types are involved, then it creates ambiguity because it defines operator * for sc_int_base and sc_fxval, and the native types can all be converted to sc_fxval and to sc_fxval_fast.
The workaround is to do the explicit casting as above, which can get quite tedious for long expressions.
Fisrt question: Is there anything that can be done? One fix would be to define all the operators for sc_int and sc_uint and the native C++ types, but that would defeat the purpose of sc_int and sc_uint in the first place, which is to do things native. Is there any other way to make this work?
Second, if we have to live with this behavior, then I think it makes sense for the LRM to explicitly mention this issue if SC_INCLUDE_FX is defined. I looked in the LRM, but could not find any such mention - I hope I didn't miss it.
Thoughts?
Thanks,
-Bishnupriya
----------------------------------------------------------------------------------------------------------------------------------------------------
Bishnupriya Bhattacharya | Software Architect - Virtual System Platform | Cadence
P: +91.80.4184.1197 www.cadence.com<http://www.cadence.com/>
----------------------------------------------------------------------------------------------------------------------------------------------------
-- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.Received on Thu Nov 25 21:00:22 2010
This archive was generated by hypermail 2.1.8 : Thu Nov 25 2010 - 21:00:24 PST