fix fmin/fmax PR

This commit is contained in:
unknown 2018-04-18 21:42:45 +02:00
commit 0bf364585c
2 changed files with 40 additions and 49 deletions

View file

@ -217,11 +217,11 @@ namespace ChocolArm64.Instruction
{ {
if (Op.Size == 0) if (Op.Size == 0)
{ {
ASoftFallback.EmitCall(Context, nameof(ASoftFallback.CustomMaxF)); ASoftFallback.EmitCall(Context, nameof(ASoftFallback.MaxF));
} }
else if (Op.Size == 1) else if (Op.Size == 1)
{ {
ASoftFallback.EmitCall(Context, nameof(ASoftFallback.CustomMax)); ASoftFallback.EmitCall(Context, nameof(ASoftFallback.Max));
} }
else else
{ {
@ -238,11 +238,11 @@ namespace ChocolArm64.Instruction
{ {
if (Op.Size == 0) if (Op.Size == 0)
{ {
ASoftFallback.EmitCall(Context, nameof(ASoftFallback.CustomMaxF)); ASoftFallback.EmitCall(Context, nameof(ASoftFallback.MaxF));
} }
else if (Op.Size == 1) else if (Op.Size == 1)
{ {
ASoftFallback.EmitCall(Context, nameof(ASoftFallback.CustomMax)); ASoftFallback.EmitCall(Context, nameof(ASoftFallback.Max));
} }
else else
{ {
@ -258,11 +258,11 @@ namespace ChocolArm64.Instruction
{ {
if (Op.Size == 0) if (Op.Size == 0)
{ {
ASoftFallback.EmitCall(Context, nameof(ASoftFallback.CustomMinF)); ASoftFallback.EmitCall(Context, nameof(ASoftFallback.MinF));
} }
else if (Op.Size == 1) else if (Op.Size == 1)
{ {
ASoftFallback.EmitCall(Context, nameof(ASoftFallback.CustomMin)); ASoftFallback.EmitCall(Context, nameof(ASoftFallback.Min));
} }
else else
{ {
@ -279,11 +279,11 @@ namespace ChocolArm64.Instruction
{ {
if (Op.Size == 2) if (Op.Size == 2)
{ {
ASoftFallback.EmitCall(Context, nameof(ASoftFallback.CustomMinF)); ASoftFallback.EmitCall(Context, nameof(ASoftFallback.MinF));
} }
else if (Op.Size == 3) else if (Op.Size == 3)
{ {
ASoftFallback.EmitCall(Context, nameof(ASoftFallback.CustomMin)); ASoftFallback.EmitCall(Context, nameof(ASoftFallback.Min));
} }
else else
{ {

View file

@ -256,104 +256,95 @@ namespace ChocolArm64.Instruction
((Value >> 6) & 1) + (Value >> 7); ((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) if (BitConverter.SingleToInt32Bits(val1) < 0 || BitConverter.SingleToInt32Bits(val2) < 0)
return (float)-0.0; return 0.0f;
if(BitConverter.GetBytes(val1)[3] == 0x80 || BitConverter.GetBytes(val2)[3] == 0x80) return 0.0f;
return (float)0.0;
return (float)0.0;
} }
if(val1 > val2) if (val1 > val2)
return val1; return val1;
if(Single.IsNaN(val1)) if (float.IsNaN(val1))
return val1; return val1;
return val2; 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; 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;
return 0.0; return 0.0;
} }
if(val1 > val2) if (val1 > val2)
return val1; return val1;
if(Double.IsNaN(val1)) if (double.IsNaN(val1))
return val1; return val1;
return val2; 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) if (BitConverter.SingleToInt32Bits(val1) < 0 || BitConverter.SingleToInt32Bits(val2) < 0)
return (float)-0.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 0.0f;
return (float)-0.0;
if(BitConverter.GetBytes(val1)[3] == 0x80 || BitConverter.GetBytes(val2)[3] == 0x80)
return (float)-0.0;
return (float)0.0;
} }
if(val1 < val2) if (val1 < val2)
return val1; return val1;
if(Single.IsNaN(val1)) if (float.IsNaN(val1))
return val1; return val1;
return val2; 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; return -0.0;
} }
if(val1 == 0.0 && val2 == 0.0) if (val1 == 0.0 && val2 == 0.0)
{ {
if (BitConverter.DoubleToInt64Bits(val1) < 0 || BitConverter.DoubleToInt64Bits(val2) < 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)
return -0.0; return -0.0;
return 0.0; return 0.0;
} }
if(val1 < val2) if (val1 < val2)
return val1; return val1;
if(Double.IsNaN(val1)) if (double.IsNaN(val1))
return val1; return val1;
return val2; return val2;