首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Accellera SystemC实现是否不正确地实现了to_long()?

Accellera SystemC实现是否不正确地实现了to_long()?
EN

Stack Overflow用户
提问于 2015-05-29 00:14:36
回答 1查看 117关注 0票数 0

考虑以下SystemC代码:

代码语言:javascript
复制
#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():

代码语言:javascript
复制
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实现在这方面没有遵守标准?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-30 20:41:15

我认为您是正确的,在SystemC LRM (IEEE Std 1666-2011)和实现之间确实存在差异。

如果要将foo解释为无符号值,则必须使用to_ulong()

代码语言:javascript
复制
#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;
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30519135

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档