aboutsummaryrefslogtreecommitdiff
path: root/pu2
diff options
context:
space:
mode:
Diffstat (limited to 'pu2')
-rw-r--r--pu2/pu2.out.c36
1 files changed, 23 insertions, 13 deletions
diff --git a/pu2/pu2.out.c b/pu2/pu2.out.c
index 8bc9f52..baae8f2 100644
--- a/pu2/pu2.out.c
+++ b/pu2/pu2.out.c
@@ -2,6 +2,7 @@
// COMPILE TIME FLAGS EXPLANATION
// - NO_MMAP Prevents usage of mmap+hugepages, which is only supported on linux
// - NO_ASM Prevents usage of inline assembly, useful for non-x86 platforms
+ // - NO_INTRINSICS Disables compiler intrinsics
// - BAD_CLOCK Use if your system clock does not support nanoseconds. Uses microseconds instead.
// - OLD_CLANG Use if your compiler version is not very up-to-date.
// - SPEED_IMPROVEMENT Almost doubles clock rate for the VM with a few optimizations.
@@ -11,6 +12,7 @@
/* -- BEGIN COMPILE TIME FLAGS -- */
// #define PU2_NO_MMAP
// #define PU2_NO_ASM
+// #define PU2_NO_INTRINSICS
// #define PU2_BAD_CLOCK
// #define PU2_OLD_CLANG
#define PU2_SPEED_IMPROVEMENT
@@ -87,8 +89,13 @@
// not implemented yet, was lazy
// bake(int start, int end) {}
- #define unlikely(JJ) __builtin_expect((JJ), 0)
- #define likely(JJ) __builtin_expect((JJ), 1)
+ #ifndef PU2_NO_INTRINSICS
+ #define unlikely(JJ) __builtin_expect((JJ), 0)
+ #define likely(JJ) __builtin_expect((JJ), 1)
+ #else
+ #define unlikely(JJ) (JJ)
+ #define likely(JJ) (JJ)
+ #endif
#ifndef PU2_NO_MMAP
__attribute__((aligned(64))) int *m;
@@ -103,7 +110,7 @@ typedef struct {
const int hugepage_size = 2 * 1024 * 1024;
-#ifndef PU2_NO_ASM
+ #ifndef PU2_NO_ASM
// unused
void set_affinity(int cpu) {
cpu_set_t mask;
@@ -112,7 +119,7 @@ void set_affinity(int cpu) {
if (sched_setaffinity(0, sizeof(mask), &mask) != 0) { perror("sched_setaffinity failed"); }
}
-#endif
+ #endif
void init_pu2() {
// set_affinity(0);
@@ -153,7 +160,7 @@ void __attribute__((hot, aligned(64))) pu2() {
static int s1, s2, s3;
static const __attribute__((aligned(64))) void *PRECOMPUTED_TABLE[]
- = { &&PU2_END, &&C_ONE, &&C_TWO, &&C_THREE, &&C_FOUR,
+ = { &&PU2_END, &&C_ONE, &&C_TWO, &&C_THREE, &&C_FOUR,
&&C_FIVE, &&C_SIX, &&C_SEVEN, &&C_EIGHT, &&C_NINE,
&&C_TEN, &&C_ELEVEN, &&C_TWELVE, &&C_THIRTEEN, &&CB_FOURTEEN,
&&CB_FIFTEEN, &&CB_SIXTEEN, &&CB_SEVENTEEN, &&CB_EIGHTEEN, [32] = 0 };
@@ -162,12 +169,14 @@ void __attribute__((hot, aligned(64))) pu2() {
while (1) {
PU2_START:
inst = *M++;
- // if (unlikely(inst.c > 18)) A;
+ // if (unlikely(inst.c > 18)) A;
+ #ifndef PU2_NO_INTRINSICS
__builtin_prefetch(M + 1, 0, 3);
+ #endif
goto *PRECOMPUTED_TABLE[ inst.c ];
-// C_ZERO:
-// goto PU2_END;
+ // C_ZERO:
+ // goto PU2_END;
C_ONE:
#ifndef PU2_NO_ASM
asm("mov %1, %0" : "=r"(a) : "r"(inst.v));
@@ -183,7 +192,8 @@ void __attribute__((hot, aligned(64))) pu2() {
#endif
goto PU2_START;
C_THREE:
- // if (unlikely(a == 7)) printf("conditional jmp %i (%i) [a=%i b=%i u=%i]\n", M - M2, u, a, b, u);
+ // if (unlikely(a == 7)) printf("conditional jmp %i (%i) [a=%i b=%i u=%i]\n", M - M2, u, a,
+ // b, u);
if (likely(u)) {
if (unlikely(a == 7)) M = M2 + (b >> 1);
m[ a ] = b;
@@ -233,8 +243,8 @@ void __attribute__((hot, aligned(64))) pu2() {
M += inst.v;
goto PU2_START;
CB_FIFTEEN:
- //if (unlikely(inst.v == 7)) M = M2 + (m[a] >> 1);
- //if (unlikely(inst.v == a)) goto PU2_START;
+ // if (unlikely(inst.v == 7)) M = M2 + (m[a] >> 1);
+ // if (unlikely(inst.v == a)) goto PU2_START;
m[ inst.v ] = m[ a ];
// asm("mov %1, %0" : "=r"(m[inst.v]) : "r"(m[a]));
goto PU2_START;
@@ -248,8 +258,8 @@ void __attribute__((hot, aligned(64))) pu2() {
m[ a ] = inst.v;
goto PU2_START;
CB_EIGHTEEN:
- //if (unlikely(a == 7)) M = M2 + (m[inst.v] >> 1);
- //if (unlikely(inst.v == a)) goto PU2_START;
+ // if (unlikely(a == 7)) M = M2 + (m[inst.v] >> 1);
+ // if (unlikely(inst.v == a)) goto PU2_START;
m[ a ] = m[ inst.v ];
// asm("mov %1, %0" : "=r"(m[a]) : "r"(m[inst.v]));
goto PU2_START;