Open Quuxplusone opened 3 years ago
Bugzilla Link | PR49415 |
Status | NEW |
Importance | P enhancement |
Reported by | Michał Górny (mgorny@gentoo.org) |
Reported on | 2021-03-03 10:54:25 -0800 |
Last modified on | 2021-03-24 09:00:37 -0700 |
Version | unspecified |
Hardware | PC Linux |
CC | arichardson.kde@gmail.com, emaste@freebsd.org, jdevlieghere@apple.com, labath@google.com, llvm-bugs@lists.llvm.org |
Fixed by commit(s) | |
Attachments | |
Blocks | |
Blocked by | |
See also |
Given a simple example:
#include <stdio.h>
int main() {
printf("%e\n", 5.35161536149201e-315);
return 0;
}
on FreeBSD/amd64 and Linux/aarch64 (openSUSE) it prints:
$ ./a.out 5.351615e-315
but on FreeBSD/aarch64:
$ ./a.out 0.000000e+00
Interesting. I guess we should convert whoever is printing this from printf to llvm::APFloat...
Could this perhaps be due to the issue fixed in https://cgit.freebsd.org/src/commit/?id=0e4ff0acbe80c547988bede738af2e227c7eb47c
I'm going to try.
Nope, still the same result as of freebsd 0cff00ae682a032dec29494f88c76d78a08edfa1.
That commit should definitely fix the issue. If I run the following .c file on a RPI4, I get the expected output once the FTZ flag is cleared.
[root@rpi4-002 ~]# cat ftz_test.c
#include <stdio.h>
#include <stdint.h>
#include <fenv.h>
#include <machine/vfp.h>
#define VFPCR_FZ (0x01000000) /* flush to zero enabled */
int main() {
volatile double d = 5.35161536149201e-315;
unsigned long fpcr;
__mrs_fpcr(fpcr);
printf("fpcr=%lx\n", fpcr);
printf("FTZ=%lx\n", fpcr & VFPCR_FZ);
printf("d=%g\n", d);
fpcr &= ~(long)VFPCR_FZ;
__msr_fpcr(fpcr);
__mrs_fpcr(fpcr);
printf("fpcr=%lx\n", fpcr);
printf("FTZ=%lx\n", fpcr & VFPCR_FZ);
printf("d=%g\n", d);
}
[root@rpi4-002 ~]# cc -o ftz ftz_test.c
[root@rpi4-002 ~]# ./ftz
fpcr=3000000
FTZ=1000000
d=0
fpcr=2000000
FTZ=0
d=5.35162e-315
Note: If you are using a recent FreeBSD HEAD/stable-13 kernel the first printf should output "fpcr=2000000" rather than "fpcr=3000000". If not, my guess would be something went wrong during the update process.
I'm getting the same output from your program. Did you try mine (#c1)?
(the same as you do, i.e. it works)
I am running an old kernel that doesn't have the fix so I am also seeing zero output. But in QEMU with a new kernel that has the fix I see non-zero output for your test program.
Since you are seeing my output that means you are running a kernel that still sets the flush-to-zero flag.
Ah, sorry, I misunderstood you. I'll update the kernel then.
Indeed this fixes it. Should I remove xfail now and close the bug or wait some more?
This change is not yet in FreeBSD 13.0, and I am not yet sure if it will be possible to include it. I should know in the next day or two. If it does get included I think we can just drop the xfail.
The change is now merged and will be in FreeBSD 13.0. I think we can drop the xfail (but probably leave a comment that this was fixed in FreeBSD 13.0, in case anyone tries on FreeBSD/arm64 12.2).