13 Commits
Author SHA1 Message Date
Bartosz Szczepański 149869a053 loader: run LOOP, LOOPE, LOOPNE and JRCXZ (#396)
The four rel8 forms E0 to E3 are declared in the instruction registry and
run through the shared semantics in both engines (Intel SDM Vol. 2A,
LOOP/LOOPcc and Jcc). The count is RCX: LOOP decrements it without
changing a flag and branches while the result is not zero, LOOPE also
needs ZF set and LOOPNE ZF clear, and JRCXZ branches on a zero RCX and
changes nothing. Each ends a translated block. The address-size prefix
stays rejected, so JECXZ and the ECX-counted forms are still refused.

The three known answers recorded as refused by #155 are verified, with
eleven more cases. tests/cpu_loop.rs checks a loop that spans translated
blocks against a step-by-step model for every count, ZF match point and
step budget, and JRCXZ against every single-bit RCX value.

Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>
2026-11-25 00:12:33 +01:00
Bartosz Szczepański 1c6bd25723 loader: run LAHF and SAHF and report them in CPUID (#387)
LAHF (9F) and SAHF (9E) are declared in the instruction registry and run
through the shared semantics in both engines (Intel SDM Vol. 2A LAHF,
Vol. 2B SAHF): LAHF writes AH = SF:ZF:0:AF:0:PF:1:CF and keeps the rest of
RAX, SAHF loads SF, ZF, AF, PF and CF from AH and leaves OF unchanged.
With both implemented, guest CPUID reports leaf 8000_0001h ECX bit 0.

The four known answers recorded as refused by #155 are verified, with
twelve more cases. Both instructions join the clang-assembled integer
fixtures and the independent bit-level reference, and cpu_features.rs
moves LAHF/SAHF from the refused witnesses to the reported features.

Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>
2026-11-24 23:32:17 +01:00
Bartosz Szczepański 0d6cef6c4e loader: raise #GP for instructions longer than 15 bytes (#384)
The shared decoder already stopped before fetching a 16th byte, but it
reported the instruction as unsupported, so both engines exited with an
illegal instruction. It now returns DecodeError::TooLong, which maps to
ExitReason::GeneralProtection (Intel SDM Vol. 3A, 7.15). The DBT retries a
block that fails this way one instruction at a time, as it already does for
illegal instructions and fetch faults, so earlier instructions in the block
complete and the fault reports the overlong instruction's RIP.

The known answer recorded as a defect by #155 is enabled, with three more
cases, and two page-end tests check that no 16th byte is fetched.

Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>
2026-11-24 23:16:49 +01:00
Bartosz Szczepański 53e5e38a4e bench: compare two dbt_bench JSON results (#114)
With XENORA_DBT_BENCH_COMPARE=<baseline.json>,<candidate.json> set,
dbt_bench reads two documents written through XENORA_DBT_BENCH_JSON and
compares them instead of running. For the interpreter and cold and warm
DBT it prints both medians, the change, and whether the change exceeds
the larger recorded IQR, and it lists changed cold DBT counters.

It refuses, with exit status 1 and the differing field named, to compare
runs whose CPU, OS or architecture differ or are unknown, or whose
workload, sample or warmup counts, debug assertions or build label
differ. The new optional XENORA_DBT_BENCH_BUILD_LABEL records build
settings the benchmark cannot observe, such as LTO; version 1 documents
without it count as unlabelled.

The documents are read by a small RFC 8259 reader in the bench file, so
no dependency is added. Unit tests cover the reader, reading back an
exported document, the report lines, and every refusal rule.

Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>
2026-11-24 23:08:04 +01:00
Bartosz Szczepański d2f77cdea3 Merge upstream main into cpu/195-adc-sbb-dbt
Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>
2026-11-24 21:55:01 +01:00
Bartosz Szczepański 061c28b405 bench: export dbt_bench results as JSON (#112)
dbt_bench printed its results only as text. With
XENORA_DBT_BENCH_JSON=<path> set it now also writes one JSON document:
host CPU, OS and architecture, git revision and dirty state, debug
assertions, the workload and sample counts, median, min, max, p95, p99,
IQR and MIPS for the interpreter and cold and warm DBT, and the cold
DBT counters. Values the benchmark cannot determine are null.

The statistics are computed once in a Summary that feeds both the text
line and the JSON, so the two cannot disagree. The text output and the
timed work are unchanged, and no dependency is added.

Unit tests cover string escaping, null handling, the whole document for
fixed inputs and the text line format.

Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>
2026-11-24 21:22:58 +01:00
Bartosz Szczepański 788de1e83b Merge upstream main into cpu/195-adc-sbb-dbt
Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>
2026-11-24 21:08:00 +01:00
Bartosz Szczepański 36c4fbd520 changelog: state the warm DBT cost of fat LTO (#116)
Review re-measurement on Apple M5 showed warm DBT about 2% slower
under fat LTO with one codegen unit in four of four alternating runs.
The entry said it was unchanged.

Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>
2026-11-24 21:02:54 +01:00
Bartosz Szczepański c3b0025977 Merge upstream main into perf/116-release-lto
Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>
2026-11-24 20:44:30 +01:00
Bartosz Szczepański 1013746e17 Merge upstream main into cpu/195-adc-sbb-dbt
Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>
2026-11-24 20:44:24 +01:00
Bartosz Szczepański 3d19c756e2 build: use fat LTO and one codegen unit for release builds (#116)
Release and bench builds used Cargo's defaults: no cross-crate LTO and
16 codegen units. Fat LTO with a single codegen unit lets the
interpreter and DBT hot paths inline across crates.

On Apple M5, dbt_bench medians over five alternating rounds of 101
samples drop from 903 to 845 us for the interpreter (-6%) and from
1.155 to 1.046 ms for cold DBT (-9%, faster in all five rounds); warm
DBT is unchanged. The xenora binary shrinks from 2.73 to 2.11 MB. A
clean release build of the workspace takes 14.0 s instead of 5.9 s.
Debug and test builds keep the dev profile and are unaffected.

Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>
2026-11-24 20:08:43 +01:00
Bartosz Szczepański 710a2e1e73 loader: load ARM64 constants with the fewest wide moves (#92)
load_imm_64 emitted MOVZ for halfword 0 and then MOVK for zero
halfwords it could skip, and never used MOVN, so a small negative
constant took four instructions. It now starts from MOVZ or MOVN,
whichever leaves more halfwords already correct, at the first halfword
that differs, and adds MOVK only for the remaining differing halfwords.

On Apple M5 the DBT benchmark emits 245,168 instead of 290,184 native
bytes for its 626 blocks (-15.5%) and the 1,048 integer fixture
instructions 128,724 instead of 145,732 (-11.7%). Benchmark run times
did not change measurably.

Tests check the sequences against llvm-mc encodings and execute the
edge values plus 512 seeded values, in X0 and X9, on the host through
the JIT, checking both the loaded value and the instruction count.

Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>
2026-11-24 19:31:02 +01:00
Bartosz Szczepański c95e175210 loader: run ADC and SBB register and immediate forms natively in the DBT (#195)
The DBT now lowers the 32- and 64-bit register and immediate forms of
ADC and SBB to ADCS and SBCS instead of calling the shared semantics.
The guest CF is moved into the host carry first, inverted for SBB
because SBCS subtracts NOT C while SBB subtracts CF. Memory forms and
8- and 16-bit forms stay on the shared semantics.

Adds the ADCS and SBCS encodings to the ARM64 assembler, checked
against llvm-mc, and tests/x86_carry_chain.rs: 256-bit add and
subtract chains of 64- and 32-bit limbs, in one block and split one
block per limb, against widening u128/i128 reference arithmetic in
both engines, plus 128-bit immediate increments and decrements and the
sbb reg, reg carry mask.

Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>
2026-11-24 19:12:29 +01:00