-
Notifications
You must be signed in to change notification settings - Fork 114
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
SFPU shift operator issue when using sfpi #15514
Comments
### Ticket #13415 ### Problem description Update left shift ### What's changed Updated file as mentioned in Issue #15514. ### Checklist - [x] [Post commit CI](https://github.com/tenstorrent/tt-metal/actions/runs/12074417574) passes - [x] [Blackhole post-commit tests](https://github.com/tenstorrent/tt-metal/actions/runs/12074418588) passes
@VirdhatchaniKN - I see you referenced this in your changes. Can you please provide an update here. |
I have merged the code that is mentioned in this issue, which is a temporary fix to the main branch. However, I believe that the issue is with the sfpi as the SFPU instructions work. |
@rdjogoTT @VirdhatchaniKN is this still an open issue ? If not, can you please close this ? Thanks |
@VirdhatchaniKN is calling these instructions directly so it is not a blocker. However it would be great to have the sfpi version updated. |
The code changed by @VirdhatchaniKN 's fix is not the same as mentioned above. it is replacing:
which is intentionally preserving the sign bit from the original value. The replacement code is not equivalent. |
@nathan-TT it is true that the code is not equivalent. @VirdhatchaniKN was trying to get rid of the part that preserves the sign bit of the original value by writing:
but that was not producing correct results. So I was asked to help debug and when I wrote it out using TTI instructions as:
I found that it worked. I thought that these two code blocks should provide the same functionality, so that's why I made this issue. |
update: The observed behavior is because of juggling 2's complement and sign-magnitude data representations. It is unclear what the 'right' answer should be. |
Can you please explain a bit how 2's complement and sign-magnitude are handled differently, for future reference if something similar pops up? |
wait a moment, signed integer overflow is undefined behavior -- why are you expecting any particular behavior in these circumstances? |
sigh, in C++17 such shifts were UB, in C++20, 2's complement representation is required and IIUC the shift is not UB. But the issue we have is that we use sign-magnitude internal representation, and there appear to be inconsistencies in how that is handled. This will take some care unraveling. |
In investigating this I implemented .ttinsn pseudo, which makes disassembling synthesized sfpu insts better. The compiler landed at #17800, but the llk headers need updating too: tenstorrent/tt-llk#22 Documenting internal data type representations to progress this issue itself |
Describe the bug
The following SFPU llk, implemented using sfpi, does not work:
But this one does, and it uses SFPU instructions directly:
Both simply load 32 bit values from Dest, left shift by
shift_amt
, and store back. Sfpi version does not work when bit 31 (MSB) has to change from 0->1 or 1->0 as a result of shift operation.See this issue for more details: #13415
To Reproduce
Use this test:
Expected behavior
Sfpi version of the LLK should pass the test as well.
The text was updated successfully, but these errors were encountered: