serenity icon indicating copy to clipboard operation
serenity copied to clipboard

LibC: Add fenv+rounding support for RISC-V (and test fenv in the first place)

Open kleinesfilmroellchen opened this issue 2 years ago • 9 comments

Because the new tests failed on x86 extended floating point (a truly cursed float format), you're getting two x87 fixes for free!

LibC: Start on fenv support for RISC-V

LibC: Add some fenv tests

Turns out that fegetround() is broken on x87, so the corresponding test assertions are commented out for now.

AK: Use common ComponentType integer type for float bitfields

This allows us to easily use an appropriate integer type when performing float bitfield operations.

This change also adds a comment about the technically-incorrect 80-bit extended float mantissa field.

LibC: Prevent undefined shift in internal_to_integer

New tests will hit a dead bit count of 64, leading to an undefined shift.

LibC: Add rounding specializations for RISC-V

Whenever the floating-point values are in integer range, we can use the various FCVT functions with static rounding mode to perform fast rounding. I took this opportunity to clean up the architecture differentiation for these functions, which allows us to use the software rounding implementation for all extreme and unimplemented cases, including AArch64.

Also adds more round & trunc tests.

LibC: Fix extended floating point software rounding

Contrary to IEEE formats, x86's 80-bit extended floats need the topmost mantissa bit to be 1 or else a special kind of NaN is produced. We fix this by reinserting the special bit if necessary.

kleinesfilmroellchen avatar Sep 19 '23 18:09 kleinesfilmroellchen

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions!

stale[bot] avatar Oct 13 '23 23:10 stale[bot]

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions!

stale[bot] avatar Nov 09 '23 02:11 stale[bot]

This pull request has been closed because it has not had recent activity. Feel free to re-open if you wish to still contribute these changes. Thank you for your contributions!

stale[bot] avatar Nov 23 '23 11:11 stale[bot]

gcc doesn't like your test file, looks like this needs a bit more than just a rebase :)

ADKaster avatar Jan 04 '24 19:01 ADKaster

gcc doesn't like your test file, looks like this needs a bit more than just a rebase :)

Another case of not realizing that we have a blackbox function already...

kleinesfilmroellchen avatar Jan 05 '24 23:01 kleinesfilmroellchen

Reminds me don't we implement most rounding functions already in AK/Math.h for risc V? So could we just forward to them instead?

Hendiadyoin1 avatar Jan 07 '24 23:01 Hendiadyoin1

Reminds me don't we implement most rounding functions already in AK/Math.h for risc V?

No, nothing riscv64-specific is in AK/Math.h yet? Although I do wonder, why we don't forward the libc rounding functions to AK, like we do for other functions with MAKE_AK_BACKED? Or should they behave differently? And those AK/Math.h versions of e.g. rint seem to be implemented differently than in LibC.

spholz avatar Jan 08 '24 12:01 spholz

Depends on Clang 17, see the WIP commit. Drafting for now.

kleinesfilmroellchen avatar Jan 19 '24 10:01 kleinesfilmroellchen

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions!

stale[bot] avatar Feb 10 '24 07:02 stale[bot]

This pull request has been closed because it has not had recent activity. Feel free to re-open if you wish to still contribute these changes. Thank you for your contributions!

stale[bot] avatar Feb 18 '24 01:02 stale[bot]