react-nitro-hermes 0.0.1-alpha.8 → 0.0.1-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/hermes/CMakeLists.txt +874 -0
- package/hermes/android/HostObjectJniTest.cpp +178 -0
- package/hermes/android/build-logic/build.gradle.kts +31 -0
- package/hermes/android/build-logic/settings.gradle.kts +17 -0
- package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/helpers/internal/SerializeHermesCompilerPackageJson.kt +33 -0
- package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/plugins/internal/TestUtilsPlugin.kt +80 -0
- package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/tasks/internal/CustomExecTask.kt +46 -0
- package/hermes/android/build-logic/src/main/kotlin/publish.gradle.kts +82 -0
- package/hermes/android/build.gradle.kts +332 -0
- package/hermes/android/cppruntime/build.gradle +72 -0
- package/hermes/android/cppruntime/src/main/AndroidManifest.xml +2 -0
- package/hermes/android/cppruntime/src/main/cpp/CMakeLists.txt +8 -0
- package/hermes/android/cppruntime/src/main/cpp/stub.cpp +12 -0
- package/hermes/android/cross-compile/swift-libicu.patch +13 -0
- package/hermes/android/cross-compile/toolchain-android-arm-api13-gnustl.cmake +13 -0
- package/hermes/android/cross-compile/toolchain-android-arm-api15-gnustl.cmake +14 -0
- package/hermes/android/gradle/libs.versions.toml +30 -0
- package/hermes/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/hermes/android/gradle/wrapper/gradle-wrapper.properties +7 -0
- package/hermes/android/gradle.properties +3 -0
- package/hermes/android/gradlew +248 -0
- package/hermes/android/gradlew.bat +93 -0
- package/hermes/android/intltest/build.gradle +147 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/CMakeLists.txt +45 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.cpp +68 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.h +44 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.java +45 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogueTestData.java +32 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesInstrumentationTest.java +150 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesIntlAndroidTest.java +147 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesIntlTest262.java +470 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesRuntimeFactory.cpp +73 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.cpp +90 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.h +62 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.java +155 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/MappedFileBuffer.cpp +48 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/MappedFileBuffer.h +36 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/OnLoad.cpp +13 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/OnLoadEpilogue.cpp +13 -0
- package/hermes/android/intltest/src/main/AndroidManifest.xml +2 -0
- package/hermes/android/ios-artifacts/build.gradle.kts +65 -0
- package/hermes/android/settings.gradle.kts +27 -0
- package/hermes/cmake/modules/Hermes.cmake +481 -0
- package/hermes/cmake/modules/Lit.cmake +96 -0
- package/hermes/doc/Branches.md +38 -0
- package/hermes/doc/BuildingAndRunning.md +121 -0
- package/hermes/doc/CodingStandards.md +112 -0
- package/hermes/doc/CrossCompilation.md +79 -0
- package/hermes/doc/Design.md +217 -0
- package/hermes/doc/Emscripten.md +156 -0
- package/hermes/doc/Features.md +143 -0
- package/hermes/doc/GCSafeCoding.md +563 -0
- package/hermes/doc/GenGC.md +300 -0
- package/hermes/doc/Hades.md +344 -0
- package/hermes/doc/HighLevelOptimizations.md +37 -0
- package/hermes/doc/IR.md +1306 -0
- package/hermes/doc/IntlAPIs.md +196 -0
- package/hermes/doc/JIT.md +999 -0
- package/hermes/doc/LazyEvalCompilation.md +84 -0
- package/hermes/doc/MemoryProfilers.md +316 -0
- package/hermes/doc/Modules.md +144 -0
- package/hermes/doc/Optimizer.md +83 -0
- package/hermes/doc/PerfProfiling.md +29 -0
- package/hermes/doc/ProhibitInvoke.md +329 -0
- package/hermes/doc/ReactNative.md +40 -0
- package/hermes/doc/ReactNativeIntegration.md +94 -0
- package/hermes/doc/RegExp.md +24 -0
- package/hermes/doc/SpecIncompat.md +85 -0
- package/hermes/doc/Strings.md +140 -0
- package/hermes/doc/TypedLanguage.md +432 -0
- package/hermes/doc/VM.md +174 -0
- package/hermes/doc/blog/2024-11-09-octane-benchmark-jit-progress.md +17 -0
- package/hermes/doc/blog/2024-12-19-static-hermes-update-dec-2024.md +47 -0
- package/hermes/doc/blog/2024-12-23-compiling-javascript-to-wasm.md +267 -0
- package/hermes/doc/blog/2025-06-09-jsi-runtime-data-apis.md +23 -0
- package/hermes/doc/blog/2025-07-15-static-h-performance-june-2025.md +18 -0
- package/hermes/doc/blog/2025-11-02-hermes-compilation-runtime-modes.md +23 -0
- package/hermes/doc/blog/2025-11-06-hermes-memory-modes.md +35 -0
- package/hermes/doc/blog/2025-11-24-json-parsing-performance.md +17 -0
- package/hermes/doc/blog/2025-12-02-iserialization.md +11 -0
- package/hermes/doc/blog/2025-12-12-new-way-to-contribute.md +68 -0
- package/hermes/doc/blog/2026-06-05-new-hermes-stable-release.md +51 -0
- package/hermes/doc/blog/README.md +25 -0
- package/hermes/doc/blog/images/2024-11-09-octane-pi3.jpeg +0 -0
- package/hermes/doc/blog/images/2024-11-09-octane-pi5.jpeg +0 -0
- package/hermes/doc/blog/images/2025-07-15-perf-hv32-interpreter.jpeg +0 -0
- package/hermes/doc/blog/images/2025-07-15-perf-hv32-jit.jpeg +0 -0
- package/hermes/doc/icu_license.txt +420 -0
- package/hermes/doc/img/heap_snapshot_retainers.png +0 -0
- package/hermes/doc/img/logo.svg +1 -0
- package/hermes/doc/img/object_captured_by_environment.png +0 -0
- package/hermes/doc/img/root_categories.png +0 -0
- package/hermes/doc/plans/ir-type/flow-type-system.md +324 -0
- package/hermes/doc/plans/ir-type/ir-type-system-v2-design.md +652 -0
- package/hermes/doc/plans/ir-type/ir-type-system.md +220 -0
- package/hermes/doc/plans/ir-type/ir-type-v2-implementation.md +1187 -0
- package/hermes/doc/plans/ir-type/memory.md +48 -0
- package/hermes/doc/plans/ir-type/phase1-steps.md +512 -0
- package/hermes/doc/plans/ir-type/progress.md +239 -0
- package/hermes/doc/plans/ir-type/typeinference-primitive-fastpath-design.md +203 -0
- package/hermes/doc/plans/ir-type/typeinference-primitive-fastpath-results.md +71 -0
- package/hermes/doc/superpowers/plans/2026-07-28-worker-arraybuffer-input.md +597 -0
- package/hermes/doc/superpowers/plans/2026-08-18-jitemitter-split.md +1149 -0
- package/hermes/doc/superpowers/plans/2026-08-20-jit-type-asserts.md +969 -0
- package/hermes/doc/superpowers/plans/2026-08-23-jit-shared-compiler-driver.md +478 -0
- package/hermes/doc/superpowers/plans/2026-08-23-x86-64-jit-skeleton.md +797 -0
- package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-arith.md +444 -0
- package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-calls.md +261 -0
- package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-props.md +240 -0
- package/hermes/doc/superpowers/plans/2026-10-26-regexp-bytecode-sharing.md +2197 -0
- package/hermes/doc/superpowers/plans/2026-10-28-regexp-start-filter-and-exec-fast-paths.md +3981 -0
- package/hermes/doc/superpowers/specs/2026-07-28-worker-arraybuffer-input-design.md +206 -0
- package/hermes/doc/superpowers/specs/2026-08-18-jitemitter-split-design.md +530 -0
- package/hermes/doc/superpowers/specs/2026-08-20-jit-type-asserts-design.md +360 -0
- package/hermes/doc/superpowers/specs/2026-08-23-x86-64-jit-design.md +246 -0
- package/hermes/doc/superpowers/specs/2026-08-26-icu-free-normalize-design.md +355 -0
- package/hermes/doc/superpowers/specs/2026-08-27-icu-free-convert-to-case-design.md +305 -0
- package/hermes/doc/superpowers/specs/2026-08-27-icu-free-locale-compare-design.md +429 -0
- package/hermes/doc/superpowers/specs/2026-08-29-icu-free-date-format-design.md +297 -0
- package/hermes/doc/superpowers/specs/2026-10-26-regexp-bytecode-sharing-design.md +605 -0
- package/hermes/doc/superpowers/specs/2026-10-28-regexp-start-filter-and-exec-fast-paths-design.md +551 -0
- package/hermes/doc/typescript-stripping.md +90 -0
- package/hermes/external/CMakeLists.txt +20 -0
- package/hermes/utils/IntlGen/IntlGen.java +531 -0
- package/hermes/utils/bench_with_stats.py +827 -0
- package/hermes/utils/build-apple-framework.sh +323 -0
- package/hermes/utils/chrome_snapshot_parser.py +210 -0
- package/hermes/utils/cmake-dev-build.sh +18 -0
- package/hermes/utils/commons.sh +55 -0
- package/hermes/utils/dump-cpp-funcs.sh +3 -0
- package/hermes/utils/es5objects.js +198 -0
- package/hermes/utils/format.sh +145 -0
- package/hermes/utils/gen-promise-internal-bc.sh +66 -0
- package/hermes/utils/genUnicodeTable.py +2503 -0
- package/hermes/utils/hermes-lit/CMakeLists.txt +22 -0
- package/hermes/utils/hermes-lit/hermes-lit.in +15 -0
- package/hermes/utils/jit/README.md +134 -0
- package/hermes/utils/jit/jit-diff.sh +160 -0
- package/hermes/utils/jit/jit-dump.sh +193 -0
- package/hermes/utils/lit-expect-gen/generate.py +217 -0
- package/hermes/utils/promise/index.js +15 -0
- package/hermes/utils/promise/package.json +13 -0
- package/hermes/utils/promise/rollup.config.js +19 -0
- package/hermes/utils/promise/yarn.lock +247 -0
- package/hermes/utils/scripts/hermes/consts.js +26 -0
- package/hermes/utils/scripts/hermes/create-tarball.js +75 -0
- package/hermes/utils/scripts/hermes/get-hermes-version.js +57 -0
- package/hermes/utils/scripts/hermes/hermes-utils.js +122 -0
- package/hermes/utils/scripts/hermes/package.json +6 -0
- package/hermes/utils/scripts/hermes/prepare-artifacts.js +113 -0
- package/hermes/utils/scripts/hermes/publish-artifacts.js +109 -0
- package/hermes/utils/scripts/hermes/publish-npm.js +96 -0
- package/hermes/utils/scripts/hermes/scm-utils.js +41 -0
- package/hermes/utils/scripts/hermes/set-artifacts-version.js +64 -0
- package/hermes/utils/scripts/hermes/version-utils.js +98 -0
- package/hermes/utils/scripts/hermes/yarn.lock +240 -0
- package/hermes/utils/summarize_sizes.py +184 -0
- package/hermes/utils/symbolicate-nativecall-stats.py +112 -0
- package/hermes/utils/test_runner.py +13 -0
- package/hermes/utils/testsuite/README.facebook +3 -0
- package/hermes/utils/testsuite/README.md +69 -0
- package/hermes/utils/testsuite/cli.py +547 -0
- package/hermes/utils/testsuite/es_ast.py +337 -0
- package/hermes/utils/testsuite/external/LICENSE +28 -0
- package/hermes/utils/testsuite/external/README.facebook +8 -0
- package/hermes/utils/testsuite/external/__init__.py +0 -0
- package/hermes/utils/testsuite/external/_monkeyYaml.py +164 -0
- package/hermes/utils/testsuite/external/parse_test262.py +141 -0
- package/hermes/utils/testsuite/hermes.py +522 -0
- package/hermes/utils/testsuite/preprocess.py +365 -0
- package/hermes/utils/testsuite/progress.py +377 -0
- package/hermes/utils/testsuite/skiplist.json +4356 -0
- package/hermes/utils/testsuite/skiplist.py +270 -0
- package/hermes/utils/testsuite/test_run_defs.py +435 -0
- package/hermes/utils/testsuite/typing_defs.py +52 -0
- package/hermes/utils/testsuite/utils.py +214 -0
- package/hermes/utils/tidy.sh +22 -0
- package/hermes/utils/update-fbcode-hermes.sh +53 -0
- package/hermes/utils/updateErrorTest.py +193 -0
- package/hermes/utils/wasm-compile.sh +65 -0
- package/package.json +1 -1
|
@@ -0,0 +1,797 @@
|
|
|
1
|
+
# x86-64 JIT Skeleton (Milestone 1) Implementation Plan
|
|
2
|
+
|
|
3
|
+
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
|
4
|
+
|
|
5
|
+
**Goal:** An x86-64 JIT backend skeleton that builds with the JIT enabled
|
|
6
|
+
on x86-64 SysV, compiles and correctly executes trivial functions
|
|
7
|
+
(`enter`/`leave`, const loads, `LoadParam`, `Mov`, `Ret`), and declines
|
|
8
|
+
everything else to the interpreter — verified natively under ASan.
|
|
9
|
+
|
|
10
|
+
**Architecture:** New `lib/VM/JIT/x86-64/` tree implementing the same
|
|
11
|
+
`Emitter` surface the shared driver (`lib/VM/JIT/JitCompiler.cpp`)
|
|
12
|
+
compiles against, selected by a new branch in `JitCurArch.h`. The FR
|
|
13
|
+
register-file substrate is ported from arm64 (copy-and-rewrite per the
|
|
14
|
+
spec's sharing policy); every per-opcode emitter starts as an
|
|
15
|
+
`unsupported()` stub. Prerequisite: the arm64 sources gain arch
|
|
16
|
+
self-guards so both subtrees can be listed unconditionally in CMake.
|
|
17
|
+
|
|
18
|
+
**Tech Stack:** C++17, asmjit x86 backend (vendored, `asmjit/x86.h`),
|
|
19
|
+
CMake/Ninja, clang, native x86-64 ASan build + aarch64 qemu cross build.
|
|
20
|
+
|
|
21
|
+
**Spec:** `doc/superpowers/specs/2026-08-23-x86-64-jit-design.md`
|
|
22
|
+
(register convention, sharing policy, AVX gate, testing sections).
|
|
23
|
+
|
|
24
|
+
## Global Constraints
|
|
25
|
+
|
|
26
|
+
- Worktree `/home/tmikov/work/hermes-x86-jit`, branch `x86-jit`. NEVER
|
|
27
|
+
`cd`; pass absolute paths (project rule).
|
|
28
|
+
- Builds:
|
|
29
|
+
- arm64 reference: `cmake-build-arm64` (existing; qemu binfmt runs with
|
|
30
|
+
`QEMU_LD_PREFIX=/usr/aarch64-linux-gnu`).
|
|
31
|
+
- x86-64 host compilers: `cmake-build-host` (existing; JIT off).
|
|
32
|
+
- x86-64 JIT dev build (created in Task 2):
|
|
33
|
+
`cmake-build-x86jit`, ASan+Debug -O1, clang,
|
|
34
|
+
`-DHERMESVM_ALLOW_JIT=2`.
|
|
35
|
+
- The arm64 backend must remain byte-identical: after any task that
|
|
36
|
+
touches a file the arm64 build compiles, re-run the jit-diff gate
|
|
37
|
+
against `cmake-build-arm64/jit-baseline.dump` (capture it first if the
|
|
38
|
+
build tree lacks one, exactly as in the milestone-0 plan).
|
|
39
|
+
- Register convention (from the spec, binding): xRuntime=r15, xFrame=r14,
|
|
40
|
+
rbp=frame pointer, callee-saved globals rbx/r12/r13 (rbx doubles as the
|
|
41
|
+
return-value stash, mirroring arm64's x21), GPR temps
|
|
42
|
+
rax,rcx,rdx,rsi,rdi,r8,r9,r10, r11=reserved scratch (never in
|
|
43
|
+
`TempRegAlloc`), vector temps xmm0–xmm15, no vector globals. VEX
|
|
44
|
+
encodings only for vector instructions (`vmovsd`, not `movsd`), AVX
|
|
45
|
+
presence gated by CPUID at `JITContext` construction.
|
|
46
|
+
- rsp is 16-byte aligned at every emitted `call` instruction.
|
|
47
|
+
- C++: 80-column, 2-space indent, copyright header on every new file.
|
|
48
|
+
Where a ported file diverges from its arm64 counterpart for a reason
|
|
49
|
+
(not just encoding), mark the site with a `// x86-64:` comment.
|
|
50
|
+
- Commit messages end with:
|
|
51
|
+
`Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>`
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
### Task 1: Arch self-guards for the arm64 sources
|
|
56
|
+
|
|
57
|
+
**Files:**
|
|
58
|
+
- Modify: `include/hermes/VM/JIT/Config.h`
|
|
59
|
+
- Modify: `lib/VM/JIT/arm64/JIT.cpp`, `lib/VM/JIT/arm64/JitEmitter.cpp`,
|
|
60
|
+
`lib/VM/JIT/arm64/JitEmitter-internal.cpp`,
|
|
61
|
+
`lib/VM/JIT/arm64/JitEmitter-regalloc.cpp`, and the nine
|
|
62
|
+
`lib/VM/JIT/arm64/JitEmitter-{alloc,const,object,property,call,env,array,arith,control}.cpp`
|
|
63
|
+
(13 .cpp files total)
|
|
64
|
+
|
|
65
|
+
**Interfaces:**
|
|
66
|
+
- Produces: `HERMESVM_JIT_ARM64` and `HERMESVM_JIT_X86_64` macros
|
|
67
|
+
(0/1, defined unconditionally whenever `Config.h` is included), which
|
|
68
|
+
Task 2's x86-64 sources guard on.
|
|
69
|
+
|
|
70
|
+
Background: today every `lib/VM/JIT/arm64/*.cpp` self-guards on
|
|
71
|
+
`#if HERMESVM_JIT` only. That is safe solely because `Config.h` never
|
|
72
|
+
sets `HERMESVM_JIT` on x86-64. Task 2 changes that, so the arm64 files
|
|
73
|
+
must first learn to compile to nothing on non-arm64.
|
|
74
|
+
|
|
75
|
+
- [ ] **Step 1: Add per-arch macros to `Config.h`**
|
|
76
|
+
|
|
77
|
+
In `include/hermes/VM/JIT/Config.h`, immediately BEFORE the final
|
|
78
|
+
`// Only enable perf profiling support...` comment block, insert:
|
|
79
|
+
|
|
80
|
+
```cpp
|
|
81
|
+
// Per-architecture JIT selectors. Exactly one is 1 when HERMESVM_JIT is 1;
|
|
82
|
+
// both are 0 when the JIT is disabled. Arch-specific sources self-guard on
|
|
83
|
+
// these so that both backend subtrees can be listed in the build
|
|
84
|
+
// unconditionally.
|
|
85
|
+
#if HERMESVM_JIT && (defined(__aarch64__) || defined(_M_ARM64))
|
|
86
|
+
#define HERMESVM_JIT_ARM64 1
|
|
87
|
+
#else
|
|
88
|
+
#define HERMESVM_JIT_ARM64 0
|
|
89
|
+
#endif
|
|
90
|
+
#if HERMESVM_JIT && (defined(__x86_64__) || defined(_M_X64))
|
|
91
|
+
#define HERMESVM_JIT_X86_64 1
|
|
92
|
+
#else
|
|
93
|
+
#define HERMESVM_JIT_X86_64 0
|
|
94
|
+
#endif
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
- [ ] **Step 2: Switch the arm64 .cpp guards**
|
|
98
|
+
|
|
99
|
+
In each of the 13 files listed above, change the guard line
|
|
100
|
+
|
|
101
|
+
```cpp
|
|
102
|
+
#if HERMESVM_JIT
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
to
|
|
106
|
+
|
|
107
|
+
```cpp
|
|
108
|
+
#if HERMESVM_JIT_ARM64
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
(each file has exactly one, directly after its
|
|
112
|
+
`#include "hermes/VM/JIT/Config.h"`). Do NOT touch
|
|
113
|
+
`lib/VM/JIT/JitHandlers.cpp`, `lib/VM/JIT/JitCompiler.cpp`, or
|
|
114
|
+
`lib/VM/JIT/PerfJitDump.cpp` — those are shared and stay on
|
|
115
|
+
`#if HERMESVM_JIT` (JitCompiler.cpp's arch selection happens inside
|
|
116
|
+
`JitCurArch.h`). Headers under `lib/VM/JIT/arm64/` need no guards: they
|
|
117
|
+
are included only from arm64-guarded contexts.
|
|
118
|
+
|
|
119
|
+
Verify coverage:
|
|
120
|
+
```bash
|
|
121
|
+
grep -L "HERMESVM_JIT_ARM64" /home/tmikov/work/hermes-x86-jit/lib/VM/JIT/arm64/*.cpp
|
|
122
|
+
```
|
|
123
|
+
Expected: no output (every .cpp converted).
|
|
124
|
+
|
|
125
|
+
- [ ] **Step 3: Rebuild arm64 and run the byte-identical gate**
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
cmake --build /home/tmikov/work/hermes-x86-jit/cmake-build-arm64 --target hermes -j "$(nproc)"
|
|
129
|
+
QEMU_LD_PREFIX=/usr/aarch64-linux-gnu \
|
|
130
|
+
/home/tmikov/work/hermes-x86-jit/utils/jit/jit-dump.sh -q \
|
|
131
|
+
-o /home/tmikov/work/hermes-x86-jit/cmake-build-arm64/jit-t1.dump \
|
|
132
|
+
/home/tmikov/work/hermes-x86-jit/cmake-build-arm64/bin/hermes
|
|
133
|
+
/home/tmikov/work/hermes-x86-jit/utils/jit/jit-diff.sh --dumps \
|
|
134
|
+
/home/tmikov/work/hermes-x86-jit/cmake-build-arm64/jit-baseline.dump \
|
|
135
|
+
/home/tmikov/work/hermes-x86-jit/cmake-build-arm64/jit-t1.dump
|
|
136
|
+
```
|
|
137
|
+
(If `jit-baseline.dump` does not exist in the build tree, capture it
|
|
138
|
+
first from the pre-change build — i.e., run the capture BEFORE Steps 1-2,
|
|
139
|
+
exactly as milestone 0 did.) Expected: exit 0, identical.
|
|
140
|
+
|
|
141
|
+
- [ ] **Step 4: Confirm the host (non-JIT) build still compiles**
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
cmake --build /home/tmikov/work/hermes-x86-jit/cmake-build-host --target hermes -j "$(nproc)"
|
|
145
|
+
```
|
|
146
|
+
Expected: clean.
|
|
147
|
+
|
|
148
|
+
- [ ] **Step 5: Commit**
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
git -C /home/tmikov/work/hermes-x86-jit add include/hermes/VM/JIT/Config.h lib/VM/JIT/arm64
|
|
152
|
+
git -C /home/tmikov/work/hermes-x86-jit commit -m "JIT: Add per-arch self-guards to the arm64 sources
|
|
153
|
+
|
|
154
|
+
The arm64 .cpp files guarded on HERMESVM_JIT alone, which was safe only
|
|
155
|
+
because Config.h never enables the JIT on other architectures. The
|
|
156
|
+
x86-64 backend is about to change that, so introduce
|
|
157
|
+
HERMESVM_JIT_ARM64/HERMESVM_JIT_X86_64 in Config.h and guard each arm64
|
|
158
|
+
translation unit on the former. Shared files (JitCompiler, JitHandlers,
|
|
159
|
+
PerfJitDump) stay on HERMESVM_JIT.
|
|
160
|
+
|
|
161
|
+
arm64 emission verified byte-identical.
|
|
162
|
+
|
|
163
|
+
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>"
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
### Task 2: The x86-64 backend skeleton
|
|
169
|
+
|
|
170
|
+
**Files:**
|
|
171
|
+
- Create: `include/hermes/VM/JIT/x86-64/JIT.h`
|
|
172
|
+
- Create: `lib/VM/JIT/x86-64/JIT.cpp`
|
|
173
|
+
- Create: `lib/VM/JIT/x86-64/JitImpl.h`
|
|
174
|
+
- Create: `lib/VM/JIT/x86-64/JitEmitter.h`
|
|
175
|
+
- Create: `lib/VM/JIT/x86-64/JitEmitter.cpp`
|
|
176
|
+
- Create: `lib/VM/JIT/x86-64/JitEmitter-internal.h`
|
|
177
|
+
- Create: `lib/VM/JIT/x86-64/JitEmitter-internal.cpp`
|
|
178
|
+
- Create: `lib/VM/JIT/x86-64/JitEmitter-regalloc.cpp`
|
|
179
|
+
- Create: `lib/VM/JIT/x86-64/JitEmitter-stubs.cpp`
|
|
180
|
+
- Modify: `include/hermes/VM/JIT/Config.h` (enable clause)
|
|
181
|
+
- Modify: `include/hermes/VM/JIT/JIT.h` (FRIEND_JIT for x86_64::Emitter)
|
|
182
|
+
- Modify: `lib/VM/JIT/JitCurArch.h` (x86-64 branch)
|
|
183
|
+
- Modify: `lib/VM/CMakeLists.txt` (list the new sources)
|
|
184
|
+
- Modify: `CMakeLists.txt` + `test/lit.cfg` (jit_arch lit feature)
|
|
185
|
+
- Create: `test/jit/lit.local.cfg` (gate existing tests to arm64)
|
|
186
|
+
|
|
187
|
+
**Interfaces:**
|
|
188
|
+
- Consumes: the shared driver `lib/VM/JIT/JitCompiler.cpp` — its calls
|
|
189
|
+
define the required `Emitter` surface; `HERMESVM_JIT_X86_64` from
|
|
190
|
+
Task 1.
|
|
191
|
+
- Produces: `x86_64::JITContext` and `x86_64::Emitter` with the complete
|
|
192
|
+
method surface (mostly stubs); `jit_arch` lit feature. Task 3
|
|
193
|
+
implements the substrate inside these files without changing their
|
|
194
|
+
names or the surface.
|
|
195
|
+
|
|
196
|
+
This task's deliverable is a BUILDING x86-64 JIT that compiles nothing:
|
|
197
|
+
`Emitter::enter()` immediately reports "unsupported", so every function
|
|
198
|
+
falls back to the interpreter and the whole test suite stays green. The
|
|
199
|
+
compiler enforces surface completeness: the task is done linking when
|
|
200
|
+
every method `JitCompiler.cpp` calls exists.
|
|
201
|
+
|
|
202
|
+
- [ ] **Step 1: Port the public header**
|
|
203
|
+
|
|
204
|
+
Copy `include/hermes/VM/JIT/arm64/JIT.h` to
|
|
205
|
+
`include/hermes/VM/JIT/x86-64/JIT.h` and apply exactly these changes:
|
|
206
|
+
- Header guard: `HERMES_VM_JIT_ARM64_JIT_H` → `HERMES_VM_JIT_X86_64_JIT_H`
|
|
207
|
+
(both lines and the trailing comment).
|
|
208
|
+
- `namespace arm64` → `namespace x86_64` (open and close).
|
|
209
|
+
- In the constructor declaration's doc comment, add:
|
|
210
|
+
`/// On x86-64 the JIT additionally requires AVX; without it the`
|
|
211
|
+
`/// context is constructed disabled.`
|
|
212
|
+
(The check itself lands in JIT.cpp, Step 3.)
|
|
213
|
+
Everything else — `DumpJitCode`, the full `JITContext` class, the inline
|
|
214
|
+
`shouldCompile`/`compile` — stays character-identical. This IS the
|
|
215
|
+
spec's "interface contract": the two headers must stay method-for-method
|
|
216
|
+
identical.
|
|
217
|
+
|
|
218
|
+
- [ ] **Step 2: Wire the dispatchers**
|
|
219
|
+
|
|
220
|
+
(a) `include/hermes/VM/JIT/JIT.h`: the x86-64 branch already exists.
|
|
221
|
+
Extend its `#elif` block (currently `using x86_64::JITContext;` and a
|
|
222
|
+
`FRIEND_JIT` defining only the JITContext friend) to match the arm64
|
|
223
|
+
shape:
|
|
224
|
+
|
|
225
|
+
```cpp
|
|
226
|
+
#elif defined(__x86_64__) || defined(_M_X64)
|
|
227
|
+
using x86_64::JITContext;
|
|
228
|
+
namespace x86_64 {
|
|
229
|
+
class Emitter;
|
|
230
|
+
}
|
|
231
|
+
#define FRIEND_JIT \
|
|
232
|
+
friend class x86_64::JITContext; \
|
|
233
|
+
friend class x86_64::Emitter;
|
|
234
|
+
#endif
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
(b) `lib/VM/JIT/JitCurArch.h`: replace the `#else` / `#error` tail with:
|
|
238
|
+
|
|
239
|
+
```cpp
|
|
240
|
+
#elif defined(__x86_64__) || defined(_M_X64)
|
|
241
|
+
|
|
242
|
+
#include "hermes/VM/JIT/x86-64/JIT.h"
|
|
243
|
+
|
|
244
|
+
#include "x86-64/JitEmitter.h"
|
|
245
|
+
#include "x86-64/JitImpl.h"
|
|
246
|
+
|
|
247
|
+
#define HERMESVM_JIT_ARCH_NS x86_64
|
|
248
|
+
|
|
249
|
+
#else
|
|
250
|
+
#error "JitCurArch.h: unsupported JIT architecture"
|
|
251
|
+
#endif
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
(c) `include/hermes/VM/JIT/Config.h`: extend the auto-enable clause
|
|
255
|
+
(the `#if !defined(HERMESVM_JIT) && (defined(__aarch64__) ...` block)
|
|
256
|
+
so its arch condition reads:
|
|
257
|
+
|
|
258
|
+
```cpp
|
|
259
|
+
#if !defined(HERMESVM_JIT) && \
|
|
260
|
+
(defined(__aarch64__) || defined(_M_ARM64) || \
|
|
261
|
+
((defined(__x86_64__) || defined(_M_X64)) && \
|
|
262
|
+
!defined(_WIN32))) && \
|
|
263
|
+
(!defined(HERMESVM_COMPRESSED_POINTERS) || \
|
|
264
|
+
defined(HERMESVM_CONTIGUOUS_HEAP))
|
|
265
|
+
#define HERMESVM_JIT 1
|
|
266
|
+
#else
|
|
267
|
+
#define HERMESVM_JIT 0
|
|
268
|
+
#endif
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
Windows x64 stays excluded (spec). The Apple clause above it already
|
|
272
|
+
restricts to macOS/Catalyst and applies to x86-64 Macs unchanged. Note
|
|
273
|
+
`HERMESVM_ALLOW_JIT == 2` force-defines `HERMESVM_JIT 1` with no arch
|
|
274
|
+
check — pre-existing "I know what I'm doing" semantics, unchanged.
|
|
275
|
+
|
|
276
|
+
- [ ] **Step 3: Port JitImpl.h and JIT.cpp**
|
|
277
|
+
|
|
278
|
+
Copy `lib/VM/JIT/arm64/JitImpl.h` → `lib/VM/JIT/x86-64/JitImpl.h`:
|
|
279
|
+
change the include of `hermes/VM/JIT/arm64/JIT.h` to
|
|
280
|
+
`hermes/VM/JIT/x86-64/JIT.h`, `#include "asmjit/a64.h"` →
|
|
281
|
+
`#include "asmjit/x86.h"`, namespace `arm64` → `x86_64`, and the guard
|
|
282
|
+
macro if it has one (`#pragma once` stays as-is). The `Impl` struct body
|
|
283
|
+
(asmjit `JitRuntime`, HC id counter/limit, `usedHCs`) is arch-neutral —
|
|
284
|
+
keep it identical.
|
|
285
|
+
|
|
286
|
+
Copy `lib/VM/JIT/arm64/JIT.cpp` → `lib/VM/JIT/x86-64/JIT.cpp` (the
|
|
287
|
+
54-line housekeeping file): guard becomes `#if HERMESVM_JIT_X86_64`,
|
|
288
|
+
include becomes `hermes/VM/JIT/x86-64/JIT.h`, namespace `x86_64`. Then
|
|
289
|
+
add the AVX gate to the constructor per the spec:
|
|
290
|
+
|
|
291
|
+
```cpp
|
|
292
|
+
JITContext::JITContext(bool enable) : enabled_(enable) {
|
|
293
|
+
// x86-64: the backend emits VEX encodings unconditionally; without AVX
|
|
294
|
+
// the JIT stays disabled and the interpreter carries on.
|
|
295
|
+
if (enabled_ && !__builtin_cpu_supports("avx"))
|
|
296
|
+
enabled_ = false;
|
|
297
|
+
if (!enabled_)
|
|
298
|
+
return;
|
|
299
|
+
impl_ = std::make_unique<Impl>();
|
|
300
|
+
}
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
- [ ] **Step 4: Create the Emitter header with the full surface**
|
|
304
|
+
|
|
305
|
+
Copy `lib/VM/JIT/arm64/JitEmitter.h` → `lib/VM/JIT/x86-64/JitEmitter.h`
|
|
306
|
+
and rewrite the arch-specific substrate declarations, keeping the METHOD
|
|
307
|
+
SURFACE (every public method the shared Compiler calls, plus the members
|
|
308
|
+
it touches: `emittingIP`, `code`, the ctor signature, `StringSwitchCase`)
|
|
309
|
+
character-compatible. Required substrate rewrites:
|
|
310
|
+
- `#include "asmjit/a64.h"` → `#include "asmjit/x86.h"`;
|
|
311
|
+
`namespace a64 = asmjit::a64;` → `namespace x86 = asmjit::x86;`;
|
|
312
|
+
assembler type `a64::Assembler` → `x86::Assembler`.
|
|
313
|
+
- Register constants (replacing the arm64 x19/x20/x21 block):
|
|
314
|
+
|
|
315
|
+
```cpp
|
|
316
|
+
// x86-64: SysV register convention (see the design spec).
|
|
317
|
+
static constexpr auto xRuntime = x86::r15;
|
|
318
|
+
static constexpr auto xFrame = x86::r14;
|
|
319
|
+
// Reserved scratch, never allocated by TempRegAlloc.
|
|
320
|
+
static constexpr auto xScratch = x86::r11;
|
|
321
|
+
// GPR temps: {rax,rcx,rdx} and {rsi,rdi,r8,r9,r10} (asmjit ids 0-2,6-10);
|
|
322
|
+
// rbx/rsp/rbp (3-5) sit between the ranges and are never temps.
|
|
323
|
+
static constexpr std::pair<uint8_t, uint8_t> kGPTemp1(0, 2);
|
|
324
|
+
static constexpr std::pair<uint8_t, uint8_t> kGPTemp2(6, 10);
|
|
325
|
+
// Callee-saved global pool: rbx (also the return-value stash, the x21
|
|
326
|
+
// analogue), r12, r13. Not contiguous, so a list, not a range.
|
|
327
|
+
static constexpr uint8_t kGPSavedList[] = {3, 12, 13};
|
|
328
|
+
// Vector temps: all of xmm0-xmm15; no callee-saved vector registers
|
|
329
|
+
// exist in SysV, so there are no vector globals.
|
|
330
|
+
static constexpr std::pair<uint8_t, uint8_t> kVecTemp(0, 15);
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
- `HWReg`: same class shape (combined index, Gp/Vec tag), with accessors
|
|
334
|
+
`a64GpX()`/`a64VecD()` renamed to return `x86::Gp` (`x86::gpq(idx)`)
|
|
335
|
+
and `x86::Xmm` (`x86::xmm(idx)`); pick names `gpq()`/`xmm()` and use
|
|
336
|
+
them consistently in the .cpp files.
|
|
337
|
+
- `TempRegAlloc` members: `gpTemp_{kGPTemp1, kGPTemp2}` (the two-range
|
|
338
|
+
form already exists for arm64's vector temps), `vecTemp_{kVecTemp}`.
|
|
339
|
+
- Everything the Compiler interacts with keeps its exact arm64 name and
|
|
340
|
+
signature: the ctor (9 args), `enter(uint32_t, uint32_t)`,
|
|
341
|
+
`leave(llvh::ArrayRef<const asmjit::Label *>)`, `newBasicBlock`,
|
|
342
|
+
`newPrefLabel`, `addToRuntime`, `assertPostInstructionInvariants`,
|
|
343
|
+
`emitPendingTypeAsserts`, `emittingIP`, `code`, `unsupported...`
|
|
344
|
+
mechanism, `StringSwitchCase`, and all ~150 per-opcode methods. Do not
|
|
345
|
+
drop any method even if its Task-2 body is a stub — link errors against
|
|
346
|
+
`JitCompiler.cpp` are the completeness check.
|
|
347
|
+
- Delete arm64-only private helpers that Task 2/3 will not port yet ONLY
|
|
348
|
+
if nothing kept references them; when in doubt keep the declaration.
|
|
349
|
+
|
|
350
|
+
- [ ] **Step 5: Stub implementation files**
|
|
351
|
+
|
|
352
|
+
`lib/VM/JIT/x86-64/JitEmitter-internal.h/.cpp`: port from arm64 only
|
|
353
|
+
what the skeleton needs — the `OurErrorHandler`/`OurLogger` classes, the
|
|
354
|
+
`comment()` plumbing, and the `EMIT_RUNTIME_CALL*` macros (bodies may
|
|
355
|
+
assert-fail until Task 3). Everything else (tag helpers, SHV decoder)
|
|
356
|
+
waits for later milestones.
|
|
357
|
+
|
|
358
|
+
`lib/VM/JIT/x86-64/JitEmitter.cpp`: implement for real —
|
|
359
|
+
- the constructor (identical logic to arm64's: error handler, `code.init`
|
|
360
|
+
from `jitImpl.jr`, logger when dumping, `code.attach(&a)`, RO-data and
|
|
361
|
+
return labels, the three property-cache RO constants),
|
|
362
|
+
- `addToRuntime` (identical),
|
|
363
|
+
- `newPrefLabel`, `reserveData`, `uint64Const`, `emitROData` (identical
|
|
364
|
+
logic),
|
|
365
|
+
- `assertPostInstructionInvariants` (port, iterating the x86 temp
|
|
366
|
+
ranges), `emitPendingTypeAsserts` (empty for now: no asserts emitted),
|
|
367
|
+
- `unsupported(const char *what)`: route through the same expected-error
|
|
368
|
+
mechanism arm64 uses so compilation of the function is abandoned
|
|
369
|
+
cleanly (`expectedError_` + longjmp callback), reported as
|
|
370
|
+
"unsupported instruction".
|
|
371
|
+
- `enter()`: for Task 2, exactly `unsupported("enter");` — the JIT
|
|
372
|
+
declines every function. `leave()`, `newBasicBlock`: port the arm64
|
|
373
|
+
logic (they are reachable only after enter succeeds; a stub body that
|
|
374
|
+
asserts-unreachable is acceptable for Task 2 if the port is deferred —
|
|
375
|
+
choose one and say which in the report).
|
|
376
|
+
|
|
377
|
+
`lib/VM/JIT/x86-64/JitEmitter-regalloc.cpp`: Task 2 may leave this file
|
|
378
|
+
containing only the copyright header, guard, and includes if no kept
|
|
379
|
+
declaration needs a body to link; otherwise stub bodies with
|
|
380
|
+
`hermes_fatal("x86-64 jit: regalloc not yet implemented")`.
|
|
381
|
+
|
|
382
|
+
`lib/VM/JIT/x86-64/JitEmitter-stubs.cpp`: every per-opcode Emitter
|
|
383
|
+
method as a stub. Generate mechanically:
|
|
384
|
+
|
|
385
|
+
```cpp
|
|
386
|
+
#define UNIMPL(name) \
|
|
387
|
+
void Emitter::name { unsupported(#name); }
|
|
388
|
+
```
|
|
389
|
+
is NOT expressible for varied signatures — instead write each stub
|
|
390
|
+
explicitly, e.g.:
|
|
391
|
+
|
|
392
|
+
```cpp
|
|
393
|
+
void Emitter::mov(FR frRes, FR frInput, bool logComment) {
|
|
394
|
+
unsupported("mov");
|
|
395
|
+
}
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
Derive the complete list by building: compile+link the x86 build and add
|
|
399
|
+
stubs until `JitCompiler.cpp` links with no undefined `x86_64::Emitter`
|
|
400
|
+
symbols. Every stub body is exactly `unsupported("<methodName>");`.
|
|
401
|
+
|
|
402
|
+
All new .cpp files guard with `#if HERMESVM_JIT_X86_64` after including
|
|
403
|
+
`hermes/VM/JIT/Config.h`; all new files get the standard copyright
|
|
404
|
+
header.
|
|
405
|
+
|
|
406
|
+
- [ ] **Step 6: Build wiring**
|
|
407
|
+
|
|
408
|
+
`lib/VM/CMakeLists.txt`: inside `if (HERMESVM_ALLOW_JIT)`, after the
|
|
409
|
+
arm64 file list, add:
|
|
410
|
+
|
|
411
|
+
```
|
|
412
|
+
JIT/x86-64/JitEmitter.cpp JIT/x86-64/JitEmitter.h
|
|
413
|
+
JIT/x86-64/JitEmitter-internal.cpp JIT/x86-64/JitEmitter-internal.h
|
|
414
|
+
JIT/x86-64/JitEmitter-regalloc.cpp
|
|
415
|
+
JIT/x86-64/JitEmitter-stubs.cpp
|
|
416
|
+
JIT/x86-64/JIT.cpp
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
Top-level `CMakeLists.txt` (the lit params block around line 860, which
|
|
420
|
+
already passes `jit_enabled=${HERMESVM_ALLOW_JIT}`): add a
|
|
421
|
+
`jit_arch=${CMAKE_SYSTEM_PROCESSOR}` param next to it, and in
|
|
422
|
+
`test/lit.cfg` (next to the existing `jit_enabled` handling at line ~66)
|
|
423
|
+
add:
|
|
424
|
+
|
|
425
|
+
```python
|
|
426
|
+
jit_arch = lit_config.params.get("jit_arch", "")
|
|
427
|
+
if jit_arch in ("aarch64", "arm64"):
|
|
428
|
+
config.available_features.add("jit-arch-arm64")
|
|
429
|
+
elif jit_arch in ("x86_64", "AMD64", "amd64"):
|
|
430
|
+
config.available_features.add("jit-arch-x86-64")
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
Create `test/jit/lit.local.cfg`:
|
|
434
|
+
|
|
435
|
+
```python
|
|
436
|
+
# The tests in this directory currently assume the arm64 backend's opcode
|
|
437
|
+
# coverage; the x86-64 backend is under bring-up and declines most
|
|
438
|
+
# functions, which breaks the -Xjit-crash-on-error RUN lines. Gate the
|
|
439
|
+
# directory to arm64 until x86-64 coverage lands; x86-64 bring-up tests
|
|
440
|
+
# live in the x86-64/ subdirectory.
|
|
441
|
+
if "jit-arch-arm64" not in config.available_features:
|
|
442
|
+
config.unsupported = True
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
(The `x86-64/` subdirectory arrives in Task 3 with its own
|
|
446
|
+
lit.local.cfg re-enabling itself.)
|
|
447
|
+
|
|
448
|
+
- [ ] **Step 7: Configure the x86-64 JIT dev build and build it**
|
|
449
|
+
|
|
450
|
+
```bash
|
|
451
|
+
cmake -B /home/tmikov/work/hermes-x86-jit/cmake-build-x86jit -G Ninja \
|
|
452
|
+
-S /home/tmikov/work/hermes-x86-jit \
|
|
453
|
+
-DCMAKE_BUILD_TYPE=Debug \
|
|
454
|
+
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
|
|
455
|
+
-DHERMES_ENABLE_ADDRESS_SANITIZER=ON \
|
|
456
|
+
-DCMAKE_CXX_FLAGS="-O1" -DCMAKE_C_FLAGS="-O1" \
|
|
457
|
+
-DHERMESVM_ALLOW_JIT=2
|
|
458
|
+
cmake --build /home/tmikov/work/hermes-x86-jit/cmake-build-x86jit --target hermes -j "$(nproc)"
|
|
459
|
+
```
|
|
460
|
+
Expected: clean build. Iterate Step 5's stub list until it links.
|
|
461
|
+
|
|
462
|
+
- [ ] **Step 8: Behavior gates**
|
|
463
|
+
|
|
464
|
+
```bash
|
|
465
|
+
echo 'function f(a,b){return a+b} print(f(2,3))' > /tmp/claude-1001/-home-tmikov-work-hermes/2bea243a-bcbe-414b-8b14-9a0aba58abe4/scratchpad/m1.js
|
|
466
|
+
/home/tmikov/work/hermes-x86-jit/cmake-build-x86jit/bin/hermes -Xjit=force -Xdump-jitcode=2 \
|
|
467
|
+
/tmp/claude-1001/-home-tmikov-work-hermes/2bea243a-bcbe-414b-8b14-9a0aba58abe4/scratchpad/m1.js
|
|
468
|
+
```
|
|
469
|
+
Expected: prints `5`; the dump-jitcode status output shows compilation
|
|
470
|
+
being declined (no "successfully compiled"), no crash, ASan clean.
|
|
471
|
+
Then the full suite:
|
|
472
|
+
```bash
|
|
473
|
+
cmake --build /home/tmikov/work/hermes-x86-jit/cmake-build-x86jit --target check-hermes -j "$(nproc)"
|
|
474
|
+
```
|
|
475
|
+
Expected: all tests pass; the `test/jit` directory reports as
|
|
476
|
+
Unsupported (gated by lit.local.cfg), NOT as failures.
|
|
477
|
+
|
|
478
|
+
- [ ] **Step 9: arm64 regression check**
|
|
479
|
+
|
|
480
|
+
The shared files touched (`Config.h`, `JIT/JIT.h`, `JitCurArch.h`,
|
|
481
|
+
CMake/lit) are compiled by the arm64 build too:
|
|
482
|
+
```bash
|
|
483
|
+
cmake --build /home/tmikov/work/hermes-x86-jit/cmake-build-arm64 --target hermes -j "$(nproc)"
|
|
484
|
+
QEMU_LD_PREFIX=/usr/aarch64-linux-gnu \
|
|
485
|
+
/home/tmikov/work/hermes-x86-jit/utils/jit/jit-dump.sh -q \
|
|
486
|
+
-o /home/tmikov/work/hermes-x86-jit/cmake-build-arm64/jit-t2.dump \
|
|
487
|
+
/home/tmikov/work/hermes-x86-jit/cmake-build-arm64/bin/hermes
|
|
488
|
+
/home/tmikov/work/hermes-x86-jit/utils/jit/jit-diff.sh --dumps \
|
|
489
|
+
/home/tmikov/work/hermes-x86-jit/cmake-build-arm64/jit-baseline.dump \
|
|
490
|
+
/home/tmikov/work/hermes-x86-jit/cmake-build-arm64/jit-t2.dump
|
|
491
|
+
LIT_FILTER="jit/" cmake --build /home/tmikov/work/hermes-x86-jit/cmake-build-arm64 --target check-hermes -j "$(nproc)"
|
|
492
|
+
```
|
|
493
|
+
Expected: dumps identical; lit 46 passes + 1 unsupported.
|
|
494
|
+
|
|
495
|
+
- [ ] **Step 10: Commit**
|
|
496
|
+
|
|
497
|
+
```bash
|
|
498
|
+
git -C /home/tmikov/work/hermes-x86-jit add -A
|
|
499
|
+
git -C /home/tmikov/work/hermes-x86-jit status --short # review: only intended files
|
|
500
|
+
git -C /home/tmikov/work/hermes-x86-jit commit -m "JIT: x86-64 backend skeleton
|
|
501
|
+
|
|
502
|
+
Enables HERMESVM_JIT on x86-64 SysV (AVX-gated at JITContext
|
|
503
|
+
construction) and adds the x86-64 backend tree with the full Emitter
|
|
504
|
+
surface the shared driver requires. Every per-opcode method is an
|
|
505
|
+
unsupported() stub and enter() declines immediately, so the JIT
|
|
506
|
+
compiles nothing yet and every function falls back to the interpreter;
|
|
507
|
+
the entire test suite runs green with the JIT enabled. Adds the
|
|
508
|
+
jit_arch lit feature and gates test/jit to arm64 until x86-64 opcode
|
|
509
|
+
coverage lands.
|
|
510
|
+
|
|
511
|
+
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>"
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
---
|
|
515
|
+
|
|
516
|
+
### Task 3: The FR substrate and first compiled functions
|
|
517
|
+
|
|
518
|
+
**Files:**
|
|
519
|
+
- Modify: `lib/VM/JIT/x86-64/JitEmitter.h` (fill substrate decls as
|
|
520
|
+
needed), `lib/VM/JIT/x86-64/JitEmitter.cpp` (enter/frameSetup/leave,
|
|
521
|
+
callRuntime plumbing), `lib/VM/JIT/x86-64/JitEmitter-regalloc.cpp`
|
|
522
|
+
(the register-file engine), `lib/VM/JIT/x86-64/JitEmitter-internal.h`
|
|
523
|
+
(frame-address helpers), `lib/VM/JIT/x86-64/JitEmitter-stubs.cpp`
|
|
524
|
+
(remove the stubs being implemented)
|
|
525
|
+
- Create: `lib/VM/JIT/x86-64/JitEmitter-const.cpp` (loadConstDouble,
|
|
526
|
+
loadConstBits64), move `mov`, `loadParam`, `ret` implementations to
|
|
527
|
+
their arm64-corresponding files (`JitEmitter.cpp` for mov/loadParam,
|
|
528
|
+
a new `JitEmitter-control.cpp` for ret) — mirror the arm64 file→topic
|
|
529
|
+
mapping so the trees stay navigable side by side
|
|
530
|
+
- Create: `test/jit/x86-64/skeleton.js`, `test/jit/x86-64/lit.local.cfg`
|
|
531
|
+
- Modify: `lib/VM/CMakeLists.txt` (add the new .cpp files)
|
|
532
|
+
|
|
533
|
+
**Interfaces:**
|
|
534
|
+
- Consumes: Task 2's skeleton; the arm64 reference implementations
|
|
535
|
+
(`lib/VM/JIT/arm64/JitEmitter-regalloc.cpp`, `JitEmitter.cpp:100-583`
|
|
536
|
+
for enter/frameSetup/leave, `JitEmitter-const.cpp:16-102`,
|
|
537
|
+
`JitEmitter.cpp:754-845` for mov/loadParam,
|
|
538
|
+
`JitEmitter-control.cpp:35-38` for ret).
|
|
539
|
+
- Produces: a working prologue/epilogue and FR register file; the first
|
|
540
|
+
functions that COMPILE and EXECUTE on x86-64.
|
|
541
|
+
|
|
542
|
+
Port rules (the arm64 file is the reference; translate, don't redesign):
|
|
543
|
+
|
|
544
|
+
1. **Frame layout** (replaces the arm64 diagram at
|
|
545
|
+
`JitEmitter.cpp:267-284`):
|
|
546
|
+
|
|
547
|
+
```
|
|
548
|
+
Higher addresses at the top.
|
|
549
|
+
+-----------------------------+ <-- caller rsp before call
|
|
550
|
+
| return address |
|
|
551
|
+
+-----------------------------+
|
|
552
|
+
| saved rbp | <-- rbp
|
|
553
|
+
+-----------------------------+
|
|
554
|
+
| saved r15, r14, then |
|
|
555
|
+
| rbx/r12/r13 as used |
|
|
556
|
+
+-----------------------------+
|
|
557
|
+
| Saved SHLocals* (optional) |
|
|
558
|
+
+-----------------------------+
|
|
559
|
+
| SHJmpBuf (optional) |
|
|
560
|
+
+-----------------------------+
|
|
561
|
+
| alignment padding 0-8 | <-- rsp (rsp % 16 == 0 here)
|
|
562
|
+
+-----------------------------+
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
Prologue: `push rbp; mov rbp, rsp;` then `push` r15, r14, and each
|
|
566
|
+
used entry of `kGPSavedList` (rbx is ALWAYS saved — it is the return
|
|
567
|
+
stash, the x21 analogue); then one `sub rsp, N` covering the optional
|
|
568
|
+
SHLocals slot, optional SHJmpBuf, and padding, with N computed so
|
|
569
|
+
`rsp % 16 == 0` after it (after `push rbp` rsp % 16 == 0; each
|
|
570
|
+
subsequent push flips it by 8 — fold that into N). Assert the
|
|
571
|
+
alignment computation with a static comment showing the arithmetic.
|
|
572
|
+
Epilogue (leave): restore in exact reverse; return value: `ret(FR)`
|
|
573
|
+
stashes into rbx via `movHWFromFR(HWReg::gpq(3), frValue)` and jumps
|
|
574
|
+
to `returnLabel_`; `leave()` does `mov rax, rbx` before the pops
|
|
575
|
+
(mirroring arm64's `mov x0, x21` at `JitEmitter.cpp:555`).
|
|
576
|
+
|
|
577
|
+
2. **enter()**: port `JitEmitter.cpp:100-164` with one structural
|
|
578
|
+
change, commented `// x86-64:`: the global-assignment loops walk
|
|
579
|
+
`kGPSavedList` (no vector loop — no vector globals; number FRs and
|
|
580
|
+
non-pointer FRs both take GPRs from the list, numbers first). The
|
|
581
|
+
exception-table/no-globals assert and `catchTableLabel_` logic port
|
|
582
|
+
unchanged.
|
|
583
|
+
|
|
584
|
+
3. **frameSetup()**: port `JitEmitter.cpp:244-521` with these
|
|
585
|
+
translations: `mov xRuntime, rdi` (first SysV arg; arm64 used x0);
|
|
586
|
+
the stack-overflow check's `sub/cmp/b_hi` becomes `mov/sub/cmp/ja`
|
|
587
|
+
using `xScratch` and one temp; `ldur` of NewTarget becomes
|
|
588
|
+
`mov reg, [xFrame + NewTarget*8]`; the `_sh_enter` register-fill loop
|
|
589
|
+
uses `vpxor xmm0` + `vmovups [ptr], xmm0` pairs (16 bytes each) in
|
|
590
|
+
the same 4/2/1 structure (`vmovups` twice per 4 regs), with the
|
|
591
|
+
>32-registers loop kept; `cbnz x0, catchTable` after `_sh_setjmp`
|
|
592
|
+
becomes `test eax, eax; jnz catchTable`. Slow-path lambdas port with
|
|
593
|
+
`em.a.mov(x86::rdi, xRuntime)` for the SHRuntime argument. All
|
|
594
|
+
`isAddSubImm` special-casing disappears: x86 `cmp`/`add` take imm32
|
|
595
|
+
directly (values here are frame sizes, far below 2^31). The
|
|
596
|
+
prohibitInvoke check uses `emit_sh_ljs_is_undefined`; port exactly
|
|
597
|
+
that one tag helper into `JitEmitter-internal.h` now (on x86:
|
|
598
|
+
materialize the raw undefined bits via `mov r11, imm64` and `cmp`) —
|
|
599
|
+
the rest of the tag-helper family still waits for milestone 2.
|
|
600
|
+
|
|
601
|
+
4. **callRuntime / callRuntimeWithSavedIP**: port
|
|
602
|
+
`JitEmitter.cpp:585-604`. Call sequence:
|
|
603
|
+
`mov r11, imm64(fn); call r11` (r11 is the reserved scratch — never
|
|
604
|
+
allocator state). `callRuntimeWithSavedIP` materializes the current
|
|
605
|
+
bytecode IP as a 64-bit immediate into r11 and stores it to the
|
|
606
|
+
frame's SavedIP slot before the call, replacing arm64's
|
|
607
|
+
`getBytecodeIP` add-chain (`// x86-64:` comment on the
|
|
608
|
+
simplification). Frame slot addressing everywhere is
|
|
609
|
+
`[xFrame + disp32]`.
|
|
610
|
+
|
|
611
|
+
5. **JitEmitter-regalloc.cpp**: port the whole arm64 file
|
|
612
|
+
(`lib/VM/JIT/arm64/JitEmitter-regalloc.cpp`, 508 lines) function by
|
|
613
|
+
function, same names, same order. Instruction translation table:
|
|
614
|
+
`mov xN, xM` → `mov gpq, gpq`; `fmov dN, dM` → `vmovsd xmm, xmm, xmm`
|
|
615
|
+
(VEX three-operand form of the reg-reg move) or `vmovaps xmm, xmm`;
|
|
616
|
+
`fmov dN, xM` → `vmovq xmm, gpq`; `fmov xN, dM` → `vmovq gpq, xmm`;
|
|
617
|
+
`ldr xN, [xFrame, ofs]` → `mov gpq, [xFrame + ofs]`;
|
|
618
|
+
`str xN, [xFrame, ofs]` → `mov [xFrame + ofs], gpq`;
|
|
619
|
+
`ldr dN, [...]` → `vmovsd xmm, [...]`;
|
|
620
|
+
`str dN, [...]` → `vmovsd [...], xmm`.
|
|
621
|
+
The FR-state logic (contains/frameUpToDate/globalRegUpToDate
|
|
622
|
+
bookkeeping, LRU spilling) is copied as-is — it is arch-independent
|
|
623
|
+
bookkeeping and future extraction depends on it staying textually
|
|
624
|
+
close.
|
|
625
|
+
|
|
626
|
+
6. **The five real emitters**: `loadConstBits64` and `loadConstDouble`
|
|
627
|
+
port from `JitEmitter-const.cpp:16-102` (`loadBits64InGp` becomes
|
|
628
|
+
`mov gpq, imm64` — one instruction, no movk chains; keep the
|
|
629
|
+
double-in-vector fast path structure of loadConstDouble); `mov` and
|
|
630
|
+
`loadParam` from `JitEmitter.cpp:754-845` (loadParam's slow path
|
|
631
|
+
calls the same runtime helper; the fast path's `cmp`/branch on argc
|
|
632
|
+
translates directly); `ret` from `JitEmitter-control.cpp:35-38`
|
|
633
|
+
(stash to rbx + `jmp returnLabel_`). Remove exactly these five from
|
|
634
|
+
`JitEmitter-stubs.cpp`. `enter()` stops being `unsupported`.
|
|
635
|
+
|
|
636
|
+
7. **Function-level fallback still works**: any function whose bytecode
|
|
637
|
+
contains ANY opcode other than {LoadParam, LoadParamLong,
|
|
638
|
+
LoadConst*, Mov, MovLong, Ret} still hits an `unsupported()` stub and
|
|
639
|
+
falls back. That is the ratchet.
|
|
640
|
+
|
|
641
|
+
- [ ] **Step 1: Port regalloc + frame helpers; build after each file**
|
|
642
|
+
|
|
643
|
+
Port `JitEmitter-regalloc.cpp` first (it has no dependency on
|
|
644
|
+
enter/leave), building
|
|
645
|
+
`cmake --build /home/tmikov/work/hermes-x86-jit/cmake-build-x86jit --target hermes -j "$(nproc)"`
|
|
646
|
+
after each file to keep errors local.
|
|
647
|
+
|
|
648
|
+
- [ ] **Step 2: Implement enter/frameSetup/leave/callRuntime per rules 1-4**
|
|
649
|
+
|
|
650
|
+
- [ ] **Step 3: Implement the five emitters per rule 6**
|
|
651
|
+
|
|
652
|
+
- [ ] **Step 4: First end-to-end run**
|
|
653
|
+
|
|
654
|
+
```bash
|
|
655
|
+
printf 'function f(){}\nf();\nfunction g(){return 42}\nprint(g());\nfunction h(a){return a}\nprint(h("xy"));\nfunction m(a,b){var t=a; a=b; b=t; return b}\nprint(m(1,2));\n' \
|
|
656
|
+
> /tmp/claude-1001/-home-tmikov-work-hermes/2bea243a-bcbe-414b-8b14-9a0aba58abe4/scratchpad/m1-run.js
|
|
657
|
+
/home/tmikov/work/hermes-x86-jit/cmake-build-x86jit/bin/hermes -Xjit=force -Xdump-jitcode=3 \
|
|
658
|
+
/tmp/claude-1001/-home-tmikov-work-hermes/2bea243a-bcbe-414b-8b14-9a0aba58abe4/scratchpad/m1-run.js
|
|
659
|
+
```
|
|
660
|
+
Expected: output `42`, `xy`, `1`; the compile-status dump shows
|
|
661
|
+
`f`, `g`, `h`, `m` each "successfully compiled" (the global function
|
|
662
|
+
declines — it contains calls); the emitted code dump shows x86
|
|
663
|
+
mnemonics; exit 0; ASan clean. If a compiled function crashes or
|
|
664
|
+
miscompiles, debug BEFORE moving on — this is the task's core gate.
|
|
665
|
+
Also verify the CPUID gate compiles out sanely:
|
|
666
|
+
`/home/tmikov/work/hermes-x86-jit/cmake-build-x86jit/bin/hermes -Xjit=force` on the same
|
|
667
|
+
file must not crash on this AVX machine (positive path only; the
|
|
668
|
+
negative path is untestable here and is covered by code review).
|
|
669
|
+
|
|
670
|
+
- [ ] **Step 5: Add the lit test**
|
|
671
|
+
|
|
672
|
+
`test/jit/x86-64/lit.local.cfg`:
|
|
673
|
+
|
|
674
|
+
```python
|
|
675
|
+
# x86-64 bring-up tests: run exactly when the x86-64 backend is enabled.
|
|
676
|
+
config.unsupported = "jit-arch-x86-64" not in config.available_features
|
|
677
|
+
```
|
|
678
|
+
|
|
679
|
+
`test/jit/x86-64/skeleton.js` (adjust the copyright year to the current
|
|
680
|
+
one and use the standard JS header comment style from existing
|
|
681
|
+
test/jit tests):
|
|
682
|
+
|
|
683
|
+
```js
|
|
684
|
+
/**
|
|
685
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
686
|
+
*
|
|
687
|
+
* This source code is licensed under the MIT license found in the
|
|
688
|
+
* LICENSE file in the root directory of this source tree.
|
|
689
|
+
*/
|
|
690
|
+
|
|
691
|
+
// RUN: %hermes -Xjit=force -Xdump-jitcode=2 %s | %FileCheck --match-full-lines %s
|
|
692
|
+
|
|
693
|
+
function ret42() {
|
|
694
|
+
return 42;
|
|
695
|
+
}
|
|
696
|
+
function identity(a) {
|
|
697
|
+
return a;
|
|
698
|
+
}
|
|
699
|
+
function shuffle(a, b) {
|
|
700
|
+
var t = a;
|
|
701
|
+
a = b;
|
|
702
|
+
b = t;
|
|
703
|
+
return b;
|
|
704
|
+
}
|
|
705
|
+
print(ret42());
|
|
706
|
+
// CHECK: 42
|
|
707
|
+
print(identity("xy"));
|
|
708
|
+
// CHECK-NEXT: xy
|
|
709
|
+
print(shuffle(1, 2));
|
|
710
|
+
// CHECK-NEXT: 1
|
|
711
|
+
```
|
|
712
|
+
|
|
713
|
+
Plus CHECK lines for the three "successfully compiled" status lines
|
|
714
|
+
(match the exact format printed by `-Xdump-jitcode=2`, which appears
|
|
715
|
+
BEFORE the program output for force-compiled functions — order the
|
|
716
|
+
CHECK lines to match reality, verified from the actual output of
|
|
717
|
+
Step 4). Run it:
|
|
718
|
+
|
|
719
|
+
```bash
|
|
720
|
+
LIT_FILTER="jit/x86-64" cmake --build /home/tmikov/work/hermes-x86-jit/cmake-build-x86jit --target check-hermes -j "$(nproc)"
|
|
721
|
+
```
|
|
722
|
+
Expected: 1 pass. Then the full suite on x86 and the byte-identical +
|
|
723
|
+
lit gates on arm64 (same commands as Task 2 Steps 8-9). Expected: x86
|
|
724
|
+
check-hermes green, arm64 dumps identical, arm64 jit lit 46+1.
|
|
725
|
+
|
|
726
|
+
- [ ] **Step 6: Prove the gate can fail**
|
|
727
|
+
|
|
728
|
+
Temporarily break `ret` (stash `frValue`'s frame slot address instead of
|
|
729
|
+
its value, e.g. `lea rbx, [...]` instead of the mov — or any one-line
|
|
730
|
+
miscompile), rebuild, re-run Step 4's script: output must be wrong or
|
|
731
|
+
crash, proving the runtime gate actually exercises emitted code. Revert,
|
|
732
|
+
rebuild, re-verify Step 4 passes.
|
|
733
|
+
|
|
734
|
+
- [ ] **Step 7: Commit**
|
|
735
|
+
|
|
736
|
+
```bash
|
|
737
|
+
git -C /home/tmikov/work/hermes-x86-jit add -A
|
|
738
|
+
git -C /home/tmikov/work/hermes-x86-jit commit -m "JIT: x86-64 FR substrate and first compiled functions
|
|
739
|
+
|
|
740
|
+
Ports the register-file engine (regalloc), prologue/epilogue
|
|
741
|
+
(enter/frameSetup/leave), the runtime-call plumbing, and the first
|
|
742
|
+
five emitters (LoadConst*, LoadParam, Mov, Ret) from the arm64
|
|
743
|
+
backend per the milestone-1 plan. Functions consisting of those
|
|
744
|
+
opcodes now compile and execute natively; everything else still
|
|
745
|
+
falls back to the interpreter. Adds test/jit/x86-64/ with the first
|
|
746
|
+
bring-up test, gated on the new jit-arch-x86-64 lit feature.
|
|
747
|
+
|
|
748
|
+
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>"
|
|
749
|
+
```
|
|
750
|
+
|
|
751
|
+
---
|
|
752
|
+
|
|
753
|
+
### Task 4: Documentation
|
|
754
|
+
|
|
755
|
+
**Files:**
|
|
756
|
+
- Modify: `doc/JIT.md` (porting-notes section: milestone-1 status)
|
|
757
|
+
- Modify: `doc/superpowers/specs/2026-08-23-x86-64-jit-design.md`
|
|
758
|
+
(build-gating section: record the HERMESVM_JIT_ARM64/X86_64 mechanism
|
|
759
|
+
as implemented)
|
|
760
|
+
|
|
761
|
+
**Interfaces:** documentation only.
|
|
762
|
+
|
|
763
|
+
- [ ] **Step 1: doc/JIT.md**
|
|
764
|
+
|
|
765
|
+
In the "x86-64 porting notes" section, add a short status paragraph
|
|
766
|
+
after the intro line ("Observations from this analysis, to be refined
|
|
767
|
+
into a plan:"): the skeleton exists (`lib/VM/JIT/x86-64/`), what
|
|
768
|
+
compiles today (the five-opcode set), the fallback ratchet, and the
|
|
769
|
+
`cmake-build-x86jit` configure line from Task 2 Step 7 as the
|
|
770
|
+
documented dev-build recipe. Keep it under 20 lines; this section is
|
|
771
|
+
working notes, not the spec.
|
|
772
|
+
|
|
773
|
+
- [ ] **Step 2: Spec build-gating paragraph**
|
|
774
|
+
|
|
775
|
+
In the spec's "Build gating" section, after the sentence describing the
|
|
776
|
+
self-guard pattern, append: "As implemented, `Config.h` defines
|
|
777
|
+
`HERMESVM_JIT_ARM64` / `HERMESVM_JIT_X86_64` selectors and each
|
|
778
|
+
arch-specific translation unit guards on its own selector; shared files
|
|
779
|
+
guard on `HERMESVM_JIT`." Keep lines ≤80 columns.
|
|
780
|
+
|
|
781
|
+
- [ ] **Step 3: Commit**
|
|
782
|
+
|
|
783
|
+
```bash
|
|
784
|
+
git -C /home/tmikov/work/hermes-x86-jit add doc/JIT.md doc/superpowers/specs/2026-08-23-x86-64-jit-design.md
|
|
785
|
+
git -C /home/tmikov/work/hermes-x86-jit commit -m "doc: record x86-64 JIT skeleton status and arch-guard mechanism
|
|
786
|
+
|
|
787
|
+
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>"
|
|
788
|
+
```
|
|
789
|
+
|
|
790
|
+
---
|
|
791
|
+
|
|
792
|
+
## Out of scope for this plan
|
|
793
|
+
|
|
794
|
+
Milestones 2-6 (arithmetic and everything after) get their own plans.
|
|
795
|
+
No arithmetic, no tag tests, no type asserts, no ICs, no goldens beyond
|
|
796
|
+
the one skeleton test. The `emit3op` helper, NaN-condition table, and
|
|
797
|
+
HV32-specific paths arrive with the emitters that need them.
|