Skip to content

Commit

Permalink
correctly handle special case of lowest negative number like -0x80 or…
Browse files Browse the repository at this point in the history
… -0x8000

this is correctly representable as negative integer and should not raise #IE
  • Loading branch information
Stanislav Shwartsman committed Nov 13, 2024
1 parent 3ee35f1 commit 949eb11
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions bochs/cpu/softfloat3e/f16_to_i16.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 0 additions & 2 deletions bochs/cpu/softfloat3e/f16_to_i8.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 7 additions & 1 deletion bochs/cpu/softfloat3e/f16_to_i8_r_minMag.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 949eb11

Please sign in to comment.