[interp] Compress interpreter opcode names in usual way, offsets vs. pointers. (mono...
authorJay Krell <jaykrell@microsoft.com>
Fri, 30 Aug 2019 08:27:19 +0000 (01:27 -0700)
committerVlad Brezae <brezaevlad@gmail.com>
Fri, 30 Aug 2019 08:27:19 +0000 (11:27 +0300)
* [interp] Compress the interpreter opcode names in the usual way, by changing
from an array of pointers to an array of 16 bit offsets into one large "string".

* PR: Make mono_interp_opname a function.

Commit migrated from https://github.com/mono/mono/commit/36296ce291f8a7b19de3eccb7a32c7e4ed9df8f2

src/mono/mono/mini/interp/interp.c
src/mono/mono/mini/interp/mintops.c
src/mono/mono/mini/interp/mintops.h
src/mono/mono/mini/interp/transform.c

index 438b80a..bd4fdac 100644 (file)
@@ -6586,7 +6586,7 @@ main_loop:
                }
 
                MINT_IN_DEFAULT
-                       g_error ("Unimplemented opcode: %04x %s at 0x%x\n", *ip, mono_interp_opname[*ip], ip-frame->imethod->code);
+                       g_error ("Unimplemented opcode: %04x %s at 0x%x\n", *ip, mono_interp_opname (*ip), ip - frame->imethod->code);
                }
        }
 
index af1351c..1a3f9d6 100644 (file)
 #include <stdio.h>
 #include "mintops.h"
 
-#define OPDEF(a,b,c,d) b,
-const char * const mono_interp_opname [] = {
+// This, instead of an array of pointers, to optimize away a pointer and a relocation per string.
+struct MonoInterpOpnameCharacters {
+#define OPDEF(a, b, c, d) char a [sizeof (b)];
 #include "mintops.def"
 };
 #undef OPDEF
 
-#define OPDEF(a,b,c,d) c,
+extern const MonoInterpOpnameCharacters mono_interp_opname_characters = {
+#define OPDEF(a, b, c, d) b,
+#include "mintops.def"
+};
+#undef OPDEF
+
+extern const guint16 mono_interp_opname_offsets [] = {
+#define OPDEF(a, b, c, d) offsetof (MonoInterpOpnameCharacters, a),
+#include "mintops.def"
+#undef OPDEF
+};
+
+#define OPDEF(a, b, c, d) c,
 unsigned char const mono_interp_oplen [] = {
 #include "mintops.def"
 };
 #undef OPDEF
 
 
-#define OPDEF(a,b,c,d) d,
+#define OPDEF(a, b, c, d) d,
 MintOpArgType const mono_interp_opargtype [] = {
 #include "mintops.def"
 };
@@ -52,7 +65,7 @@ mono_interp_dis_mintop(const guint16 *base, const guint16 *ip)
        guint32 token;
        int target;
 
-       g_string_append_printf (str, "IL_%04x: %-10s", (int)(ip - base), mono_interp_opname [*ip]);
+       g_string_append_printf (str, "IL_%04x: %-10s", (int)(ip - base), mono_interp_opname (*ip));
        switch (mono_interp_opargtype [*ip]) {
        case MintOpNoArgs:
                break;
@@ -122,3 +135,8 @@ mono_interp_dis_mintop(const guint16 *base, const guint16 *ip)
        return g_string_free (str, FALSE);
 }
 
+const char*
+mono_interp_opname (int op)
+{
+       return ((const char*)&mono_interp_opname_characters) + mono_interp_opname_offsets [op];
+}
index e6a1203..f5793bf 100644 (file)
@@ -53,11 +53,17 @@ enum {
 
 #define MINT_SWITCH_LEN(n) (3 + (n) * 2)
 
-extern const char * const mono_interp_opname[];
 extern unsigned char const mono_interp_oplen[];
 extern MintOpArgType const mono_interp_opargtype[];
 extern char* mono_interp_dis_mintop(const unsigned short *base, const guint16 *ip);
 extern const guint16* mono_interp_dis_mintop_len (const guint16 *ip);
 
-#endif
+// This, instead of an array of pointers, to optimize away a pointer and a relocation per string.
+extern const guint16 mono_interp_opname_offsets [ ];
+typedef struct MonoInterpOpnameCharacters MonoInterpOpnameCharacters;
+extern const MonoInterpOpnameCharacters mono_interp_opname_characters;
+
+const char*
+mono_interp_opname (int op);
 
+#endif
index 3e3c027..ad4910d 100644 (file)
@@ -532,7 +532,7 @@ binary_arith_op(TransformData *td, int mint_op)
        if (type1 != type2) {
                g_warning("%s.%s: %04x arith type mismatch %s %d %d", 
                        m_class_get_name (td->method->klass), td->method->name,
-                       td->ip - td->il_code, mono_interp_opname[mint_op], type1, type2);
+                       td->ip - td->il_code, mono_interp_opname (mint_op), type1, type2);
        }
        op = mint_op + type1 - STACK_TYPE_I4;
        CHECK_STACK(td, 2);