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,444 @@
|
|
|
1
|
+
# x86-64 JIT Arithmetic, Comparisons and Branches (Milestone 2) 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:** The x86-64 JIT compiles and correctly executes arithmetic,
|
|
6
|
+
comparisons, conditional branches and bit operations — real loops stay in
|
|
7
|
+
machine code — with the type-assert machinery ported and enabled, all
|
|
8
|
+
verified natively under ASan by differential testing against the
|
|
9
|
+
interpreter.
|
|
10
|
+
|
|
11
|
+
**Architecture:** Port the arm64 emitters `arithBinOp`/`arithUnop`/`mod`/
|
|
12
|
+
`toNumber`/`toNumeric` (Task 1), `compareImpl`/`strictEqualImpl`/`jCond`/
|
|
13
|
+
`jmp`/`jmpTrueFalse`/`jmpUndefined`/`jStrictEqual`/`booleanNot` (Task 2),
|
|
14
|
+
and `bitBinOp`/`bitNot`/`toInt32` (Task 3) into the x86-64 tree, then the
|
|
15
|
+
type-assert machinery (Task 4). The single x86-specific design element is
|
|
16
|
+
the NaN-safe condition mapping (below); everything else is instruction
|
|
17
|
+
translation over the substrate landed in milestone 1.
|
|
18
|
+
|
|
19
|
+
**Tech Stack:** C++17, asmjit x86 (VEX only), CMake/Ninja, clang, native
|
|
20
|
+
ASan build `cmake-build-x86jit`, arm64 qemu build `cmake-build-arm64` as
|
|
21
|
+
reference.
|
|
22
|
+
|
|
23
|
+
**Spec:** `doc/superpowers/specs/2026-08-23-x86-64-jit-design.md`
|
|
24
|
+
("Emitter specifics" — NaN-aware conditions; "Testing").
|
|
25
|
+
|
|
26
|
+
## Global Constraints
|
|
27
|
+
|
|
28
|
+
- Worktree `/home/tmikov/work/hermes-x86-jit`, branch `x86-jit`. NEVER
|
|
29
|
+
`cd`; absolute paths only.
|
|
30
|
+
- All changes live in `lib/VM/JIT/x86-64/` and `test/jit/x86-64/` unless
|
|
31
|
+
a task says otherwise. No shared files (`lib/VM/JIT/*.cpp/h`,
|
|
32
|
+
`include/hermes/VM/JIT/*` outside `x86-64/`) may change; if a task
|
|
33
|
+
finds it must touch one, it must also re-run the arm64 byte-identical
|
|
34
|
+
comparison (dump vs `cmake-build-arm64/jit-baseline.dump`, as in the
|
|
35
|
+
milestone-1 plan).
|
|
36
|
+
- The arm64 files are the porting reference; keep logic textually close,
|
|
37
|
+
mark real divergences `// x86-64:`. VEX encodings only. r11 stays
|
|
38
|
+
reserved (never allocator-managed). rsp%16==0 at every emitted call.
|
|
39
|
+
- Every port task ends with: x86 build clean; its new lit tests pass;
|
|
40
|
+
the FULL x86 `check-hermes` green (zero unexpected failures); ASan
|
|
41
|
+
clean on all runs; and a prove-the-gate-can-fail step (one deliberate
|
|
42
|
+
miscompile, observed failing, reverted, re-verified).
|
|
43
|
+
- Differential testing pattern for new lit tests (both RUN lines in one
|
|
44
|
+
test): run the program under the plain interpreter and under
|
|
45
|
+
`-Xjit=force`, diff the outputs; PLUS a separate
|
|
46
|
+
RUN with `-Xdump-jitcode=2` FileCheck'ing "successfully compiled" for
|
|
47
|
+
the functions under test, so the differential can never silently
|
|
48
|
+
degrade into interpreter-vs-interpreter.
|
|
49
|
+
- 80-column, 2-space indent, copyright headers. Commit messages end
|
|
50
|
+
with: `Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>`
|
|
51
|
+
|
|
52
|
+
## The NaN-safe condition mapping (binding design, used by Tasks 1-3)
|
|
53
|
+
|
|
54
|
+
After arm64's `fcmp`, the codes kGT/kGE/kMI/kLS are all false on
|
|
55
|
+
unordered, and `b.vs` routes unordered (i.e., at least one non-number,
|
|
56
|
+
since non-numbers are NaN-boxed; `HERMESVALUE_VERSION == 2`) to the slow
|
|
57
|
+
path. x86's `vucomisd` sets ZF=PF=CF=1 on unordered, so only the
|
|
58
|
+
above-family conditions are unordered-false. Therefore:
|
|
59
|
+
|
|
60
|
+
| Comparison | arm64 | x86-64 |
|
|
61
|
+
|---|---|---|
|
|
62
|
+
| greater | `fcmp L,R` + kGT | `vucomisd L,R` + `a` (ja/seta) |
|
|
63
|
+
| greaterEqual | `fcmp L,R` + kGE | `vucomisd L,R` + `ae` |
|
|
64
|
+
| less | `fcmp L,R` + kMI | **`vucomisd R,L`** (swapped) + `a` |
|
|
65
|
+
| lessEqual | `fcmp L,R` + kLS | **`vucomisd R,L`** (swapped) + `ae` |
|
|
66
|
+
| equal (numbers) | `fcmp` + kEQ after `b.vs` routing | `vucomisd L,R` + `e` after `jp` routing |
|
|
67
|
+
| unordered routing | `b.vs lab` | `jp lab` |
|
|
68
|
+
| inverted jumps | `b(negateCond)` after `b.vs` | inverse cc (`be`/`b`/`ne`) after `jp` |
|
|
69
|
+
|
|
70
|
+
Consequences, mirrored from the arm64 logic:
|
|
71
|
+
- The non-inverted `jCond` may branch on its condition BEFORE the
|
|
72
|
+
unordered routing (unordered-false makes that safe) — keep arm64's
|
|
73
|
+
ordering: direct branch, then `jp slowPath`, then (inverted case only)
|
|
74
|
+
the inverse-condition branch.
|
|
75
|
+
- The emitter signatures that take `a64::CondCode` take an
|
|
76
|
+
`x86::CondCode` from {kA, kAE, kE} **plus a `bool swapOperands`**;
|
|
77
|
+
the DECL_COMPARE/DECL_JCOND macro tables in `JitEmitter.h` supply both
|
|
78
|
+
per operation. `invert` handling stays structural (same branches as
|
|
79
|
+
arm64), never by picking a NaN-unsafe code.
|
|
80
|
+
- `setcc` writes an 8-bit register: clear the destination first
|
|
81
|
+
(`xor r32,r32` before the compare, or `movzx` after) — pick one idiom
|
|
82
|
+
and use it everywhere.
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
### Task 1: Number arithmetic
|
|
87
|
+
|
|
88
|
+
**Files:**
|
|
89
|
+
- Modify: `lib/VM/JIT/x86-64/JitEmitter-arith.cpp` (create it),
|
|
90
|
+
`lib/VM/JIT/x86-64/JitEmitter.h` (move the relevant DECL macros /
|
|
91
|
+
declarations from the stub set), `lib/VM/JIT/x86-64/JitEmitter-internal.h`
|
|
92
|
+
(tag helpers as needed), `lib/VM/JIT/x86-64/JitEmitter-stubs.cpp`
|
|
93
|
+
(remove exactly the stubs implemented here)
|
|
94
|
+
- Create: `test/jit/x86-64/arith.js`
|
|
95
|
+
|
|
96
|
+
**Interfaces:**
|
|
97
|
+
- Consumes: milestone-1 substrate (regalloc, callRuntime*, slow paths).
|
|
98
|
+
- Produces: working `arithBinOp`, `arithUnop`, `mod`, `toNumber`,
|
|
99
|
+
`toNumeric`; the ported tag-helper subset; a no-op
|
|
100
|
+
`emitTypeAssert(FR, HWReg, TypePred)` inline placeholder (asserts the
|
|
101
|
+
flag is off; Task 4 replaces it) so ported code keeps arm64's call
|
|
102
|
+
sites verbatim.
|
|
103
|
+
|
|
104
|
+
Opcode coverage after this task: Add/AddN/Sub/SubN/Mul/MulN/Div/DivN,
|
|
105
|
+
Mod, Inc/Dec, Negate, ToNumber, ToNumeric. NOT in scope: AddS,
|
|
106
|
+
AddEmptyString, TypeOf (later milestones).
|
|
107
|
+
|
|
108
|
+
Port sources (arm64): `JitEmitter-arith.cpp:18-117` (toNumber/toNumeric),
|
|
109
|
+
`:229-303` (arithUnop), `:417-508` (mod), `:509-602` (arithBinOp), plus
|
|
110
|
+
whichever `emit_sh_ljs_*` helpers those bodies use from
|
|
111
|
+
`JitEmitter-internal.h` — port exactly the helpers needed, no more.
|
|
112
|
+
Instruction translations beyond milestone 1's table: `fadd/fsub/fmul/fdiv`
|
|
113
|
+
→ `vaddsd/vsubsd/vmulsd/vdivsd` (three-operand, no aliasing hazard);
|
|
114
|
+
`fcmp` → `vucomisd`; `b.vs` → `jp`; `fneg` → `vxorpd` with the sign-bit
|
|
115
|
+
constant from RO data (or `xor gpq, imm64-sign-bit` when the value is in
|
|
116
|
+
a GP register — pick per site, note the choice); integer `eor x,x,1`
|
|
117
|
+
bool-flip → `xor r32, 1`.
|
|
118
|
+
|
|
119
|
+
- [ ] **Step 1: Port the needed tag helpers into `JitEmitter-internal.h`**
|
|
120
|
+
|
|
121
|
+
Only those referenced by this task's emitter bodies (expect
|
|
122
|
+
`emit_sh_ljs_is_double` / `emit_sh_ljs_is_bool` / `emit_sh_ljs_bool` /
|
|
123
|
+
tag-extraction helpers). Each is a direct translation of the arm64
|
|
124
|
+
helper of the same name; keep names identical. x86 note: tag tests use
|
|
125
|
+
`sar`/`shr` by 47-48 + `cmp` (imm32 fits after shifting); when a helper
|
|
126
|
+
needs the raw 64-bit tag constant, materialize via `mov gpq, imm64`
|
|
127
|
+
using a caller-provided temp — never r11 inside emitter fast paths
|
|
128
|
+
(r11 is for instrumentation/call plumbing).
|
|
129
|
+
|
|
130
|
+
- [ ] **Step 2: Port the four emitter bodies + declarations**
|
|
131
|
+
|
|
132
|
+
Move the corresponding DECL macro blocks from the stub arrangement into
|
|
133
|
+
real declarations mirroring arm64's `JitEmitter.h` layout (the
|
|
134
|
+
`DECL_ARITH_BINOP`-style tables), add the no-op `emitTypeAssert`
|
|
135
|
+
placeholder, delete exactly these stubs from `JitEmitter-stubs.cpp`.
|
|
136
|
+
Build after each emitter body:
|
|
137
|
+
`cmake --build /home/tmikov/work/hermes-x86-jit/cmake-build-x86jit --target hermes -j "$(nproc)"`
|
|
138
|
+
|
|
139
|
+
- [ ] **Step 3: The lit test**
|
|
140
|
+
|
|
141
|
+
Create `test/jit/x86-64/arith.js` with the standard copyright header and
|
|
142
|
+
these RUN lines:
|
|
143
|
+
|
|
144
|
+
```js
|
|
145
|
+
// RUN: %hermes %s > %t.int && %hermes -Xjit=force %s > %t.jit && diff %t.int %t.jit
|
|
146
|
+
// RUN: %hermes -Xjit=force -Xdump-jitcode=2 %s | %FileCheck %s
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Body: straight-line functions only (no loops/branches until Task 2 —
|
|
150
|
+
note `a ? b : c` and `&&` also branch; avoid them):
|
|
151
|
+
|
|
152
|
+
```js
|
|
153
|
+
function arith(a, b) {
|
|
154
|
+
return [a + b, a - b, a * b, a / b, a % b, -a, a + b * 3.5 - 0.5];
|
|
155
|
+
}
|
|
156
|
+
function incdec(a) {
|
|
157
|
+
var x = a;
|
|
158
|
+
x++; x++; x--;
|
|
159
|
+
return x;
|
|
160
|
+
}
|
|
161
|
+
function corner(a, b) {
|
|
162
|
+
return [a / 0, -a / 0, a % 0, 0 * b, a - a];
|
|
163
|
+
}
|
|
164
|
+
print(arith(7, 2));
|
|
165
|
+
print(arith(0.1, 0.2));
|
|
166
|
+
print(arith(-0, 0));
|
|
167
|
+
print(incdec(5.5));
|
|
168
|
+
print(corner(1, Infinity));
|
|
169
|
+
print(String(arith(NaN, 1)));
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Plus `// CHECK:` lines for the `-Xdump-jitcode=2` run asserting
|
|
173
|
+
`arith`, `incdec`, `corner` each print "successfully compiled" (copy the
|
|
174
|
+
exact status-line format from a real run), and CHECK-NEXT lines for the
|
|
175
|
+
printed values (take them from the INTERPRETER's output, never computed
|
|
176
|
+
by hand). Mixed-type operands exercise `arithBinOp`'s runtime slow call
|
|
177
|
+
while the function still compiles (slow paths are calls inside compiled
|
|
178
|
+
code, not declines). Add:
|
|
179
|
+
|
|
180
|
+
```js
|
|
181
|
+
function mixed(a, b) {
|
|
182
|
+
return a + b;
|
|
183
|
+
}
|
|
184
|
+
print(mixed(1, 2));
|
|
185
|
+
print(mixed(true, 1));
|
|
186
|
+
print(mixed(null, 3));
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
(`true`/`null` operands exercise `arithBinOp`'s slow call at run time
|
|
190
|
+
while the function still compiles.) Run
|
|
191
|
+
`LIT_FILTER="jit/x86-64" cmake --build /home/tmikov/work/hermes-x86-jit/cmake-build-x86jit --target check-hermes -j "$(nproc)"` — all pass.
|
|
192
|
+
|
|
193
|
+
- [ ] **Step 4: Gates**
|
|
194
|
+
|
|
195
|
+
Full `check-hermes` on x86 (zero unexpected failures, ASan clean).
|
|
196
|
+
Prove-can-fail: temporarily swap `vsubsd` operands in `arithBinOp`'s
|
|
197
|
+
sub case, rebuild, the arith.js differential RUN must fail; revert,
|
|
198
|
+
rebuild, re-verify.
|
|
199
|
+
|
|
200
|
+
- [ ] **Step 5: Commit**
|
|
201
|
+
|
|
202
|
+
```
|
|
203
|
+
JIT: x86-64 arithmetic emitters
|
|
204
|
+
|
|
205
|
+
Ports arithBinOp, arithUnop, mod, toNumber and toNumeric with their
|
|
206
|
+
tag-check fast paths and runtime slow paths. Non-inverted NaN
|
|
207
|
+
semantics follow the design's vucomisd mapping; unordered routing
|
|
208
|
+
uses jp where arm64 used b.vs.
|
|
209
|
+
|
|
210
|
+
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
### Task 2: Comparisons and branches
|
|
216
|
+
|
|
217
|
+
**Files:**
|
|
218
|
+
- Modify: `lib/VM/JIT/x86-64/JitEmitter-arith.cpp` (compareImpl,
|
|
219
|
+
strictEqualImpl, booleanNot), `lib/VM/JIT/x86-64/JitEmitter-control.cpp`
|
|
220
|
+
(jmp, jCond, jmpTrueFalse, jmpUndefined, jStrictEqual),
|
|
221
|
+
`JitEmitter.h` (DECL_COMPARE/DECL_JCOND tables with the x86 signature:
|
|
222
|
+
`x86::CondCode` + `bool swapOperands`), `JitEmitter-stubs.cpp`
|
|
223
|
+
- Create: `test/jit/x86-64/cmp.js`, `test/jit/x86-64/loops.js`
|
|
224
|
+
|
|
225
|
+
**Interfaces:**
|
|
226
|
+
- Consumes: Task 1's helpers and the condition mapping table above.
|
|
227
|
+
- Produces: working Greater/GreaterEq/Less/LessEq/Eq/Neq/StrictEq/
|
|
228
|
+
StrictNeq, Not, Jmp(Long), all JLess/JGreater/JEqual/JStrictEqual
|
|
229
|
+
families (± Not, ± N, ± Long), JmpTrue/JmpFalse(Long),
|
|
230
|
+
JmpUndefined(Long).
|
|
231
|
+
|
|
232
|
+
Port sources: `arm64/JitEmitter-arith.cpp:698-893` (strictEqualImpl),
|
|
233
|
+
`:894-1004` (compareImpl), `:304-323` (booleanNot);
|
|
234
|
+
`arm64/JitEmitter-control.cpp:625-706` (jmpTrueFalse, jmp,
|
|
235
|
+
jmpUndefined), `:739-856` (jCond), `:857-` (jStrictEqual); the macro
|
|
236
|
+
tables `arm64/JitEmitter.h:713-800` region. Apply the condition mapping
|
|
237
|
+
exactly as specified above; `cset` → `setcc`+zero-idiom; `cbnz/cbz w0`
|
|
238
|
+
on slow-path results → `test eax,eax; jnz/jz`.
|
|
239
|
+
|
|
240
|
+
Order-of-operations notes that are load-bearing (from the arm64 code and
|
|
241
|
+
its findings history): `strictEqualImpl` evaluates both tiers' guards
|
|
242
|
+
before `frRes` is declared updated (frRes can alias an operand);
|
|
243
|
+
`jCond`/`jmpTrueFalse` sync/free temps in arm64's exact order because a
|
|
244
|
+
branch may end the BB — keep those sequences verbatim.
|
|
245
|
+
|
|
246
|
+
- [ ] **Step 1: Port compareImpl + the DECL tables; build**
|
|
247
|
+
- [ ] **Step 2: Port strictEqualImpl, booleanNot; build**
|
|
248
|
+
- [ ] **Step 3: Port the control-flow five (jmp, jCond, jmpTrueFalse, jmpUndefined, jStrictEqual); build**
|
|
249
|
+
- [ ] **Step 4: Tests**
|
|
250
|
+
|
|
251
|
+
`test/jit/x86-64/cmp.js` — same two-RUN differential pattern. Body must
|
|
252
|
+
cover: every comparison in both polarities with NaN on each side, ±0,
|
|
253
|
+
Infinity, equal numbers, strict-equal on mixed same-bits values
|
|
254
|
+
(`0 === -0`, `NaN === NaN`), loose equal slow paths (`1 == "1"`,
|
|
255
|
+
`null == undefined`), and `!x` on bools and numbers. Straight-line
|
|
256
|
+
`print(...)` calls of comparison results only — comparisons produce
|
|
257
|
+
values; branches are exercised by loops.js.
|
|
258
|
+
|
|
259
|
+
`test/jit/x86-64/loops.js` — the milestone's headline: loops that stay
|
|
260
|
+
in machine code.
|
|
261
|
+
|
|
262
|
+
```js
|
|
263
|
+
function sum(n) {
|
|
264
|
+
var s = 0;
|
|
265
|
+
for (var i = 0; i < n; ++i) s += i;
|
|
266
|
+
return s;
|
|
267
|
+
}
|
|
268
|
+
function countdown(n) {
|
|
269
|
+
var c = 0;
|
|
270
|
+
while (n > 0) { n -= 1.5; c++; }
|
|
271
|
+
return [n, c];
|
|
272
|
+
}
|
|
273
|
+
function findFirst(limit, threshold) {
|
|
274
|
+
for (var i = 0; i < limit; ++i) {
|
|
275
|
+
if (i * i >= threshold) return i;
|
|
276
|
+
}
|
|
277
|
+
return -1;
|
|
278
|
+
}
|
|
279
|
+
function nanLoop(n) {
|
|
280
|
+
var s = 0;
|
|
281
|
+
for (var i = 0; i < n; ++i) {
|
|
282
|
+
var v = i % 3 === 0 ? NaN : i;
|
|
283
|
+
if (v < 100) s += 1;
|
|
284
|
+
if (!(v < 100)) s += 1000;
|
|
285
|
+
}
|
|
286
|
+
return s;
|
|
287
|
+
}
|
|
288
|
+
print(sum(1000));
|
|
289
|
+
print(countdown(10));
|
|
290
|
+
print(findFirst(100, 500));
|
|
291
|
+
print(nanLoop(30));
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
Same two RUN lines; CHECK the compile-status lines for all four
|
|
295
|
+
functions plus the outputs (values from the interpreter run).
|
|
296
|
+
|
|
297
|
+
- [ ] **Step 5: Gates + prove-can-fail**
|
|
298
|
+
|
|
299
|
+
Full x86 `check-hermes` + ASan. Prove-can-fail: invert the swapOperands
|
|
300
|
+
flag on `less` only; loops.js and cmp.js must both fail; revert,
|
|
301
|
+
re-verify. (This specifically proves the swap mapping is load-bearing.)
|
|
302
|
+
|
|
303
|
+
- [ ] **Step 6: Commit** (message pattern as Task 1: "JIT: x86-64
|
|
304
|
+
comparisons and branches", body noting the swapped-compare mapping and
|
|
305
|
+
that loops now stay in compiled code.)
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
309
|
+
### Task 3: Bit operations and int conversions
|
|
310
|
+
|
|
311
|
+
**Files:**
|
|
312
|
+
- Modify: `lib/VM/JIT/x86-64/JitEmitter-arith.cpp` (bitBinOp, bitNot,
|
|
313
|
+
toInt32), `JitEmitter.h`, `JitEmitter-stubs.cpp`,
|
|
314
|
+
`JitEmitter-internal.h` (`emit_double_is_int`-family helpers)
|
|
315
|
+
- Create: `test/jit/x86-64/bitops.js`
|
|
316
|
+
|
|
317
|
+
**Interfaces:**
|
|
318
|
+
- Consumes: Tasks 1-2.
|
|
319
|
+
- Produces: BitAnd/BitOr/BitXor/LShift/RShift/URshift, BitNot,
|
|
320
|
+
ToInt32/ToUint32.
|
|
321
|
+
|
|
322
|
+
Port sources: `arm64/JitEmitter-arith.cpp:118-179` (toInt32), `:324-378`
|
|
323
|
+
(bitNot), `:603-697` (bitBinOp), plus `emit_double_is_int` /
|
|
324
|
+
`emit_double_is_uint32` from `arm64/JitEmitter-internal.h`. Translation
|
|
325
|
+
notes: `fcvtzs`/round-trip-compare idiom → `vcvttsd2si` +
|
|
326
|
+
`vcvtsi2sd` + `vucomisd` + `jne`/`jp` (INT64_MIN sentinel from
|
|
327
|
+
`vcvttsd2si` overflow makes the round-trip fail, same as arm64's
|
|
328
|
+
saturation — verify against the arm64 comments); shifts: x86 variable
|
|
329
|
+
shifts take the count in `cl` — the count operand must be allocated into
|
|
330
|
+
rcx or moved there (rcx is temp id 1; use `getOrAllocFRInGpX` with a
|
|
331
|
+
specific-register hint the way arm64 hints `HWReg::gpX(0)` for results,
|
|
332
|
+
`// x86-64:` comment); `and/orr/eor/lsl/lsr/asr` → `and/or/xor/shl/shr/
|
|
333
|
+
sar` (two-operand: copy-then-operate; dst==src2 aliasing rule from the
|
|
334
|
+
plan's emit3op discipline — if a shared helper is worth it, add
|
|
335
|
+
`emit3op` to `-internal.h`, else keep it per-site and consistent).
|
|
336
|
+
|
|
337
|
+
- [ ] **Step 1: Port helpers + toInt32; build**
|
|
338
|
+
- [ ] **Step 2: Port bitBinOp + bitNot; build**
|
|
339
|
+
- [ ] **Step 3: Test**
|
|
340
|
+
|
|
341
|
+
`test/jit/x86-64/bitops.js`, two-RUN differential pattern, covering:
|
|
342
|
+
`&|^` on int and double operands, all three shifts with counts 0/1/31/32/
|
|
343
|
+
33/-1, `>>> 0` on negative values, `~` on ±0/NaN/2^31, `(2147483647|0)+1`,
|
|
344
|
+
`-2147483648>>1`, int32-boundary doubles (2^31, 2^31-0.5, -2^31-1,
|
|
345
|
+
2^32), and non-number slow paths (`"8"|0`, `true<<1`).
|
|
346
|
+
|
|
347
|
+
- [ ] **Step 4: Gates + prove-can-fail** (break URshift's unsigned-ness —
|
|
348
|
+
use `sar` in place of `shr` — bitops.js must fail; revert, re-verify.)
|
|
349
|
+
- [ ] **Step 5: Commit** ("JIT: x86-64 bit operations and int conversions")
|
|
350
|
+
|
|
351
|
+
---
|
|
352
|
+
|
|
353
|
+
### Task 4: Type asserts
|
|
354
|
+
|
|
355
|
+
**Files:**
|
|
356
|
+
- Modify: `lib/VM/JIT/x86-64/JitEmitter.cpp` (the machinery),
|
|
357
|
+
`JitEmitter.h` (replace the no-op placeholder; TypeAssertSite decls),
|
|
358
|
+
`JitEmitter-internal.cpp` (the `_jit_type_assert_failed` handler and
|
|
359
|
+
`typePredName`, matching wherever arm64 defines them — check
|
|
360
|
+
`grep -rn "_jit_type_assert_failed" lib/VM/JIT/arm64/`),
|
|
361
|
+
remove `enter()`'s `unsupported("type asserts")` decline
|
|
362
|
+
- Create: `test/jit/x86-64/type-asserts.js`
|
|
363
|
+
|
|
364
|
+
**Interfaces:**
|
|
365
|
+
- Consumes: every `emitTypeAssert` call site already ported verbatim in
|
|
366
|
+
Tasks 1-3 (they were kept because arm64 has them).
|
|
367
|
+
- Produces: working `-Xjit-emit-type-asserts` on x86-64.
|
|
368
|
+
|
|
369
|
+
Port sources: `arm64/JitEmitter.cpp:1012-1156` (emitTypeAssert,
|
|
370
|
+
emitTypeAssertFR, emitPendingTypeAssertsSlow, emitTypeAssertGpX,
|
|
371
|
+
readFRForAssert, emitTypeAssertFailTail) and the arm64 definitions of
|
|
372
|
+
the handler/name table. The check sequences translate with the same tag
|
|
373
|
+
idioms as Task 1's helpers; the assert paths may use r11 freely (that
|
|
374
|
+
is exactly its role — instrumentation that must not disturb allocator
|
|
375
|
+
state). `readFRForAssert`'s read-priority order (local → global iff
|
|
376
|
+
up-to-date → frame, assert `!regIsDirty`) is load-bearing; port
|
|
377
|
+
verbatim.
|
|
378
|
+
|
|
379
|
+
- [ ] **Step 1: Port the machinery; replace the placeholder; remove the
|
|
380
|
+
enter() decline; build**
|
|
381
|
+
- [ ] **Step 2: Test**
|
|
382
|
+
|
|
383
|
+
`test/jit/x86-64/type-asserts.js` modeled on arm64's
|
|
384
|
+
`test/jit/type-asserts.js` (read it first) but restricted to opcodes
|
|
385
|
+
x86-64 compiles today; RUN lines add `-Xjit-emit-type-asserts` to the
|
|
386
|
+
differential pattern (outputs must be identical with the flag on).
|
|
387
|
+
Also update `test/jit/x86-64/loops.js` and `arith.js`: add a third RUN
|
|
388
|
+
line with `-Xjit-emit-type-asserts` to each (same diff-vs-interpreter
|
|
389
|
+
form), so the asserts run continuously from now on.
|
|
390
|
+
|
|
391
|
+
- [ ] **Step 3: Prove the asserts can fire**
|
|
392
|
+
|
|
393
|
+
Temporarily mis-declare a type at one site (e.g., make `arithBinOp`'s
|
|
394
|
+
result `frUpdatedWithHW(..., FRType::Bool)` in the double fast path),
|
|
395
|
+
rebuild, run loops.js's assert RUN line: the type assert must trap with
|
|
396
|
+
the site diagnostics (function, offset, FR, predicate). Revert, rebuild,
|
|
397
|
+
re-verify. Record the observed trap message in the report.
|
|
398
|
+
|
|
399
|
+
- [ ] **Step 4: Gates** — full x86 check-hermes + ASan; doc/JIT.md
|
|
400
|
+
sentence from milestone 1 about the type-asserts decline is now stale:
|
|
401
|
+
update that one sentence (this is the only shared-tree file touched;
|
|
402
|
+
it is a doc, no arm64 comparison needed).
|
|
403
|
+
- [ ] **Step 5: Commit** ("JIT: x86-64 type asserts")
|
|
404
|
+
|
|
405
|
+
---
|
|
406
|
+
|
|
407
|
+
### Task 5: Docs and the arm64 cross-check
|
|
408
|
+
|
|
409
|
+
**Files:**
|
|
410
|
+
- Modify: `doc/JIT.md` (x86-64 status paragraph: opcode coverage now;
|
|
411
|
+
loops compile; type asserts working)
|
|
412
|
+
- No code.
|
|
413
|
+
|
|
414
|
+
- [ ] **Step 1: Update the status paragraph** (keep under 25 lines total).
|
|
415
|
+
- [ ] **Step 2: Whole-milestone insurance run on arm64** — even though no
|
|
416
|
+
shared code should have changed, verify:
|
|
417
|
+
|
|
418
|
+
```bash
|
|
419
|
+
cmake --build /home/tmikov/work/hermes-x86-jit/cmake-build-arm64 --target hermes -j "$(nproc)"
|
|
420
|
+
QEMU_LD_PREFIX=/usr/aarch64-linux-gnu \
|
|
421
|
+
/home/tmikov/work/hermes-x86-jit/utils/jit/jit-dump.sh -q \
|
|
422
|
+
-o /home/tmikov/work/hermes-x86-jit/cmake-build-arm64/jit-m2.dump \
|
|
423
|
+
/home/tmikov/work/hermes-x86-jit/cmake-build-arm64/bin/hermes
|
|
424
|
+
/home/tmikov/work/hermes-x86-jit/utils/jit/jit-diff.sh --dumps \
|
|
425
|
+
/home/tmikov/work/hermes-x86-jit/cmake-build-arm64/jit-baseline.dump \
|
|
426
|
+
/home/tmikov/work/hermes-x86-jit/cmake-build-arm64/jit-m2.dump
|
|
427
|
+
LIT_FILTER="jit/" cmake --build /home/tmikov/work/hermes-x86-jit/cmake-build-arm64 --target check-hermes -j "$(nproc)"
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
Expected: identical; 46 passes + N unsupported (N = 2 + the new x86-64
|
|
431
|
+
tests added this milestone).
|
|
432
|
+
|
|
433
|
+
- [ ] **Step 3: Commit** ("doc: x86-64 JIT milestone-2 status")
|
|
434
|
+
|
|
435
|
+
---
|
|
436
|
+
|
|
437
|
+
## Out of scope
|
|
438
|
+
|
|
439
|
+
AddS/AddEmptyString/TypeOf/typeOfIs (string/object milestones), switches,
|
|
440
|
+
throws/try (EH milestone), calls (milestone 3), property access
|
|
441
|
+
(milestone 4), HV32/BOXED build matrix (arrives with the GC-facing
|
|
442
|
+
milestone), x86-64 emitted-code goldens (milestone 6). The
|
|
443
|
+
`loadConstDouble` vector-materialization TODO stays a TODO unless Task 1
|
|
444
|
+
finds it forced; revisit with performance work.
|