qemu/tests/tcg/i386/test-i386-fbstp.c
Joseph Myers 18c53e1e73 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>
2020-06-10 12:10:25 -04:00

26 lines
651 B
C

/* 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;
}