From 4c0d59ff16f76dcbe0c16cf34e6a09dbc2422f93 Mon Sep 17 00:00:00 2001 From: Moon Flower Date: Wed, 20 Aug 2025 14:31:59 +0330 Subject: compat flags explanation --- pu2/pu2.c | 18 ++++++++++++++++-- pu2/pu2.out.c | 24 ++++++++++++++++++++---- 2 files changed, 36 insertions(+), 6 deletions(-) (limited to 'pu2') diff --git a/pu2/pu2.c b/pu2/pu2.c index 076261c..85c28f4 100644 --- a/pu2/pu2.c +++ b/pu2/pu2.c @@ -647,12 +647,20 @@ unsigned long long rdtsc(void) { #endif } +#ifndef PU2_BAD_CLOCK clock_t ntime() { struct timespec t; clock_gettime(CLOCK_MONOTONIC_RAW, &t); return t.tv_nsec + t.tv_sec * 1e9; } +#else +clock_t ntime() { + struct timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_sec * 1000000000 + tv.tv_usec * 1000; +} +#endif // bench: measure using clock() double bench_cycle(int instr) { @@ -729,8 +737,14 @@ sleep_nano(int nanoseconds) { } } -[[clang::always_inline]] sleep_micro(int microseconds) { sleep_nano(microseconds * 1e3); } -[[clang::always_inline]] sleep_milli(int milliseconds) { sleep_nano(milliseconds * 1e6); } +#ifdef PU2_OLD_CLANG + #define inline() __attribute__((always_inline)) +#else + #define inline() [[clang::always_inline]] +#endif + +inline() sleep_micro(int microseconds) { sleep_nano(microseconds * 1e3); } +inline() sleep_milli(int milliseconds) { sleep_nano(milliseconds * 1e6); } // benchmark: run target for all opcodes and print summary benchmark(double (*target)(int), const char *mode_label) { diff --git a/pu2/pu2.out.c b/pu2/pu2.out.c index 98f0554..cd403f5 100644 --- a/pu2/pu2.out.c +++ b/pu2/pu2.out.c @@ -1,10 +1,26 @@ +// clang-format off + // 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 + // - 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. + // - EXTENDED_INSTRUCTION_SET Adds a few instructions which decrease token throughput for ir2. The high-level IR emitter will not work otherwise. +// clang-format on + /* -- BEGIN COMPILE TIME FLAGS -- */ // #define PU2_NO_MMAP // #define PU2_NO_ASM -#define __PU2_SPEED_IMPROVEMENT -#define __PU2_EXTENDED_INSTRUCTION_SET +// #define PU2_BAD_CLOCK +// #define PU2_OLD_CLANG +#define PU2_SPEED_IMPROVEMENT +#define PU2_EXTENDED_INSTRUCTION_SET /* -- END COMPILE TIME FLAGS --*/ +#ifdef PU2_NO_ASM + #warning Enabling this flag will invalidate all clock speed and cycle count measurements (thus, your CPU clock rate will be reported as 0MHz) +#endif + #define _GNU_SOURCE #include #include @@ -32,9 +48,9 @@ #define J while #define H !--c -#ifndef __PU2_SPEED_IMPROVEMENT +#ifndef PU2_SPEED_IMPROVEMENT - #ifndef __PU2_EXTENDED_INSTRUCTION_SET + #ifndef PU2_EXTENDED_INSTRUCTION_SET // clang-format off m[S],c,v,a,b,u;pu2(){J(c=m[m[7]++],v=m[m[7]++],c){H?a=v:H?a=m[b]:H?u?m[a]=b:0:H?v=a,a=b,b=v:H?a+=b:H?a-=b:H?a&=b:H?a=!a:H?u=v:H?u=a:H?a=u:H?u=b:H?b=u:A;}} -- cgit v1.2.3