aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMerry <MerryMage@users.noreply.github.com>2018-07-08 16:41:46 +0100
committergdkchan <gab.dark.100@gmail.com>2018-07-08 12:41:46 -0300
commitaf1516a1466de474c7f8fb5f564219b9323e1c26 (patch)
tree19b0845b6ba07bfaa4b0221d3d8e2a1faabcf9d6
parent0bec547b9dc11cb01c42db7f015cc47a0e649f6b (diff)
ASoftFloat: Fix InvSqrtEstimate for negative values (#233)
-rw-r--r--ChocolArm64/Instruction/ASoftFloat.cs20
1 files changed, 13 insertions, 7 deletions
diff --git a/ChocolArm64/Instruction/ASoftFloat.cs b/ChocolArm64/Instruction/ASoftFloat.cs
index 7bee69ba..1bd71665 100644
--- a/ChocolArm64/Instruction/ASoftFloat.cs
+++ b/ChocolArm64/Instruction/ASoftFloat.cs
@@ -50,14 +50,8 @@ namespace ChocolArm64.Instruction
long x_exp = (long)((x_bits >> 52) & 0x7FF);
ulong scaled = x_bits & ((1ul << 52) - 1);
- if (x_exp == 0x7ff)
+ if (x_exp == 0x7FF && scaled != 0)
{
- if (scaled == 0)
- {
- // Infinity -> Zero
- return BitConverter.Int64BitsToDouble((long)x_sign);
- }
-
// NaN
return BitConverter.Int64BitsToDouble((long)(x_bits | 0x0008000000000000));
}
@@ -79,6 +73,18 @@ namespace ChocolArm64.Instruction
scaled <<= 1;
}
+ if (x_sign != 0)
+ {
+ // Negative -> NaN
+ return BitConverter.Int64BitsToDouble((long)0x7ff8000000000000);
+ }
+
+ if (x_exp == 0x7ff && scaled == 0)
+ {
+ // Infinity -> Zero
+ return BitConverter.Int64BitsToDouble((long)x_sign);
+ }
+
if (((ulong)x_exp & 1) == 1)
{
scaled >>= 45;