From 0bf364585cc59a57fd99f25f36b35cb515fe6062 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 18 Apr 2018 21:42:45 +0200 Subject: [PATCH] fix fmin/fmax PR --- .../Instruction/AInstEmitSimdArithmetic.cs | 16 ++-- ChocolArm64/Instruction/ASoftFallback.cs | 73 ++++++++----------- 2 files changed, 40 insertions(+), 49 deletions(-) diff --git a/ChocolArm64/Instruction/AInstEmitSimdArithmetic.cs b/ChocolArm64/Instruction/AInstEmitSimdArithmetic.cs index 21e494c2dc..39450c2477 100644 --- a/ChocolArm64/Instruction/AInstEmitSimdArithmetic.cs +++ b/ChocolArm64/Instruction/AInstEmitSimdArithmetic.cs @@ -217,11 +217,11 @@ namespace ChocolArm64.Instruction { if (Op.Size == 0) { - ASoftFallback.EmitCall(Context, nameof(ASoftFallback.CustomMaxF)); + ASoftFallback.EmitCall(Context, nameof(ASoftFallback.MaxF)); } else if (Op.Size == 1) { - ASoftFallback.EmitCall(Context, nameof(ASoftFallback.CustomMax)); + ASoftFallback.EmitCall(Context, nameof(ASoftFallback.Max)); } else { @@ -238,11 +238,11 @@ namespace ChocolArm64.Instruction { if (Op.Size == 0) { - ASoftFallback.EmitCall(Context, nameof(ASoftFallback.CustomMaxF)); + ASoftFallback.EmitCall(Context, nameof(ASoftFallback.MaxF)); } else if (Op.Size == 1) { - ASoftFallback.EmitCall(Context, nameof(ASoftFallback.CustomMax)); + ASoftFallback.EmitCall(Context, nameof(ASoftFallback.Max)); } else { @@ -258,11 +258,11 @@ namespace ChocolArm64.Instruction { if (Op.Size == 0) { - ASoftFallback.EmitCall(Context, nameof(ASoftFallback.CustomMinF)); + ASoftFallback.EmitCall(Context, nameof(ASoftFallback.MinF)); } else if (Op.Size == 1) { - ASoftFallback.EmitCall(Context, nameof(ASoftFallback.CustomMin)); + ASoftFallback.EmitCall(Context, nameof(ASoftFallback.Min)); } else { @@ -279,11 +279,11 @@ namespace ChocolArm64.Instruction { if (Op.Size == 2) { - ASoftFallback.EmitCall(Context, nameof(ASoftFallback.CustomMinF)); + ASoftFallback.EmitCall(Context, nameof(ASoftFallback.MinF)); } else if (Op.Size == 3) { - ASoftFallback.EmitCall(Context, nameof(ASoftFallback.CustomMin)); + ASoftFallback.EmitCall(Context, nameof(ASoftFallback.Min)); } else { diff --git a/ChocolArm64/Instruction/ASoftFallback.cs b/ChocolArm64/Instruction/ASoftFallback.cs index 77577c1e64..5fb17f7fcb 100644 --- a/ChocolArm64/Instruction/ASoftFallback.cs +++ b/ChocolArm64/Instruction/ASoftFallback.cs @@ -256,104 +256,95 @@ namespace ChocolArm64.Instruction ((Value >> 6) & 1) + (Value >> 7); } - public static float CustomMaxF(float val1, float val2) + public static float MaxF(float val1, float val2) { - if(val1 == 0.0 && val2 == 0.0) + if (val1 == 0.0 && val2 == 0.0) { + if (BitConverter.SingleToInt32Bits(val1) < 0 && BitConverter.SingleToInt32Bits(val2) < 0) + return -0.0f; - if(BitConverter.GetBytes(val1)[3] == 0x80 && BitConverter.GetBytes(val2)[3] == 0x80) - return (float)-0.0; + if (BitConverter.SingleToInt32Bits(val1) < 0 || BitConverter.SingleToInt32Bits(val2) < 0) + return 0.0f; - if(BitConverter.GetBytes(val1)[3] == 0x80 || BitConverter.GetBytes(val2)[3] == 0x80) - return (float)0.0; - - return (float)0.0; + return 0.0f; } - if(val1 > val2) + if (val1 > val2) return val1; - if(Single.IsNaN(val1)) + if (float.IsNaN(val1)) return val1; return val2; } - public static double CustomMax(double val1, double val2) + public static double Max(double val1, double val2) { - if(val1 == 0.0 && val2 == 0.0) + if (val1 == 0.0 && val2 == 0.0) { - if(BitConverter.GetBytes(val1)[7] == 0x80 && BitConverter.GetBytes(val2)[7] == 0x80) + if (BitConverter.DoubleToInt64Bits(val1) < 0 && BitConverter.DoubleToInt64Bits(val2) < 0) return -0.0; - if(BitConverter.GetBytes(val1)[7] == 0x80 || BitConverter.GetBytes(val2)[7] == 0x80) + if (BitConverter.DoubleToInt64Bits(val1) < 0 || BitConverter.DoubleToInt64Bits(val2) < 0) return 0.0; return 0.0; } - if(val1 > val2) + if (val1 > val2) return val1; - if(Double.IsNaN(val1)) + if (double.IsNaN(val1)) return val1; return val2; } - public static float CustomMinF(float val1, float val2) + public static float MinF(float val1, float val2) { - if((val1 == 0.0 && val2 >= 0.0) || (val1 >= 0.0 && val2 == 0.0)) + if ((val1 == 0.0 && val2 >= 0.0) || (val1 >= 0.0 && val2 == 0.0)) { - if(BitConverter.GetBytes(val1)[3] == 0x80 || BitConverter.GetBytes(val2)[3] == 0x80) - return (float)-0.0; + if (BitConverter.SingleToInt32Bits(val1) < 0 || BitConverter.SingleToInt32Bits(val2) < 0) + return -0.0f; } - if(val1 == 0.0 && val2 == 0.0) + if (val1 == 0.0 && val2 == 0.0) { + if (BitConverter.SingleToInt32Bits(val1) < 0 || BitConverter.SingleToInt32Bits(val2) < 0) + return -0.0f; - if(BitConverter.GetBytes(val1)[3] == 0x80 && BitConverter.GetBytes(val2)[3] == 0x80) - return (float)-0.0; - - if(BitConverter.GetBytes(val1)[3] == 0x80 || BitConverter.GetBytes(val2)[3] == 0x80) - return (float)-0.0; - - return (float)0.0; + return 0.0f; } - if(val1 < val2) + if (val1 < val2) return val1; - if(Single.IsNaN(val1)) + if (float.IsNaN(val1)) return val1; return val2; } - public static double CustomMin(double val1, double val2) + public static double Min(double val1, double val2) { - if((val1 == 0.0 && val2 >= 0.0) || (val1 >= 0.0 && val2 == 0.0)) + if ((val1 == 0.0 && val2 >= 0.0) || (val1 >= 0.0 && val2 == 0.0)) { - if(BitConverter.GetBytes(val1)[7] == 0x80 || BitConverter.GetBytes(val2)[7] == 0x80) + if (BitConverter.DoubleToInt64Bits(val1) < 0 || BitConverter.DoubleToInt64Bits(val2) < 0) return -0.0; } - if(val1 == 0.0 && val2 == 0.0) + if (val1 == 0.0 && val2 == 0.0) { - - if(BitConverter.GetBytes(val1)[7] == 0x80 && BitConverter.GetBytes(val2)[7] == 0x80) - return -0.0; - - if(BitConverter.GetBytes(val1)[7] == 0x80 || BitConverter.GetBytes(val2)[7] == 0x80) + if (BitConverter.DoubleToInt64Bits(val1) < 0 || BitConverter.DoubleToInt64Bits(val2) < 0) return -0.0; return 0.0; } - if(val1 < val2) + if (val1 < val2) return val1; - if(Double.IsNaN(val1)) + if (double.IsNaN(val1)) return val1; return val2;