考虑以下SystemC代码:
#include <iostream>
#include "systemc.h"
using namespace std;
int
sc_main(int argc, char* argv[])
{
sc_bv<3> foo;
operand_0 = "0d6";
cout << foo.to_long() << endl; // prints -2
return EXIT_SUCCESS;
}
按照我的预期打印出-2而不是6。这样做的明显原因是to_long()将位向量0b110解释为有符号。但是,在IEEE Std 1666-2011中,它在第7.2.9节中提到了整数转换函数,例如to_long():
These member functions shall interpret the bits within a SystemC integer,
fixed-point type or vector, or any part-select or concatenation thereof,
as representing an unsigned binary value, with the exception of signed
integers and signed fixed-point types.
我是否误解了某些事情,或者Accellera的SystemC实施是否不遵守这方面的标准?
答案 0 :(得分:2)
我认为你是对的,SystemC LRM(IEEE Std 1666-2011)和实现之间似乎存在差异。
如果您希望将foo
解释为无符号值,则必须使用to_ulong()
:
#include <iostream>
#include <systemc>
using namespace std;
int sc_main(int argc, char* argv[]) {
sc_bv<3> foo("0d6");
cout << foo.to_long() << endl; // prints -2
cout << foo.to_ulong() << endl; // prints 6
return EXIT_SUCCESS;
}