2002-06-17 Dietmar Maurer <dietmar@ximian.com>
authorDietmar Maurer <dietmar@mono-cvs.ximian.com>
Mon, 17 Jun 2002 13:54:05 +0000 (13:54 -0000)
committerDietmar Maurer <dietmar@mono-cvs.ximian.com>
Mon, 17 Jun 2002 13:54:05 +0000 (13:54 -0000)
* x86.brg: added inlined versions of Math.Sin, Math.Cos, Math.Sqrt

svn path=/trunk/mono/; revision=5312

mono/benchmark/Makefile.am
mono/benchmark/math.cs [new file with mode: 0755]
mono/jit/ChangeLog
mono/jit/jit.c
mono/jit/x86.brg
mono/metadata/domain.c
mono/metadata/loader.h

index fb98ba1dffcb8a0657e391f2e4a72a5550383d2f..00b5f44c880ee04485baed3824a219a04a1aeec6 100644 (file)
@@ -15,7 +15,8 @@ TESTSRC=                      \
        loops.cs                \
        initlocals.cs           \
        logic.cs                \
-       bulkcpy.il
+       bulkcpy.il              \
+       math.cs
 
 TESTSI_TMP=$(TESTSRC:.cs=.exe)
 TESTSI=$(TESTSI_TMP:.il=.exe)
diff --git a/mono/benchmark/math.cs b/mono/benchmark/math.cs
new file mode 100755 (executable)
index 0000000..4ad8242
--- /dev/null
@@ -0,0 +1,31 @@
+using System;
+
+public class MulDiv {
+
+       public static double mathtest (int n) {
+               double res = 0;
+
+               for (int j = 0; j < 200000; j++) {
+                       res += Math.Sin (j);
+                       res += Math.Cos (j);
+               }
+               
+               return res;
+       }
+       
+       public static int Main (string[] args) {
+               int repeat = 1;
+               
+               if (args.Length == 1)
+                       repeat = Convert.ToInt32 (args [0]);
+               
+               Console.WriteLine ("Repeat = " + repeat);
+
+               for (int i = 0; i < (repeat * 50); i++)
+                       mathtest (1000);
+               
+               return 0;
+       }
+}
+
+
index 184a77ac7a0dbeba3225dc69607c84fec3520f98..a78b2169eaa683eba23605e6eeb039cce47f66dd 100644 (file)
@@ -1,5 +1,7 @@
 2002-06-17  Dietmar Maurer  <dietmar@ximian.com>
 
+       * x86.brg: added inlined versions of Math.Sin, Math.Cos, Math.Sqrt
+
        * jit.c (mono_analyze_stack): impl. STARG
        (mono_analyze_stack): impl. LDARGA
 
index c7cbed936499623a14296ae9721e37113ca7f92c..9dda6356960dfb2e7a2a99f5205f1fca7297f9e1 100644 (file)
@@ -2016,6 +2016,27 @@ mono_analyze_stack (MonoFlowGraph *cfg)
                                cm = mono_get_method (image, token, NULL);
                                g_assert (cm);
 
+                               if (cm->klass == mono_defaults.math_class &&
+                                   cm->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) {
+
+                                       if (!strcmp (cm->name, "Sin")) {
+                                               --sp;
+                                               t1 = mono_ctree_new (mp, MB_TERM_SIN, *sp, NULL);
+                                               PUSH_TREE (t1, VAL_DOUBLE);
+                                               break;
+                                       } else if (!strcmp (cm->name, "Cos")) {
+                                               --sp;
+                                               t1 = mono_ctree_new (mp, MB_TERM_COS, *sp, NULL);
+                                               PUSH_TREE (t1, VAL_DOUBLE);
+                                               break;
+                                       } else if (!strcmp (cm->name, "Sqrt")) {
+                                               --sp;
+                                               t1 = mono_ctree_new (mp, MB_TERM_SQRT, *sp, NULL);
+                                               PUSH_TREE (t1, VAL_DOUBLE);
+                                               break;
+                                       }
+                               }
+
                                if (cm->klass == mono_defaults.string_class &&
                                    *cm->name == '.' && !strcmp (cm->name, ".ctor"))
                                        g_assert_not_reached ();
index aa5dd609802e9758d336443bacde5ce83ed6875b..eebddbdd79568e485cf73f37f4191aed20201b7b 100644 (file)
@@ -237,6 +237,7 @@ debug_memcopy (void *dest, const void *src, size_t n);
 %term LDLEN LDELEMA LDFTN LDVIRTFTN LDSTR LDSFLDA
 %term REMOTE_LDFLDA REMOTE_STIND_I1 REMOTE_STIND_I2 REMOTE_STIND_I4
 %term REMOTE_STIND_I8 REMOTE_STIND_R4 REMOTE_STIND_R8 REMOTE_STIND_OBJ
+%term SIN COS SQRT
 #
 # we start at stmt
 #
@@ -4586,6 +4587,18 @@ stmt: RET (freg) {
        }
 }
 
+freg: SIN (freg) {
+       x86_fsin (s->code);
+}
+
+freg: COS (freg) {
+       x86_fcos (s->code);
+}
+
+freg: SQRT (freg) {
+       x86_fsqrt (s->code);
+}
+
 # support for value types
 
 reg: LDIND_OBJ (reg) {
index 19f44f3623168beabad0552b2c8729984e29163f..4695e3fa607e8bbfd13a46ded999559ffaed2150 100644 (file)
@@ -344,6 +344,10 @@ mono_init (const char *filename)
                mono_defaults.corlib, "System.Reflection", "FieldInfo");
        g_assert (mono_defaults.field_info_class != 0);
 
+       mono_defaults.math_class = mono_class_from_name (
+               mono_defaults.corlib, "System", "Math");
+       g_assert (mono_defaults.math_class != 0);
+
        domain->friendly_name = g_path_get_basename (filename);
 
        return domain;
index 844873402013e6a72d301fd9f018d0f7d5d98540..cf286294cd233c6e5b8bf179997da96c5e06aca1 100644 (file)
@@ -69,6 +69,7 @@ typedef struct {
        MonoClass *mono_method_message_class;
        MonoClass *appdomain_class;
        MonoClass *field_info_class;
+       MonoClass *math_class;
 } MonoDefaults;
 
 extern MonoDefaults mono_defaults;