Skip to content

Commit

Permalink
Fixed conv.r.un bug
Browse files Browse the repository at this point in the history
  • Loading branch information
anydream committed Sep 29, 2017
1 parent fd89ee0 commit b192cd9
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 9 deletions.
2 changes: 1 addition & 1 deletion il2cpp/MethodGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ private void GenerateInstCode(InstInfo inst)
GenConv(inst, StackType.R8, "double");
return;
case Code.Conv_R_Un:
GenConv(inst, StackType.R8, "uintptr_t");
GenConv(inst, StackType.R8, "uint32_t");
return;
case Code.Conv_I:
GenConv(inst, StackType.Ptr, "intptr_t");
Expand Down
2 changes: 1 addition & 1 deletion runtime/il2cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void il2cpp_CheckRange(int32_t lowerBound, int32_t length, int32_t index)

float il2cpp_Remainder(float numer, float denom)
{
return remainder(numer, denom);
return remainderf(numer, denom);
}

double il2cpp_Remainder(double numer, double denom)
Expand Down
107 changes: 100 additions & 7 deletions test/testcase/CodeGenTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using System.Diagnostics;
using System.IO;

namespace testcase
{
Expand Down Expand Up @@ -145,13 +145,41 @@ public static int Entry()
[CodeGen]
static class TestStaticCctor2
{
class MyCls
{
public static float sfldR4 = 6.28f;

public static void StaticEmpty()
{
}

public static float StaticGet()
{
return sfldR4;
}

public static bool StaticEq(float cmp)
{
return sfldR4 == cmp;
}
}

public static int Entry()
{
if (TestStaticCctor.ClsB.sfld != 1035)
return 1;
if (TestStaticCctor.ClsA.sfld != 579)
return 2;

MyCls.StaticEmpty();
float val = MyCls.StaticGet();
bool eq = MyCls.StaticEq(val);

if (val != 6.28f)
return 3;
if (!eq)
return 4;

return 0;
}
}
Expand Down Expand Up @@ -617,11 +645,66 @@ public static int Entry()
[CodeGen]
static class TestRayTrace
{
#if true
static extern double MathSqrt(double n);
static extern double MathAbs(double n);
static extern double MathSin(double n);
static extern double MathCos(double n);
static extern double MathPow(double n, double m);
#else
/*[DllImport("msvcrt.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
public static extern double sqrt(double n);
[DllImport("msvcrt.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
public static extern double fabs(double n);
[DllImport("msvcrt.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
public static extern double sin(double n);
[DllImport("msvcrt.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
public static extern double cos(double n);
[DllImport("msvcrt.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
public static extern double pow(double n, double m);
static double MathSqrt(double n)
{
return sqrt(n);
}
static double MathAbs(double n)
{
return fabs(n);
}
static double MathSin(double n)
{
return sin(n);
}
static double MathCos(double n)
{
return cos(n);
}
static double MathPow(double n, double m)
{
return pow(n, m);
}*/
static double MathSqrt(double n)
{
return Math.Sqrt(n);
}
static double MathAbs(double n)
{
return Math.Abs(n);
}
static double MathSin(double n)
{
return Math.Sin(n);
}
static double MathCos(double n)
{
return Math.Cos(n);
}
static double MathPow(double n, double m)
{
return Math.Pow(n, m);
}
#endif

static double MathMax(double v1, double v2)
{
Expand All @@ -646,7 +729,7 @@ public double NextDouble()
}
}

struct Vec
public struct Vec
{
public double x;
public double y;
Expand Down Expand Up @@ -780,7 +863,7 @@ public double intersect(ref Ray r)
}
};

class Smallpt
public class Smallpt
{
//Scene: radius, position, emission, color, material
static Sphere[] spheres =
Expand Down Expand Up @@ -814,7 +897,7 @@ static double clamp(double x)
return x;
}

static int toInt(double x)
public static int toInt(double x)
{
return (int)(MathPow(clamp(x), 1 / 2.2) * 255 + .5);
}
Expand Down Expand Up @@ -1004,7 +1087,7 @@ static void radiance(out Vec rad, ref Ray r, int depth)
}
}

public static void Entry()
public static Vec[] RenderEntry()
{
const int w = 256;
const int h = 256;
Expand Down Expand Up @@ -1084,19 +1167,29 @@ public static void Entry()
}
}
}
return c;
}
}

public static void Entry()
public static Vec[] Entry()
{
Smallpt.Entry();
return Smallpt.RenderEntry();
}
}

internal class Program
{
private static void Main()
{
var c = TestRayTrace.Entry();

using (StreamWriter sw = new StreamWriter("imageCS.ppm"))
{
sw.Write("P3\r\n{0} {1}\r\n{2}\r\n", 256, 256, 255);
for (int i = 0; i < 256 * 256; i++)
sw.Write("{0} {1} {2}\r\n", TestRayTrace.Smallpt.toInt(c[i].x), TestRayTrace.Smallpt.toInt(c[i].y), TestRayTrace.Smallpt.toInt(c[i].z));
}

//Console.Write("Input Times: ");
//int times = int.Parse(Console.ReadLine());
//Console.WriteLine("Times: {0}", times);
Expand Down

0 comments on commit b192cd9

Please sign in to comment.