From 2adb0a3586555e76aedbef10a14b177c73e62030 Mon Sep 17 00:00:00 2001 From: dzaima Date: Wed, 28 May 2025 02:12:44 +0300 Subject: [PATCH] --disable-jit flag will be less efficient than if compiled with -DJIT_ENABLED=0, but better than nothing --- src/main.c | 3 +++ src/vm.c | 2 ++ src/vm.h | 4 +++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 72b2b68c..c89918ed 100644 --- a/src/main.c +++ b/src/main.c @@ -963,6 +963,9 @@ int main(int argc, char* argv[]) { } else if (!strcmp(carg, "--replxx-read-only")) { replxx_read_only = true; continue; + } else if (!strcmp(carg, "--disable-jit")) { + jit_enabled = false; + continue; #endif } else { printf("%s: Unknown option: %s\n", argv[0], carg); diff --git a/src/vm.c b/src/vm.c index c9f4992c..fe20fd8b 100644 --- a/src/vm.c +++ b/src/vm.c @@ -985,8 +985,10 @@ NOINLINE Scope* m_scope(Body* body, Scope* psc, u16 varAm, i32 initVarAm, B* ini B execBlockInplaceImpl(Body* body, Scope* sc, Block* block) { return execBodyInplaceI(block->bodies[0], sc, block); } +bool jit_enabled = true; #if JIT_START != -1 B mnvmExecBodyInplace(Body* body, Scope* sc) { + if (!jit_enabled) return evalBC(body, sc, body->bl); Nvm_res r = m_nvm(body); body->nvm = r.p; body->nvmRefs = r.refs; diff --git a/src/vm.h b/src/vm.h index b8270326..87d18ed3 100644 --- a/src/vm.h +++ b/src/vm.h @@ -177,12 +177,14 @@ static B execBlockInplace(Block* block, Scope* sc) { // doesn't consume; execute #if JIT_START != -1 NOINLINE B mnvmExecBodyInplace(Body* body, Scope* sc); #endif +extern bool jit_enabled; FORCE_INLINE B execBodyInplaceI(Body* body, Scope* sc, Block* block) { // consumes sc, unlike execBlockInplace + debug_assert(body->bl == block); #if JIT_START != -1 if (LIKELY(body->nvm != NULL)) return evalJIT(body, sc, body->nvm); bool jit = true; #if JIT_START > 0 - jit = body->callCount++ >= JIT_START; + jit = body->callCount++ == JIT_START; #endif // jit = body->bc[2]==m_f64(123456).u>>32; // enable JIT for blocks starting with `123456⋄` if (jit) return mnvmExecBodyInplace(body, sc);