Comments (9)
Thank you for finding this. Such a result is a bug. For any finite floating-point number (meaning "non-NaN") x
, x - x
should be +0.0
. (Thus, you are right.)
IEEE754-2019 6.3 The sign bit
When the sum of two operands with opposite signs (or the difference of two operands with like signs) is exactly zero, the sign of that sum (or difference) shall be +0 under all rounding-direction attributes except roundTowardNegative;
Unfortunately, I couldn't reproduce the problem on my end. I used a test code in Processor/Src/Verification/TestCode/Asm/FP/code.s
. I rewrite L13-14 to set both a1
and a2
to zero. The result of the subtraction, which would be in fa4 (f14)
, was confirmed to be 0x00000000 (+0.0)
. The only 0x80000000 (-0.0)
was in fs6 (f21)
, which resulted from the FNMSUB
instruction and was correct.
To better understand, could you please provide more details? Specifically, the following information would be helpful:
- Sorce code and compiler version, options, etc. (or an assembly code)
- Kanata log
- Register.csv
We want to resolve this issue and greatly appreciate your assistance. Thank you!
from rsd.
Thanks for your reply.
Here are the all files you will need for debugging: https://wormhole.app/zkkA4#yJpgCuoEpgaozwhhZ-2R0w
from rsd.
I confirmed the test_spike.log file contains the following:
core 0: 0x000020b0 (0x040fa407) flw fs0, 64(t6)
core 0: 3 0x000020b0 (0x040fa407) f8 0x3abff4ac mem 0x80003040
(omit)
core 0: 0x000020e8 (0x0b0fab07) flw fs6, 176(t6)
core 0: 3 0x000020e8 (0x0b0fab07) f22 0xd54ce604 mem 0x800030b0
(omit)
core 0: 0x00003420 (0x096406d3) fsub.s fa3, fs0, fs6
core 0: 3 0x00003420 (0x096406d3) c1_fflags 0x00000001 f13 0x554ce604
Since std::bit_cast<unsigned>( std::bit_cast<float>(0x3abff4ac) - std::bit_cast<float>(0xd54ce604) ) == 0x554ce604
, this is a correct behavior.
Could you please provide the hex file of the program where the wrong behavior occurs?
Thank you.
from rsd.
Sorry, I lost the hex file of this bug. I manually restored the instruction sequence this afternoon according to spike's commit log. Here are the final hex:
zero_minus_zero.hex.zip
For reproduce, you need to modify PC_GOAL
to 32'h000030dc
and cancle define RSD_NARROW_PC
in Processor/Src/Memory/MemoryMapTypes.sv.
Moreover, here is the spike commit log: spike_zero_minus_zero.log
In detail, there is a mismatch on ft8
between spike(0x00000000, as shown in the following figure) and rsd(0x80000000).
from rsd.
Thank you for your cooperation. I'll try reproducing.
from rsd.
It reproduced. Thank you restoring the hex file!
The root of this bug is wrong behavior of fmul.s
.
First, the fmul.s ft1, ft8, fs6
is executed and should produce -0.0
because ft8
is +0.0
and fs6
is a negative number. However, in bd7c5c1, it wrongly returns +0.0
(#92).
Then, the fmsub.s ft8, ft1, ft6, ft8
with ft6
is a negative number and ft8
is +0.0
is executed. When ft1
is -0.0
, it should returns +0.0
because it is a same-number subtraction. When ft1
is +0.0
, it should returns -0.0
because it is a (-0.0) - (+0.0)
-like subtraction. So, the behavior of fmsub.s
is correct.
In summary, the fmsub.s
implementation is correct and the wrong implementation of fmul.s
(#92) leads to fmsub.s
instruction returning -0.0
.
Please do not close this issue and keep it open until it is sure that #92 is resolved and this issue no longer occurs.
from rsd.
The meaning of fmsub.s ft8, ft1, ft6, ft8
is ft8=ft1×ft6−ft8
. In rsd, ft1=+0.0
, ft6 is negative
, ft8=+0.0
. so it means (+0.0)*negative-(+0.0)
.
However, when computing (+0.0)*negative
, the result in rsd is +0.0
or -0.0
?
Does #92 only happens on fmul
not on ordinary multiplication?
from rsd.
Yes, the problem #92 only happens on fmul.s
.
The current fmul.s
implementation on RSD wrongly returns fma(a,b,+0.0)
. It is not that the multiplier produces a wrong-sign result, but the last + (+0.0)
causes the problem.
from rsd.
I see. Thanks for your patient reply!
from rsd.
Related Issues (20)
- error running the Makefile.verilator.mk HOT 3
- Off by one error in leading 0 count loop? HOT 1
- cannot convert ‘const VlWide<92>’ to ‘const uint32_t (&)[92]’ {aka ‘const unsigned int (&)[92]’} HOT 10
- wrong pointer used for poping btb queue HOT 2
- Wiki issue HOT 2
- Error when run in verilator: no viable conversion from 'const VlWide<92>' to 'const uint32_t [92]' HOT 2
- Report 'Memory address 0x1e38 is invalid' when running helloworld.elf in spike HOT 4
- PC becomes 0x00000000 after jump to 0x80000000 to execute auipc instruction HOT 7
- [Bug Report] SD bit in mstatus doesn't update when FS=11 HOT 3
- [Bug Report] RSD doesn't update mstatus after `mret` instruction HOT 3
- [Bug Report] `fflags` records the accumulated status incorrectly HOT 1
- [Bug Report] Incorrect upward rounding result of fsub.s instruction HOT 3
- Cache and BP Disable Possible Way HOT 6
- [Bug Report] OF flag bit in fflags is not set correctly after fdiv.s instruction HOT 1
- [Bug Report] RSD didn't update fflags.NX correctly after fnmadd.s instruction HOT 1
- [Bug Report] `fflags.NV` is not set correctly after `fsqrt.s` instruction HOT 1
- [Bug Report] `fflags.UF` is not set correctly after `fdiv.s` instruction HOT 1
- [Bug Report] `fflags.DZ` set incorrectly after `fdiv.s` instruction HOT 3
- [Bug Report] Wrong sign bit when 0 is multiplied by a negative number HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rsd.