aboutsummaryrefslogtreecommitdiff
path: root/pu2/pu2.c
diff options
context:
space:
mode:
authorGravatar Moon Flower <moon@coffin.ir> 2025-08-19 15:52:38 +0330
committerGravatar Moon Flower <moon@coffin.ir> 2025-08-19 15:52:38 +0330
commit0bd4c2925a32d384ea2c333b950115404b88c619 (patch)
treee5c447a5425869626473394010cc470b11b51451 /pu2/pu2.c
parentimproved pu2 (vm speed ~1GHz on 1.8GHz cpu), reduced code emission, added ano... (diff)
the speedster
Diffstat (limited to 'pu2/pu2.c')
-rw-r--r--pu2/pu2.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/pu2/pu2.c b/pu2/pu2.c
index d1f6fe1..1e3bdf1 100644
--- a/pu2/pu2.c
+++ b/pu2/pu2.c
@@ -281,8 +281,13 @@ clean_slice_ref(slice *val) { free(val->ref); }
char T;
string ERR;
string ERR_code;
-int *Code = &m[ 4000 ];
-int *Data = &m[ static_len(m) - 1 ]; // grows downwards
+int *Code;
+int *Data;
+
+init_ir2() {
+ Code = &m[ 4000 ];
+ Data = &m[ S * sizeof(int) - 1 ]; // grows downwards
+}
__attribute__((always_inline)) emit(int op, int val) {
*Code++ = op;
@@ -650,7 +655,7 @@ double bench_cycle(int instr) {
int i;
for (i = 0; i < S - 2; i += 2) {
m[ i ] = instr;
- m[ i + 1 ] = 5;
+ m[ i + 1 ] = 10;
}
m[ S - 2 ] = 0;
m[ S - 1 ] = 0;
@@ -785,6 +790,9 @@ main(int argc, char **argv) {
argv[ 0 ]);
}
+ init_pu2();
+ init_ir2();
+
if (strcmp(argv[ 1 ], "benchmark") == 0) {
benchmark(bench_cycle, "time");
@@ -800,7 +808,7 @@ main(int argc, char **argv) {
unsigned long long t1 = rdtsc();
out = sum; // single volatile write to make sum observable
printf(
- "N=%llu cycles=%llu cycles/iter=%.6f\n",
+ "(absolute max) N=%llu cycles=%llu cycles/iter=%.6f\n",
(unsigned long long) N,
(unsigned long long) (t1 - t0),
(t1 - t0) / (double) N);