Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,21 @@ if(EXISTS "${INTAKE_PYTHON}")
add_library(cpu_rotates_shifts_lifted SHARED "${rotates_shifts_fixture}")
add_test(NAME cpu_aot_rotates_shifts COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_SOURCE_DIR}/tests/cpu/rotates_shifts.py"
check "$<TARGET_FILE:cpu_rotates_shifts>" "$<TARGET_FILE:cpu_rotates_shifts_lifted>")
cpu_asm_fixture(cpu_string_ops string_ops)
# The lifted DLL and three mutated controls that the check requires to mismatch.
foreach(variant IN ITEMS lifted memmove swapped forward)
set(string_ops_fixture "${CMAKE_CURRENT_BINARY_DIR}/cpu_string_ops_${variant}.cpp")
add_custom_command(OUTPUT "${string_ops_fixture}"
COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_SOURCE_DIR}/tests/cpu/string_ops.py"
emit "$<TARGET_FILE:cpu_string_ops>" "${string_ops_fixture}" ${variant}
DEPENDS cpu_string_ops tests/cpu/string_ops.py tools/ffx_version_query.py
tools/cpu_ranges.py tools/cpu_leaf_aot.py VERBATIM)
add_library(cpu_string_ops_${variant} SHARED "${string_ops_fixture}")
endforeach()
add_test(NAME cpu_aot_string_ops COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_SOURCE_DIR}/tests/cpu/string_ops.py"
check "$<TARGET_FILE:cpu_string_ops>" "$<TARGET_FILE:cpu_string_ops_lifted>"
"$<TARGET_FILE:cpu_string_ops_memmove>" "$<TARGET_FILE:cpu_string_ops_swapped>"
"$<TARGET_FILE:cpu_string_ops_forward>")
cpu_translation(cpu_callback cpu_chained_aot call_context CALLBACK_OFFSET 8)
cpu_asm_fixture(cpu_xlatb xlatb)
# The lifted DLL and three mutated controls that the check requires to mismatch.
Expand Down
2 changes: 2 additions & 0 deletions docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ An immediate SHL, SHR or SAR whose masked count is zero leaves the flags unchang
The shared lowering also handles 32-bit and 64-bit BMI1 bit-manipulation forms (`andn`, `bextr`, `blsi`, `blsmsk`, `blsr`, `tzcnt`), including their zero-extending 32-bit writes and ZF/CF updates. `cpu_aot_bmi1` probes CPUID leaf 7 EBX bit 3 (`BMI1`) before invoking the native fixture and exits 77 (capability skip) on hosts without BMI1; on BMI1-capable hosts it builds all twelve 32-bit and 64-bit exports from MASM source (`tests/cpu/bmi1.asm`), translates them, compares both values and observed ZF/CF flags against the native DLL and an independent reference, and checks that 16-bit `tzcnt` is rejected. Run `cmake --build --preset dev --target cpu_bmi1_lifted` and `ctest --preset dev --no-tests=error -R '^cpu_aot_bmi1$' -V`.
The shared lowering also handles 32-bit and 64-bit rotates and double-precision shifts (`rol`, `ror`, `shld`, `shrd`) with both immediate and `cl` counts, preserving flags on zero masked counts while zero-extending 32-bit destinations. `cpu_aot_rotates_shifts` builds all 12 exports from MASM source (`tests/cpu/rotates_shifts.asm`), translates them, and compares values and ZF/CF flags against the native DLL and a reference model. Run `cmake --build --preset dev --target cpu_rotates_shifts_lifted` and `ctest --preset dev --no-tests=error -R '^cpu_aot_rotates_shifts$' -V`.

The string instructions `movs`, `stos`, `lods`, `scas` and `cmps` lower in byte, word, dword and qword widths, bare or with REP (`movs`, `stos`, `lods`), REPE or REPNE (`scas`, `cmps`), together with `cld` and `std`. The lowering selects them by iced `Code`, because the SSE2 scalar `movsd` and `cmpsd` share their mnemonics. Each iteration moves or compares one element and then steps RSI and RDI by the width, downward when DF is set. Overlapping copies therefore replicate as on the hardware, which a whole-range `memmove` would not. A repeated form tests RCX before each element and ZF after it. A zero count leaves the pointers, memory and flags unchanged. `lodsb` and `lodsw` merge into RAX and `lodsd` zero-extends. `cmps` compares the source element with the destination element and `scas` compares the accumulator with the destination; only ZF and CF are modelled, like the rest of the lowering. DF starts clear in each translated function. The [x64 software conventions](https://learn.microsoft.com/en-us/cpp/build/x64-software-conventions#x64-register-usage) expect DF clear on function exit and on entry to runtime and system calls, so a conforming caller never enters with it set. The 67h forms that walk ESI, EDI and ECX, REPNE on `movs`, `stos` and `lods`, and FS or GS sources are rejected. `cpu_aot_string_ops` builds 62 exports from MASM source (`tests/cpu/string_ops.asm`). In 13 of them the instruction runs with DF set, and one sets DF and clears it again before the instruction. Each export takes its pointers, count, RAX and a flag preset from the caller and reports memory, RAX, RSI, RDI, RCX, ZF and CF. The check runs 39984 cases against the native DLL, the translation and a Python reference. The cases cover overlaps of one byte and of less than an element, zero counts under each flag preset, and REPE and REPNE exits on the first element, on a later one and at count exhaustion, with both CF results. Three mutated translations must each mismatch: a `memmove` for REP `movs`, swapped `cmps` operands, and STD ignored. A 1 KiB guard on each side of the buffer is compared too. Run `ctest --preset dev --no-tests=error -R '^cpu_aot_string_ops$' -V`.

## Recompiling a direct x64 call

The [caller and callee](../tests/cpu/direct.asm) each accept two unsigned 64-bit integers and an output pointer. The [translator](../tools/cpu_call_aot.py) starts at the caller export, follows the signed displacement in its E8 call and reads the target's runtime-function interval. It generates two C++ functions from the linked machine code. MSVC emits a separate x64 DLL with a non-inlined call. The Windows test checks the relative call against the two export addresses in both the input and output DLLs.
Expand Down
Loading