From 949eb11776039604d031e8a47db81cc44eca2f14 Mon Sep 17 00:00:00 2001 From: Stanislav Shwartsman Date: Wed, 13 Nov 2024 08:12:44 +0200 Subject: [PATCH] correctly handle special case of lowest negative number like -0x80 or -0x8000 this is correctly representable as negative integer and should not raise #IE --- bochs/cpu/softfloat3e/f16_to_i16.c | 1 + bochs/cpu/softfloat3e/f16_to_i8.c | 2 -- bochs/cpu/softfloat3e/f16_to_i8_r_minMag.c | 8 +++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bochs/cpu/softfloat3e/f16_to_i16.c b/bochs/cpu/softfloat3e/f16_to_i16.c index 12a15a1b2..3b3897b74 100644 --- a/bochs/cpu/softfloat3e/f16_to_i16.c +++ b/bochs/cpu/softfloat3e/f16_to_i16.c @@ -76,6 +76,7 @@ int16_t f16_to_i16(float16 a, uint8_t roundingMode, bool exact, struct softfloat if (0 <= shiftDist) { sig32 <<= shiftDist; if (shiftDist > 4) { + if (a == packToF16UI(1, 0x1E, 0)) return -0x7FFF - 1; softfloat_raiseFlags(status, softfloat_flag_invalid); return sign ? i16_fromNegOverflow : i16_fromPosOverflow; } diff --git a/bochs/cpu/softfloat3e/f16_to_i8.c b/bochs/cpu/softfloat3e/f16_to_i8.c index a1462d8a7..567505195 100644 --- a/bochs/cpu/softfloat3e/f16_to_i8.c +++ b/bochs/cpu/softfloat3e/f16_to_i8.c @@ -61,8 +61,6 @@ int8_t f16_to_i8(float16 a, uint8_t roundingMode, bool exact, bool saturate, str *------------------------------------------------------------------------*/ shiftDist = 0x16 - exp; if (shiftDist < 0) { - if (a == packToF16UI(1, 0x16, 0)) return -0x7F - 1; - const int8_t NegOverflowResponse = saturate ? i8_minNegativeValue : i8_fromNegOverflow; const int8_t PosOverflowResponse = saturate ? i8_maxPositiveValue : i8_fromPosOverflow; diff --git a/bochs/cpu/softfloat3e/f16_to_i8_r_minMag.c b/bochs/cpu/softfloat3e/f16_to_i8_r_minMag.c index 6966b614a..354551b53 100644 --- a/bochs/cpu/softfloat3e/f16_to_i8_r_minMag.c +++ b/bochs/cpu/softfloat3e/f16_to_i8_r_minMag.c @@ -64,7 +64,13 @@ int8_t f16_to_i8_r_minMag(float16 a, bool exact, bool saturate, struct softfloat *------------------------------------------------------------------------*/ shiftDist = 0x19 - exp; if (shiftDist <= 3) { - if (a == packToF16UI(1, 0x16, 0)) return -0x7F - 1; + if (shiftDist == 3) { + uint16_t roundMask = a & 0x7; + if ((a & ~roundMask) == packToF16UI(1, 0x16, 0)) { + if (roundMask) softfloat_raiseFlags(status, softfloat_flag_inexact); + return -0x7F - 1; + } + } const int8_t NaN_response = saturate ? 0 : i8_fromNaN; const int8_t NegOverflowResponse = saturate ? i8_minNegativeValue : i8_fromNegOverflow;