target/i386: fix fscale handling of signaling NaN
The implementation of the fscale instruction returns a NaN exponent unchanged. Fix it to return a quiet NaN when the provided exponent is a signaling NaN. Signed-off-by: Joseph Myers <joseph@codesourcery.com> Message-Id: <alpine.DEB.2.21.2005070043330.18350@digraph.polyomino.org.uk> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
c415f2c582
commit
0d48b43632
@ -970,6 +970,10 @@ void helper_fscale(CPUX86State *env)
|
||||
{
|
||||
if (floatx80_is_any_nan(ST1)) {
|
||||
ST0 = ST1;
|
||||
if (floatx80_is_signaling_nan(ST0, &env->fp_status)) {
|
||||
float_raise(float_flag_invalid, &env->fp_status);
|
||||
ST0 = floatx80_silence_nan(ST0, &env->fp_status);
|
||||
}
|
||||
} else {
|
||||
int n = floatx80_to_int32_round_to_zero(ST1, &env->fp_status);
|
||||
ST0 = floatx80_scalbn(ST0, n, &env->fp_status);
|
||||
|
37
tests/tcg/i386/test-i386-fscale.c
Normal file
37
tests/tcg/i386/test-i386-fscale.c
Normal file
@ -0,0 +1,37 @@
|
||||
/* Test fscale instruction. */
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
union u {
|
||||
struct { uint64_t sig; uint16_t sign_exp; } s;
|
||||
long double ld;
|
||||
};
|
||||
|
||||
volatile long double ld_res;
|
||||
|
||||
int isnan_ld(long double x)
|
||||
{
|
||||
union u tmp = { .ld = x };
|
||||
return ((tmp.s.sign_exp & 0x7fff) == 0x7fff &&
|
||||
(tmp.s.sig >> 63) != 0 &&
|
||||
(tmp.s.sig << 1) != 0);
|
||||
}
|
||||
|
||||
int issignaling_ld(long double x)
|
||||
{
|
||||
union u tmp = { .ld = x };
|
||||
return isnan_ld(x) && (tmp.s.sig & UINT64_C(0x4000000000000000)) == 0;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int ret = 0;
|
||||
__asm__ volatile ("fscale" : "=t" (ld_res) :
|
||||
"0" (2.5L), "u" (__builtin_nansl("")));
|
||||
if (!isnan_ld(ld_res) || issignaling_ld(ld_res)) {
|
||||
printf("FAIL: fscale snan\n");
|
||||
ret = 1;
|
||||
}
|
||||
return ret;
|
||||
}
|
Loading…
Reference in New Issue
Block a user