Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uint64类型数据加法和除法问题 #26

Open
electrocrazy opened this issue Aug 1, 2024 · 2 comments
Open

uint64类型数据加法和除法问题 #26

electrocrazy opened this issue Aug 1, 2024 · 2 comments

Comments

@electrocrazy
Copy link

electrocrazy commented Aug 1, 2024

1、我们在用rv64ilp32 工具链测试uint64 类型(unsigned long long)数据加法和除法时出现了一个反常现象。
如下图代码所示,tmp1和tmp2是两个uint64 类型(unsigned long long)数据。tmp1应该大于tmp2,但是在if语句中判断出来的结果却是tmp1小于tmp2。如果把tmp1和tmp2除以2的话,tmp2的值反而变大了。请帮忙排查一下原因。源代码和测试打印如下图。
uint64类型数据加法测试代码:
uint64加法错误-1
uint64类型数据加法测试打印:
uint64加法错误-2
uint64类型数据加法除法测试代码:
uint64加法除法错误-1

uint64类型数据加法除法测试打印:
uint64加法除法错误-2

@Liaoshihua
Copy link

Liaoshihua commented Aug 2, 2024

目前来看似乎是测试用例的问题,tmp2 overflow了。
当测试代码如下的时候
`

int main()
{
    unsigned long long tmp1,tmp2;
    tmp1 = 0xb2d05e00;
    tmp2 = 1092471462 + 26000*60000;
    if(tmp1 > tmp2)
        printf("tmp1 > tmp2\n");
    else
        printf("tmp1 < tmp2\n");
    return 0;
}

`

`

riscv64-unknown-elf-gcc ilp32long_long/test.c -Woverflow -o 64ilp32 (64ilp32)
ilp32long_long/test.c: In function 'main':
ilp32long_long/test.c:7:23: warning: integer overflow in expression of type 'int' results in 
'-1642495834' [-Woverflow]
    7 |     tmp2 = 1092471462 + 26000*60000; 

qemu-riscv64ilp32 64ilp32
    tmp1 < tmp2


riscv64-unknown-elf-gcc ilp32long_long/test.c -Woverflow -o 64lp64
ilp32long_long/test.c: In function 'main':
ilp32long_long/test.c:7:23: warning: integer overflow in expression of type 'int' results in 
'-1642495834' [-Woverflow]
    7 |     tmp2 = 1092471462 + 26000*60000;

qemu-riscv64 64lp64
    tmp1 < tmp2

`

使用64ilp32工具链和gcc-master分支构建的gcc15.0 rv64lp64 工具链,得到的结果都是tmp1 < tmp2

除此之外,在上使用x86编译出来的程序,也是tmp < tmp2

@guoren83
Copy link

guoren83 commented Aug 2, 2024

看起来,这个问题,可以 close 了。

是测试用例的问题?@electrocrazy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants