From 450ced09c93ecb9c1c2c4c97fe2dde29439dac8f Mon Sep 17 00:00:00 2001 From: Moon Flower Date: Mon, 18 Aug 2025 11:59:33 +0330 Subject: ppu isn't useful. i'll just go back to pu2 --- ppu/code.p2p | 1 + ppu/ppu | Bin 0 -> 17464 bytes ppu/ppu.c | 155 +++++++++++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 137 insertions(+), 19 deletions(-) create mode 100644 ppu/code.p2p create mode 100755 ppu/ppu diff --git a/ppu/code.p2p b/ppu/code.p2p new file mode 100644 index 0000000..596ca02 --- /dev/null +++ b/ppu/code.p2p @@ -0,0 +1 @@ +@1048566 movi 1 1 \ No newline at end of file diff --git a/ppu/ppu b/ppu/ppu new file mode 100755 index 0000000..addbcf2 Binary files /dev/null and b/ppu/ppu differ diff --git a/ppu/ppu.c b/ppu/ppu.c index 9b4fc5a..0111d97 100644 --- a/ppu/ppu.c +++ b/ppu/ppu.c @@ -1,13 +1,16 @@ +// c89 doesnt support inline, so we get rid of it #define inline #include +#include #include #include #include +#include #pragma clang diagnostic ignored "-Wreturn-type" -typedef char* string; +typedef char *string; // opcodes! // 0: halt @@ -22,36 +25,150 @@ typedef char* string; // program counter is m[0] // Q is set to the previous A in memory +#define S 1 << 22 +m[ S ] = { 0 }, c, N, Q, E; + +// comment to disable cpu batch counter which guesses how many branches to run +#define __PPU_BATCH_COUNTER + +#ifdef __PPU_BATCH_COUNTER + #define BC (N = run_batch_counter()) +#else + #define BC ({}) +#endif + +#define MAX_BATCH_COUNT 16 + +run_batch_counter() { + int max_value = MAX_BATCH_COUNT; + int bcup_c = 0, i_count, j_count; + int bcupt[ MAX_BATCH_COUNT ]; + int *M = m; + // effects table + static const string effW = "001111111"; + static const string effR = "001010101"; + + for (i_count = 0; i_count < MAX_BATCH_COUNT; i_count++) { + if (i_count > max_value) break; + + int num = c + (i_count << 2); + int __N = M[ num++ ]; + int __O = M[ num++ ]; + int __A = M[ num++ ]; + int __B = M[ num++ ]; + + if (__N != 0) { + max_value = i_count + __N; + break; + } + if (__O == 0) { + max_value = i_count; + break; + } + if (__O >= 9) { + max_value = i_count - 1; + break; + } + + char w = effW[ __O ] - 48; + char r = effR[ __O ] - 48; + + for (j_count = 0; j_count < bcup_c; j_count++) { + int prev = bcupt[ j_count ]; + if ((prev == __A && w) || (prev == __B && r)) { + max_value = i_count - 1; + goto END; + } + } + + if (w) bcupt[ bcup_c++ ] = __A; + } + +END: + return max_value; +} + // error handling for unknown ops #define W 0 -// clang-format off #define J while -#define S 1<<20 #define H !K-- -m[S]={0},c,N,Q,E; -ppu(){E=1;_Pragma("omp parallel")J(E){_Pragma("omp single")N=m[m[0]],c=m[0],m[0]+=++N*4;int i;_Pragma("omp for")for(i=0;i