summaryrefslogtreecommitdiffstats
path: root/tests/tcg
diff options
context:
space:
mode:
authorJoseph Myers2020-05-14 01:51:09 +0200
committerPaolo Bonzini2020-06-10 18:10:25 +0200
commit18c53e1e73197a24f9f4b66b1276eb9868db5bf0 (patch)
treebee7345ba6b19eafcb2e87e38cffc02ee8107445 /tests/tcg
parenttarget/i386: fix fxam handling of invalid encodings (diff)
downloadqemu-18c53e1e73197a24f9f4b66b1276eb9868db5bf0.tar.gz
qemu-18c53e1e73197a24f9f4b66b1276eb9868db5bf0.tar.xz
qemu-18c53e1e73197a24f9f4b66b1276eb9868db5bf0.zip
target/i386: fix fbstp handling of negative zero
The fbstp implementation stores +0 when the rounded result should be -0 because it compares an integer value with 0 to determine the sign. Fix this by checking the sign bit of the operand instead. Signed-off-by: Joseph Myers <joseph@codesourcery.com> Message-Id: <alpine.DEB.2.21.2005132350230.11687@digraph.polyomino.org.uk> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'tests/tcg')
-rw-r--r--tests/tcg/i386/test-i386-fbstp.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/tcg/i386/test-i386-fbstp.c b/tests/tcg/i386/test-i386-fbstp.c
new file mode 100644
index 0000000000..d368949188
--- /dev/null
+++ b/tests/tcg/i386/test-i386-fbstp.c
@@ -0,0 +1,25 @@
+/* Test fbstp instruction. */
+
+#include <stdio.h>
+#include <string.h>
+
+int main(void)
+{
+ int ret = 0;
+ unsigned char out[10];
+ memset(out, 0xfe, sizeof out);
+ __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (-0.0L) : "st");
+ out[9] &= 0x80;
+ if (memcmp(out, "\0\0\0\0\0\0\0\0\0\x80", sizeof out) != 0) {
+ printf("FAIL: fbstp -0\n");
+ ret = 1;
+ }
+ memset(out, 0x12, sizeof out);
+ __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (-0.1L) : "st");
+ out[9] &= 0x80;
+ if (memcmp(out, "\0\0\0\0\0\0\0\0\0\x80", sizeof out) != 0) {
+ printf("FAIL: fbstp -0.1\n");
+ ret = 1;
+ }
+ return ret;
+}