mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-06 08:23:19 +08:00
With --cpu-dispatch, an x86-64 executable carries two copies of each program function: the baseline code and a copy compiled for x86-64-v3. main reads CPUID and XGETBV once. Calls between the program's functions go to the caller's copy. A function that is also named outside the copies (a function value, a call from main, a runtime callback or a coroutine body) keeps a dispatcher under its own name, which tests the level and tail-calls one copy. Functions without such a use get no dispatcher, so their copies have the callers the original had and LLVM inlines them the same way. The executable still runs on any x86-64 CPU. SCRIPTC_CPU_LEVEL caps the level at run time. The option is off by default, applies to executables without a --target-cpu level, and is part of the executable cache key. bench:runtime takes --baseline-cpu-dispatch and --candidate-cpu-dispatch, and the LLVM differential suite runs each program at levels 0 and 3 with SCRIPTC_CPU_DISPATCH=1.