Skip to content

Commit b192cd9

Browse files
committed
Fixed conv.r.un bug
1 parent fd89ee0 commit b192cd9

3 files changed

Lines changed: 102 additions & 9 deletions

File tree

il2cpp/MethodGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ private void GenerateInstCode(InstInfo inst)
11421142
GenConv(inst, StackType.R8, "double");
11431143
return;
11441144
case Code.Conv_R_Un:
1145-
GenConv(inst, StackType.R8, "uintptr_t");
1145+
GenConv(inst, StackType.R8, "uint32_t");
11461146
return;
11471147
case Code.Conv_I:
11481148
GenConv(inst, StackType.Ptr, "intptr_t");

runtime/il2cpp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void il2cpp_CheckRange(int32_t lowerBound, int32_t length, int32_t index)
4545

4646
float il2cpp_Remainder(float numer, float denom)
4747
{
48-
return remainder(numer, denom);
48+
return remainderf(numer, denom);
4949
}
5050

5151
double il2cpp_Remainder(double numer, double denom)

test/testcase/CodeGenTests.cs

Lines changed: 100 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System;
2-
using System.Diagnostics;
2+
using System.IO;
33

44
namespace testcase
55
{
@@ -145,13 +145,41 @@ public static int Entry()
145145
[CodeGen]
146146
static class TestStaticCctor2
147147
{
148+
class MyCls
149+
{
150+
public static float sfldR4 = 6.28f;
151+
152+
public static void StaticEmpty()
153+
{
154+
}
155+
156+
public static float StaticGet()
157+
{
158+
return sfldR4;
159+
}
160+
161+
public static bool StaticEq(float cmp)
162+
{
163+
return sfldR4 == cmp;
164+
}
165+
}
166+
148167
public static int Entry()
149168
{
150169
if (TestStaticCctor.ClsB.sfld != 1035)
151170
return 1;
152171
if (TestStaticCctor.ClsA.sfld != 579)
153172
return 2;
154173

174+
MyCls.StaticEmpty();
175+
float val = MyCls.StaticGet();
176+
bool eq = MyCls.StaticEq(val);
177+
178+
if (val != 6.28f)
179+
return 3;
180+
if (!eq)
181+
return 4;
182+
155183
return 0;
156184
}
157185
}
@@ -617,11 +645,66 @@ public static int Entry()
617645
[CodeGen]
618646
static class TestRayTrace
619647
{
648+
#if true
620649
static extern double MathSqrt(double n);
621650
static extern double MathAbs(double n);
622651
static extern double MathSin(double n);
623652
static extern double MathCos(double n);
624653
static extern double MathPow(double n, double m);
654+
#else
655+
/*[DllImport("msvcrt.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
656+
public static extern double sqrt(double n);
657+
[DllImport("msvcrt.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
658+
public static extern double fabs(double n);
659+
[DllImport("msvcrt.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
660+
public static extern double sin(double n);
661+
[DllImport("msvcrt.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
662+
public static extern double cos(double n);
663+
[DllImport("msvcrt.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
664+
public static extern double pow(double n, double m);
665+
666+
static double MathSqrt(double n)
667+
{
668+
return sqrt(n);
669+
}
670+
static double MathAbs(double n)
671+
{
672+
return fabs(n);
673+
}
674+
static double MathSin(double n)
675+
{
676+
return sin(n);
677+
}
678+
static double MathCos(double n)
679+
{
680+
return cos(n);
681+
}
682+
static double MathPow(double n, double m)
683+
{
684+
return pow(n, m);
685+
686+
}*/
687+
static double MathSqrt(double n)
688+
{
689+
return Math.Sqrt(n);
690+
}
691+
static double MathAbs(double n)
692+
{
693+
return Math.Abs(n);
694+
}
695+
static double MathSin(double n)
696+
{
697+
return Math.Sin(n);
698+
}
699+
static double MathCos(double n)
700+
{
701+
return Math.Cos(n);
702+
}
703+
static double MathPow(double n, double m)
704+
{
705+
return Math.Pow(n, m);
706+
}
707+
#endif
625708

626709
static double MathMax(double v1, double v2)
627710
{
@@ -646,7 +729,7 @@ public double NextDouble()
646729
}
647730
}
648731

649-
struct Vec
732+
public struct Vec
650733
{
651734
public double x;
652735
public double y;
@@ -780,7 +863,7 @@ public double intersect(ref Ray r)
780863
}
781864
};
782865

783-
class Smallpt
866+
public class Smallpt
784867
{
785868
//Scene: radius, position, emission, color, material
786869
static Sphere[] spheres =
@@ -814,7 +897,7 @@ static double clamp(double x)
814897
return x;
815898
}
816899

817-
static int toInt(double x)
900+
public static int toInt(double x)
818901
{
819902
return (int)(MathPow(clamp(x), 1 / 2.2) * 255 + .5);
820903
}
@@ -1004,7 +1087,7 @@ static void radiance(out Vec rad, ref Ray r, int depth)
10041087
}
10051088
}
10061089

1007-
public static void Entry()
1090+
public static Vec[] RenderEntry()
10081091
{
10091092
const int w = 256;
10101093
const int h = 256;
@@ -1084,19 +1167,29 @@ public static void Entry()
10841167
}
10851168
}
10861169
}
1170+
return c;
10871171
}
10881172
}
10891173

1090-
public static void Entry()
1174+
public static Vec[] Entry()
10911175
{
1092-
Smallpt.Entry();
1176+
return Smallpt.RenderEntry();
10931177
}
10941178
}
10951179

10961180
internal class Program
10971181
{
10981182
private static void Main()
10991183
{
1184+
var c = TestRayTrace.Entry();
1185+
1186+
using (StreamWriter sw = new StreamWriter("imageCS.ppm"))
1187+
{
1188+
sw.Write("P3\r\n{0} {1}\r\n{2}\r\n", 256, 256, 255);
1189+
for (int i = 0; i < 256 * 256; i++)
1190+
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));
1191+
}
1192+
11001193
//Console.Write("Input Times: ");
11011194
//int times = int.Parse(Console.ReadLine());
11021195
//Console.WriteLine("Times: {0}", times);

0 commit comments

Comments
 (0)