简体   繁体   English

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

[英]Does the Accellera SystemC Implementation incorrectly implement to_long()?

Consider the following SystemC code: 考虑以下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;
}

This prints out -2 rather than 6 as I would have expected. 这将打印出-2而不是我所期望的6。 The apparent reason for doing so would be that to_long() interprets the bit-vector 0b110 as signed. 这样做的明显原因是to_long()将位向量0b110解释为带符号。 However, in IEEE Std 1666-2011 , it says in Section 7.2.9 referring to integer conversion functions such as to_long(): 但是,在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.

Do I misunderstand something or is the SystemC implementation from Accellera not adhering to the standard in this aspect? 我是否误解了某些内容,还是Accellera的SystemC实现没有遵守这方面的标准?

I think you are correct, there does seems to be a discrepancy between the SystemC LRM ( IEEE Std 1666-2011 ) and the implementation. 我认为您是对的,SystemC LRM( IEEE Std 1666-2011 )与实施之间似乎确实存在差异。

If you want foo to be interpreted as an unsigned value, you must use to_ulong() : 如果要将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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM