Behaviour differences on x86 and RISC-V on cos/sin functions
Ludovic Henry
ludovic@rivosinc.com
Thu Dec 8 18:23:37 GMT 2022
Hello,
As part of some OpenJDK work on RISC-V, I've stumbled upon a behavior
difference in cos/sin functions between x86 and RISC-V. It's not clear to
me whether the difference in behavior is acceptable, and whether it should
be handled in the OpenJDK (or other relevant libraries).
The simple test case I have which runs successfully on x86 but not RISC-V
is the following:
```
#include <stdint.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
void main(int argc, char* argv[]) {
int64_t bitsNaN = 0x7fff800000000000L;
double valNaN = *((double*)&bitsNaN);
double resD = acos(valNaN);
int64_t res = *((int64_t*)&resD);
if (!(res == bitsNaN)) {
printf("expected 0x%lx but got 0x%lx\n", bitsNaN, res);
exit(1);
}
}
```
I can see that there are some NaN related tests in glibc already at
glibc/math/libm-test-acos.inc#L25-26 and that some are failing at
https://sourceware.org/glibc/wiki/Release/2.35#RISC-V_.28rv64imafdc.2Flp64d.29
and
https://sourceware.org/glibc/wiki/Release/2.36#RISC-V_.28rv64imafdc.2Flp64d.29.
I'm not sure exactly which test is failing though.
What do you think?
Thank you,
Ludovic
More information about the Libc-alpha
mailing list