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

[RV64_DYNAREC] Clear high 32bits when write back as single #1684

Merged
merged 1 commit into from
Jul 16, 2024

Conversation

ksco
Copy link
Collaborator

@ksco ksco commented Jul 16, 2024

We cannot use FSD here, because RISC-V uses Nan-boxing on single precision floating point values, so if some freg holds a float value, the high 32bits will be all 1s.

@ptitSeb
Copy link
Owner

ptitSeb commented Jul 16, 2024

We cannot use FSD here, because RISC-V uses Nan-boxing on single precision floating point values, so if some freg holds a float value, the high 32bits will be all 1s.

Not sure I understand. Nan-boxing is the abality to pass a "workload" inside a NAN (fill the mantissa with a speicifc value), and get this value carried away accross operations...
What you discribe looks more like the typical sign extension of a 32bits, extended to 64bits, wich might happens with negative values, or x86 NaN (that are negative).

No issue with the code, tho.

@ptitSeb ptitSeb merged commit d700cc1 into ptitSeb:main Jul 16, 2024
47 checks passed
@ksco ksco deleted the fix branch July 16, 2024 06:58
@ksco
Copy link
Collaborator Author

ksco commented Jul 16, 2024

It's not a sign extension thing. anyway, the spec explains it well, pasted below:

12.2
 NaN Boxing of Narrower Values
When multiple floating-point precisions are supported, then valid values of narrower n-bit types,
n < FLEN, are represented in the lower n bits of an FLEN-bit NaN value, in a process termed
NaN-boxing. The upper bits of a valid NaN-boxed value must be all 1s. Valid NaN-boxed n-bit
values therefore appear as negative quiet NaNs (qNaNs) when viewed as any wider m-bit value,
n < m ≤ FLEN. Any operation that writes a narrower result to an f register must write all 1s to
the uppermost FLEN−n bits to yield a legal NaN-boxed value.

@ptitSeb
Copy link
Owner

ptitSeb commented Jul 16, 2024

It's not a sign extension thing. anyway, the spec explains it well, pasted below:

12.2
 NaN Boxing of Narrower Values
When multiple floating-point precisions are supported, then valid values of narrower n-bit types,
n < FLEN, are represented in the lower n bits of an FLEN-bit NaN value, in a process termed
NaN-boxing. The upper bits of a valid NaN-boxed value must be all 1s. Valid NaN-boxed n-bit
values therefore appear as negative quiet NaNs (qNaNs) when viewed as any wider m-bit value,
n < m ≤ FLEN. Any operation that writes a narrower result to an f register must write all 1s to
the uppermost FLEN−n bits to yield a legal NaN-boxed value.

Well, it's still some kind of sign extension, at least, the 32bits upper is filled with 1, like a sign extension, but has a ### "NAN" extension.... Anyway, we don't really care here, we just write using FSW, so no issue, also, I think it's only relevent for 32bits->64bits conversions, it makes no sense for 64bits->32bits conversion

Also also, the upper part is untouched, including the 32-63 interval that might contains upper part of the old 64bits SD value:

CVTSD2SS (128-bit Legacy SSE Version)[ ¶](https://www.felixcloutier.com/x86/cvtsd2ss#cvtsd2ss--128-bit-legacy-sse-version-)
DEST[31:0] := Convert_Double_Precision_To_Single_Precision_Floating_Point(SRC[63:0]);
(* DEST[MAXVL-1:32] Unmodified *)

@ksco
Copy link
Collaborator Author

ksco commented Jul 16, 2024

yeah, I'm working on that.

Javier97sm pushed a commit to Javier97sm/box64 that referenced this pull request Aug 16, 2024
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

Successfully merging this pull request may close these issues.

2 participants