On Tue, Feb 18, 2014 at 03:11:01PM +0000, Nicholas Clark wrote:
> Attached is the proposed patch, which implements compiler based probing for
> the MoarVM Configure.pl. Tested on OS X, FreeBSD, Linux, HP/UX and AIX.
> Not tested on Win32, so might not work there without tweaks.
Attached are 5 patches which build on the probing patch, to create a
MVM_STATIC_INLINE macro, and then use it to inline various functions from
sc.c, and convert 2 macros in sc.h to inline functions.
I can't actually measure any speedup (or slowdown) from the generated code.
(Yes, Rakudo builds and passes tests)
But the source code (in my opinion) much cleaner this way.
Nicholas Clark
>From 07ab8cc35266b9377da60c501a1ccc261444e9a5 Mon Sep 17 00:00:00 2001
From: Nicholas Clark <n...@ccl4.org>
Date: Tue, 18 Feb 2014 15:22:35 +0100
Subject: [PATCH 2/6] Add a #define MVM_STATIC_INLINE to gen/config.h
---
build/config.h.in | 3 +++
1 file changed, 3 insertions(+)
diff --git a/build/config.h.in b/build/config.h.in
index b938fcf..acc8cb0 100644
--- a/build/config.h.in
+++ b/build/config.h.in
@@ -35,3 +35,6 @@
#if @profilecalls@
#define MVM_HLL_PROFILE_CALLS @profilecalls@
#endif
+
+/* How this compiler does static inline functions. */
+#define MVM_STATIC_INLINE @static_inline@
--
1.8.4.2
>From 3e79e0f9e899f27bbd67633294ba7a76d6bc04c3 Mon Sep 17 00:00:00 2001
From: Nicholas Clark <n...@ccl4.org>
Date: Tue, 18 Feb 2014 15:23:08 +0100
Subject: [PATCH 3/6] Convert MVM_sc_{get,set}_{obj,stable}_sc to inline
functions.
This requires moving the include of "gc/wb.h" earlier, as the inline functions
use the macro it declares within their bodies.
---
src/6model/sc.c | 28 ----------------------------
src/6model/sc.h | 34 ++++++++++++++++++++++++++++++----
src/moar.h | 2 +-
3 files changed, 31 insertions(+), 33 deletions(-)
diff --git a/src/6model/sc.c b/src/6model/sc.c
index 8ff6890..f6a992c 100644
--- a/src/6model/sc.c
+++ b/src/6model/sc.c
@@ -255,34 +255,6 @@ MVMuint64 MVM_sc_get_object_count(MVMThreadContext *tc, MVMSerializationContext
return sc->body->num_objects;
}
-/* Gets an object's SC. */
-MVMSerializationContext * MVM_sc_get_obj_sc(MVMThreadContext *tc, MVMObject *obj) {
- assert(!(obj->header.flags & MVM_CF_GEN2_LIVE));
- assert(!(obj->header.flags & MVM_CF_FORWARDER_VALID));
- return obj->header.sc_forward_u.sc;
-}
-
-/* Gets an STables's SC. */
-MVMSerializationContext * MVM_sc_get_stable_sc(MVMThreadContext *tc, MVMSTable *st) {
- assert(!(st->header.flags & MVM_CF_GEN2_LIVE));
- assert(!(st->header.flags & MVM_CF_FORWARDER_VALID));
- return st->header.sc_forward_u.sc;
-}
-
-/* Sets an object's SC. */
-void MVM_sc_set_obj_sc(MVMThreadContext *tc, MVMObject *obj, MVMSerializationContext *sc) {
- assert(!(obj->header.flags & MVM_CF_GEN2_LIVE));
- assert(!(obj->header.flags & MVM_CF_FORWARDER_VALID));
- MVM_ASSIGN_REF(tc, obj, obj->header.sc_forward_u.sc, sc);
-}
-
-/* Sets an STable's SC. */
-void MVM_sc_set_stable_sc(MVMThreadContext *tc, MVMSTable *st, MVMSerializationContext *sc) {
- assert(!(st->header.flags & MVM_CF_GEN2_LIVE));
- assert(!(st->header.flags & MVM_CF_FORWARDER_VALID));
- MVM_ASSIGN_REF(tc, st, st->header.sc_forward_u.sc, sc);
-}
-
/* Resolves an SC handle using the SC weakhash. */
MVMSerializationContext * MVM_sc_find_by_handle(MVMThreadContext *tc, MVMString *handle) {
MVMSerializationContextBody *scb;
diff --git a/src/6model/sc.h b/src/6model/sc.h
index 3671bfb..e3c1f2f 100644
--- a/src/6model/sc.h
+++ b/src/6model/sc.h
@@ -18,13 +18,39 @@ MVMObject * MVM_sc_get_code(MVMThreadContext *tc, MVMSerializationContext *sc, M
void MVM_sc_set_code(MVMThreadContext *tc, MVMSerializationContext *sc, MVMint64 idx, MVMObject *code);
void MVM_sc_set_code_list(MVMThreadContext *tc, MVMSerializationContext *sc, MVMObject *code_list);
MVMuint64 MVM_sc_get_object_count(MVMThreadContext *tc, MVMSerializationContext *sc);
-MVMSerializationContext * MVM_sc_get_obj_sc(MVMThreadContext *tc, MVMObject *obj);
-MVMSerializationContext * MVM_sc_get_stable_sc(MVMThreadContext *tc, MVMSTable *st);
-void MVM_sc_set_obj_sc(MVMThreadContext *tc, MVMObject *obj, MVMSerializationContext *sc);
-void MVM_sc_set_stable_sc(MVMThreadContext *tc, MVMSTable *st, MVMSerializationContext *sc);
MVMSerializationContext * MVM_sc_find_by_handle(MVMThreadContext *tc, MVMString *handle);
MVMSerializationContext * MVM_sc_get_sc(MVMThreadContext *tc, MVMCompUnit *cu, MVMint16 dep);
+
+/* Gets an object's SC. */
+MVM_STATIC_INLINE MVMSerializationContext * MVM_sc_get_obj_sc(MVMThreadContext *tc, MVMObject *obj) {
+ assert(!(obj->header.flags & MVM_CF_GEN2_LIVE));
+ assert(!(obj->header.flags & MVM_CF_FORWARDER_VALID));
+ return obj->header.sc_forward_u.sc;
+}
+
+/* Gets an STables's SC. */
+MVM_STATIC_INLINE MVMSerializationContext * MVM_sc_get_stable_sc(MVMThreadContext *tc, MVMSTable *st) {
+ assert(!(st->header.flags & MVM_CF_GEN2_LIVE));
+ assert(!(st->header.flags & MVM_CF_FORWARDER_VALID));
+ return st->header.sc_forward_u.sc;
+}
+
+/* Sets an object's SC. */
+MVM_STATIC_INLINE void MVM_sc_set_obj_sc(MVMThreadContext *tc, MVMObject *obj, MVMSerializationContext *sc) {
+ assert(!(obj->header.flags & MVM_CF_GEN2_LIVE));
+ assert(!(obj->header.flags & MVM_CF_FORWARDER_VALID));
+ MVM_ASSIGN_REF(tc, obj, obj->header.sc_forward_u.sc, sc);
+}
+
+/* Sets an STable's SC. */
+MVM_STATIC_INLINE void MVM_sc_set_stable_sc(MVMThreadContext *tc, MVMSTable *st, MVMSerializationContext *sc) {
+ assert(!(st->header.flags & MVM_CF_GEN2_LIVE));
+ assert(!(st->header.flags & MVM_CF_FORWARDER_VALID));
+ MVM_ASSIGN_REF(tc, st, st->header.sc_forward_u.sc, sc);
+}
+
+
/* SC repossession write barriers. */
#define MVM_SC_WB_OBJ(tc, obj) \
do { \
diff --git a/src/moar.h b/src/moar.h
index e377682..1824ab1 100644
--- a/src/moar.h
+++ b/src/moar.h
@@ -52,6 +52,7 @@ typedef double MVMnum64;
/* Headers for various other data structures and APIs. */
#include "6model/6model.h"
+#include "gc/wb.h"
#include "core/threadcontext.h"
#include "core/instance.h"
#include "core/interp.h"
@@ -83,7 +84,6 @@ typedef double MVMnum64;
#include "gc/orchestrate.h"
#include "gc/gen2.h"
#include "gc/roots.h"
-#include "gc/wb.h"
#include "strings/decode_stream.h"
#include "strings/ascii.h"
#include "strings/utf8.h"
--
1.8.4.2
>From 158aeef70276b07dfe691e7c0c9ba57b7a0bff53 Mon Sep 17 00:00:00 2001
From: Nicholas Clark <n...@ccl4.org>
Date: Tue, 18 Feb 2014 15:36:36 +0100
Subject: [PATCH 4/6] Convert sc_set_code, sc_set_code_list and
sc_get_object_count to inline.
---
src/6model/sc.c | 17 -----------------
src/6model/sc.h | 20 +++++++++++++++++---
2 files changed, 17 insertions(+), 20 deletions(-)
diff --git a/src/6model/sc.c b/src/6model/sc.c
index f6a992c..4789480 100644
--- a/src/6model/sc.c
+++ b/src/6model/sc.c
@@ -238,23 +238,6 @@ MVMObject * MVM_sc_get_code(MVMThreadContext *tc, MVMSerializationContext *sc, M
"No code ref at index %d", idx);
}
-/* Given an SC, an index and a code ref, store it and the index. */
-void MVM_sc_set_code(MVMThreadContext *tc, MVMSerializationContext *sc, MVMint64 idx, MVMObject *code) {
- MVMObject *roots = sc->body->root_codes;
- MVMuint64 count = MVM_repr_elems(tc, roots);
- MVM_repr_bind_pos_o(tc, roots, idx, code);
-}
-
-/* Sets the full list of code refs. */
-void MVM_sc_set_code_list(MVMThreadContext *tc, MVMSerializationContext *sc, MVMObject *code_list) {
- MVM_ASSIGN_REF(tc, sc, sc->body->root_codes, code_list);
-}
-
-/* Gets the number of objects in the SC. */
-MVMuint64 MVM_sc_get_object_count(MVMThreadContext *tc, MVMSerializationContext *sc) {
- return sc->body->num_objects;
-}
-
/* Resolves an SC handle using the SC weakhash. */
MVMSerializationContext * MVM_sc_find_by_handle(MVMThreadContext *tc, MVMString *handle) {
MVMSerializationContextBody *scb;
diff --git a/src/6model/sc.h b/src/6model/sc.h
index e3c1f2f..954ed63 100644
--- a/src/6model/sc.h
+++ b/src/6model/sc.h
@@ -15,9 +15,6 @@ MVMSTable * MVM_sc_try_get_stable(MVMThreadContext *tc, MVMSerializationContext
void MVM_sc_set_stable(MVMThreadContext *tc, MVMSerializationContext *sc, MVMint64 idx, MVMSTable *st);
void MVM_sc_push_stable(MVMThreadContext *tc, MVMSerializationContext *sc, MVMSTable *st);
MVMObject * MVM_sc_get_code(MVMThreadContext *tc, MVMSerializationContext *sc, MVMint64 idx);
-void MVM_sc_set_code(MVMThreadContext *tc, MVMSerializationContext *sc, MVMint64 idx, MVMObject *code);
-void MVM_sc_set_code_list(MVMThreadContext *tc, MVMSerializationContext *sc, MVMObject *code_list);
-MVMuint64 MVM_sc_get_object_count(MVMThreadContext *tc, MVMSerializationContext *sc);
MVMSerializationContext * MVM_sc_find_by_handle(MVMThreadContext *tc, MVMString *handle);
MVMSerializationContext * MVM_sc_get_sc(MVMThreadContext *tc, MVMCompUnit *cu, MVMint16 dep);
@@ -50,6 +47,23 @@ MVM_STATIC_INLINE void MVM_sc_set_stable_sc(MVMThreadContext *tc, MVMSTable *st,
MVM_ASSIGN_REF(tc, st, st->header.sc_forward_u.sc, sc);
}
+/* Given an SC, an index and a code ref, store it and the index. */
+MVM_STATIC_INLINE void MVM_sc_set_code(MVMThreadContext *tc, MVMSerializationContext *sc, MVMint64 idx, MVMObject *code) {
+ MVMObject *roots = sc->body->root_codes;
+ MVMuint64 count = MVM_repr_elems(tc, roots);
+ MVM_repr_bind_pos_o(tc, roots, idx, code);
+}
+
+/* Sets the full list of code refs. */
+MVM_STATIC_INLINE void MVM_sc_set_code_list(MVMThreadContext *tc, MVMSerializationContext *sc, MVMObject *code_list) {
+ MVM_ASSIGN_REF(tc, sc, sc->body->root_codes, code_list);
+}
+
+/* Gets the number of objects in the SC. */
+MVM_STATIC_INLINE MVMuint64 MVM_sc_get_object_count(MVMThreadContext *tc, MVMSerializationContext *sc) {
+ return sc->body->num_objects;
+}
+
/* SC repossession write barriers. */
#define MVM_SC_WB_OBJ(tc, obj) \
--
1.8.4.2
>From e3d22dafd5806ea637c2ab7725a1205417e466f1 Mon Sep 17 00:00:00 2001
From: Nicholas Clark <n...@ccl4.org>
Date: Tue, 18 Feb 2014 15:41:54 +0100
Subject: [PATCH 5/6] Convert MVM_SC_WB_OBJ and MVM_SC_WB_ST from macros to
inline functions.
---
src/6model/sc.h | 30 ++++++++++++++----------------
1 file changed, 14 insertions(+), 16 deletions(-)
diff --git a/src/6model/sc.h b/src/6model/sc.h
index 954ed63..89630c1 100644
--- a/src/6model/sc.h
+++ b/src/6model/sc.h
@@ -66,21 +66,19 @@ MVM_STATIC_INLINE MVMuint64 MVM_sc_get_object_count(MVMThreadContext *tc, MVMSer
/* SC repossession write barriers. */
-#define MVM_SC_WB_OBJ(tc, obj) \
- do { \
- MVMObject *check = (MVMObject *)obj; \
- assert(!(obj->header.flags & MVM_CF_GEN2_LIVE)); \
- assert(!(obj->header.flags & MVM_CF_FORWARDER_VALID)); \
- if (check->header.sc_forward_u.sc) \
- MVM_sc_wb_hit_obj(tc, check); \
- } while (0);
void MVM_sc_wb_hit_obj(MVMThreadContext *tc, MVMObject *obj);
-#define MVM_SC_WB_ST(tc, st) \
- do { \
- MVMSTable *check = st; \
- assert(!(st->header.flags & MVM_CF_GEN2_LIVE)); \
- assert(!(st->header.flags & MVM_CF_FORWARDER_VALID)); \
- if (check->header.sc_forward_u.sc) \
- MVM_sc_wb_hit_st(tc, check); \
- } while (0);
void MVM_sc_wb_hit_st(MVMThreadContext *tc, MVMSTable *st);
+
+MVM_STATIC_INLINE void MVM_SC_WB_OBJ(MVMThreadContext *tc, MVMObject *obj) {
+ assert(!(obj->header.flags & MVM_CF_GEN2_LIVE));
+ assert(!(obj->header.flags & MVM_CF_FORWARDER_VALID));
+ if (obj->header.sc_forward_u.sc)
+ MVM_sc_wb_hit_obj(tc, obj);
+}
+
+MVM_STATIC_INLINE void MVM_SC_WB_ST(MVMThreadContext *tc, MVMSTable *st) {
+ assert(!(st->header.flags & MVM_CF_GEN2_LIVE));
+ assert(!(st->header.flags & MVM_CF_FORWARDER_VALID));
+ if (st->header.sc_forward_u.sc)
+ MVM_sc_wb_hit_st(tc, st);
+}
--
1.8.4.2
>From c6dc930dd11df624cd787951033bfff271edfd88 Mon Sep 17 00:00:00 2001
From: Nicholas Clark <n...@ccl4.org>
Date: Tue, 18 Feb 2014 15:45:41 +0100
Subject: [PATCH 6/6] Convert MVM_sc_push_object() to an inline function.
---
src/6model/sc.c | 5 -----
src/6model/sc.h | 5 ++++-
2 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/src/6model/sc.c b/src/6model/sc.c
index 4789480..cbb35ac 100644
--- a/src/6model/sc.c
+++ b/src/6model/sc.c
@@ -165,11 +165,6 @@ void MVM_sc_set_object(MVMThreadContext *tc, MVMSerializationContext *sc, MVMint
}
}
-/* Given an SC and an object, push it onto the SC. */
-void MVM_sc_push_object(MVMThreadContext *tc, MVMSerializationContext *sc, MVMObject *obj) {
- MVM_sc_set_object(tc, sc, sc->body->num_objects, obj);
-}
-
/* Given an SC and an index, fetch the STable stored there. */
MVMSTable * MVM_sc_get_stable(MVMThreadContext *tc, MVMSerializationContext *sc, MVMint64 idx) {
if (idx >= 0 && idx < sc->body->num_stables && sc->body->root_stables[idx])
diff --git a/src/6model/sc.h b/src/6model/sc.h
index 89630c1..f162e91 100644
--- a/src/6model/sc.h
+++ b/src/6model/sc.h
@@ -9,7 +9,6 @@ MVMint64 MVM_sc_find_code_idx(MVMThreadContext *tc, MVMSerializationContext *sc,
MVMObject * MVM_sc_get_object(MVMThreadContext *tc, MVMSerializationContext *sc, MVMint64 idx);
MVMObject * MVM_sc_try_get_object(MVMThreadContext *tc, MVMSerializationContext *sc, MVMint64 idx);
void MVM_sc_set_object(MVMThreadContext *tc, MVMSerializationContext *sc, MVMint64 idx, MVMObject *obj);
-void MVM_sc_push_object(MVMThreadContext *tc, MVMSerializationContext *sc, MVMObject *obj);
MVMSTable * MVM_sc_get_stable(MVMThreadContext *tc, MVMSerializationContext *sc, MVMint64 idx);
MVMSTable * MVM_sc_try_get_stable(MVMThreadContext *tc, MVMSerializationContext *sc, MVMint64 idx);
void MVM_sc_set_stable(MVMThreadContext *tc, MVMSerializationContext *sc, MVMint64 idx, MVMSTable *st);
@@ -64,6 +63,10 @@ MVM_STATIC_INLINE MVMuint64 MVM_sc_get_object_count(MVMThreadContext *tc, MVMSer
return sc->body->num_objects;
}
+/* Given an SC and an object, push it onto the SC. */
+MVM_STATIC_INLINE void MVM_sc_push_object(MVMThreadContext *tc, MVMSerializationContext *sc, MVMObject *obj) {
+ MVM_sc_set_object(tc, sc, sc->body->num_objects, obj);
+}
/* SC repossession write barriers. */
void MVM_sc_wb_hit_obj(MVMThreadContext *tc, MVMObject *obj);
--
1.8.4.2