Accellera SystemC 实现是否错误地实现了 to_long()?

Does the Accellera SystemC Implementation incorrectly implement to_long()?

考虑以下 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 实现在这方面没有遵守标准?

我认为你是对的,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;
}