From: Daniel Collins <solemnwarning@solemnwarning.net>
To: qemu-devel@nongnu.org
Subject: Strange floating-point behaviour with some CPU models
Date: Tue, 18 Feb 2025 11:31:51 +0000 [thread overview]
Message-ID: <73cc235e-6401-426e-b02e-e5a72ae8059f@solemnwarning.net> (raw)
Hello all,
I'm encountering a very weird bug with some floating-point maths code, but only under very specific configurations. First I thought it was a Clang bug, but then further digging eventually showed it to only occur under Windows VMs with specific QEMU CPU options, I'm not certain whether it is a QEMU/KVM bug or a Windows bug, but thought starting here would be easiest.
When compiled under MSVC Clang with modern CPU instructions disabled (e.g. -march=pentium3 or -march=pentium-mmx), the floorf() call in the following program always returns 0.0, while the truncation works correctly:
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
float n = atof(argv[1]);
printf("n = %f\n", n);
float f = floorf(n);
printf("f = %f\n", f);
float c = (int)(n);
printf("c = %f\n", c);
return 0;
}
Example output on an affected VM:
C:\Users\Administrator> floorf-p3.exe 10
n = 10.000000
f = 0.000000
c = 10.000000
C:\Users\Administrator> floorf-p4.exe 10
n = 10.000000
f = 10.000000
c = 10.000000
(floorf-p3.exe was compiled with -march=pentium3 and floorf-p4.exe with -march=pentium4 above)
I've tried a few QEMU CPU models on a variety of Intel/AMD VM hosts and two different Windows versions (10 and Server 2022), and observed the following:
host-passthrough: works (on AMD and Intel hosts)
qemu64: broken
EPYC-Milan: works
Westmere: works
Penryn: broken
Happy to provide executables and/or disassembly to aid in debugging this.
Daniel
reply other threads:[~2025-02-18 13:56 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=73cc235e-6401-426e-b02e-e5a72ae8059f@solemnwarning.net \
--to=solemnwarning@solemnwarning.net \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.