diff --git a/content/bvm/optimizing.mdx b/content/bvm/optimizing.mdx index fab7bb0..17f2a34 100644 --- a/content/bvm/optimizing.mdx +++ b/content/bvm/optimizing.mdx @@ -7,7 +7,7 @@ order: 65 # The JIT bvm gets faster as a program runs. It starts every function in the interpreter, counts how often each one is called -and how often its loops turn, and compiles the hot ones to x86-64 machine code while the program keeps running. There +and how often its loops turn, and compiles the hot ones to machine code (x86-64 or arm64) while the program keeps running. There is nothing to configure and no cache on disk, and it works for every language built on bvm, not just Burn. ![Functions start in the interpreter and are compiled to machine code when they get hot](../images/tiering.svg) @@ -54,10 +54,14 @@ error names the same line and column. Threads started with `async` share the com The results are always the same; only the speed changes. Burn's test suite runs every test program with `BURN_JIT_THRESHOLD=1` and with `BURN_JIT=0` and compares their output with the native executables. -The JIT runs on x86-64 Linux and macOS. On arm64 (Apple silicon and Linux), bvm interprets for now. +The JIT runs on Linux and macOS, on x86-64 (`compiler/src/bvm/jit_x86.bn`) and arm64, Macs with Apple silicon +included (`jit_arm64.bn`). Both code generators share the tracking of the operand stack and jumps (`jitbase.bn`). +On arm64 the accumulator is `x9` and the frame base `x19`; on x86-64 they are `rax` and `rbx`. ## Numbers +Measured on x86-64 Linux: + | Program | Interpreted | With the JIT | Native executable | | --- | --- | --- | --- | | `fib(32)`, recursive calls | 1.4 s | 31 ms | 20 ms | diff --git a/content/bvm/overview.mdx b/content/bvm/overview.mdx index 2d36d9d..19cfb43 100644 --- a/content/bvm/overview.mdx +++ b/content/bvm/overview.mdx @@ -28,7 +28,7 @@ What a language gets by targeting bvm: run off the end of a function. - **Fast execution.** Verified code runs on an interpreter with a precomputed frame size per function, so pushes and pops aren't bounds-checked. At load time common instruction sequences are fused into - superinstructions, and functions and loops that run often are compiled to x86-64 machine code while the program + superinstructions, and functions and loops that run often are compiled to x86-64 or arm64 machine code while the program runs (see [the JIT](./optimizing.mdx)). - **Two interchangeable file formats**: readable assembly (`.bvm`) and compact bytecode (`.bvmc`). They convert both ways without loss. diff --git a/content/images/tiering.svg b/content/images/tiering.svg index aa753f9..1554528 100644 --- a/content/images/tiering.svg +++ b/content/images/tiering.svg @@ -13,8 +13,8 @@ loop turns per function compiled - x86-64 machine code, - values in registers + machine code (x86-64, + arm64), values in registers running loops go on in compiled @@ -27,5 +27,5 @@ or loop turns compiled and interpreted functions call each other - BURN_JIT_THRESHOLD changes the threshold, BURN_JIT=0 turns compiling off. On arm64, bvm interprets. + BURN_JIT_THRESHOLD changes the threshold, BURN_JIT=0 turns compiling off. diff --git a/content/internals/running.mdx b/content/internals/running.mdx index d11b174..7c54a73 100644 --- a/content/internals/running.mdx +++ b/content/internals/running.mdx @@ -43,7 +43,7 @@ jump", or "load a local and read one of its fields". The interpreter is a loop o ## Compiling hot code bvm counts calls and loop turns per function. When a function gets hot (1000 calls or loop turns), the JIT compiles -it to x86-64 machine code that keeps the interpreter's frame, so compiled and interpreted functions call each other +it to machine code for the processor (x86-64 or arm64) that keeps the interpreter's frame, so compiled and interpreted functions call each other freely, and a loop that is already running continues in the compiled code at its next turn (on-stack replacement). Compiled code keeps values in registers and runs arithmetic, comparisons, fields, arrays and reference counting inline. See [the JIT](../bvm/optimizing.mdx) for the details and its settings, `BURN_JIT` and `BURN_JIT_THRESHOLD`.