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
43 changes: 43 additions & 0 deletions docs/experiments/native-direct-salu-cmp64.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# 64-bit scalar SOPC comparisons in the direct C++ compute path

Issue #3078 (part of #2935) lowers the remaining 64-bit SOPC scalar comparison
and bit-test instructions in the direct C++ compute DXIL path
(`src/gfx1013_direct_compute.inl`): `s_cmp_eq_u64`, `s_cmp_lg_u64`,
`s_bitcmp0_b64`, and `s_bitcmp1_b64`.

All four instructions write `SCC` only and leave scalar registers untouched.
`s_cmp_eq_u64` and `s_cmp_lg_u64` accept aligned even SGPR pairs, `null` (`0`),
sign-extended negative inline integers (`-1..-16`), and zero-extended positive
inline integers (`0..64`) or 32-bit literals (`0x80000001` -> `(0x80000001, 0)`),
while refusing `vcc`, `exec`, `m0`, `scc`, floats, and odd SGPRs.
`s_bitcmp0_b64` and `s_bitcmp1_b64` test bit `S1 & 63` of the 64-bit `S0` operand
using pure 32-bit DXIL operations (no `Int64Ops` shader feature bit required).

## Verification

`native_salu_cmp64_ir` dumps DXIL IR via `native_compute_ir_dump` for all 22
test cases, asserts pure 32-bit IR (no 64-bit integer IR ops), evaluates lane 0
to verify both the preserved SGPR pair (`s[22:23]`) and exact `SCC` output
(pinning compare operands, sign/zero-extension rules, and bit-5 high-word
selection), and verifies all 7 negative operand refusal controls.
`native_salu_cmp64_controls` compiles all 22 test cases together with
`compile_dxil`, checks `dxc.exe -dumpbin` for pure 32-bit IR (`icmp eq i32`,
`icmp ne i32`, `lshr i32`) with no 64-bit integer IR ops, checks 7 negative
operand refusal controls, and checks 6 oracle mutants (`low_word_only_cmp`,
`high_word_only_cmp`, `zero_ext_neg_inline`, `sign_ext_lit`,
`ignore_bit5_bitcmp`, `inverted_bitcmp`). `native_salu_cmp64_hardware` runs
`native_store_replay --direct` and returns skip code 77 when shader model 6.6
wave32 hardware is unavailable.

```powershell
cmake --build --preset dev --target compile_dxil native_store_replay native_compute_ir_dump
ctest --preset dev --no-tests=error -R '^native_salu_cmp64_' -V
ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' --output-on-failure
```

Results (Windows `10.0.26100`, `dev` preset, base `88cddb09`):
- `native_salu_cmp64_ir`: Passed (`0.98s`) — evaluated DXIL IR for all 22 cases in pure 32-bit IR (`s[22:23]` preserved + exact `SCC`), verified 7 operand refusals, and caught 6 oracle mutants. Five deliberate broken lowerings (`low_word_only_cmp`, `high_word_only_cmp`, `swap_and_or`, `ignore_bit5`, `invert_bitcmp`) each failed `native_salu_cmp64_ir` (`exit 1`).
- `native_salu_cmp64_controls`: Passed (`1.14s`) — compiled all 22 cases together in pure 32-bit DXIL IR (`6.77 ms` cold DXIL compile, `6948` bytes), passed 7 negative operand refusal checks, and caught all 6 SCC oracle mutants.
- `native_salu_cmp64_hardware`: Skipped (exit code `77`, `requires shader model 6.6 with wave32`) on local NVIDIA Quadro M1000M (SM 6.1); GPU readback is unmeasured locally.
- `ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' --output-on-failure`: `47/47` passed (`51.67s`).
- `tests/docs_links_check.py`: `102` Markdown files, `589` links passed.
30 changes: 30 additions & 0 deletions src/gfx1013_direct_compute.inl
Original file line number Diff line number Diff line change
Expand Up @@ -2145,6 +2145,36 @@ struct DirectCompute {
refuse(i.pc, "a GPU-selected heap slot stride read is not translated with a view contract");
}
}
if (compute && (n == "s_cmp_eq_u64" || n == "s_cmp_lg_u64" || n == "s_bitcmp0_b64" || n == "s_bitcmp1_b64")) {
// Issue #3078: lower 64-bit SOPC scalar comparisons to pure 32-bit DXIL writes of SCC.
auto scalar64 = [&](unsigned src) -> std::pair<string, string> {
if (src == 125)
return {"0", "0"};
if (src == 106 || src == 126)
refuse(i.pc, "invalid " + string(n) + " source");
return {operand32(i, src), pair_high(i, src)};
};
auto [a_lo, a_hi] = scalar64(i.src[0]);
string cond;
if (n == "s_cmp_eq_u64" || n == "s_cmp_lg_u64") {
auto [b_lo, b_hi] = scalar64(i.src[1]);
const bool eq = n == "s_cmp_eq_u64";
const auto op = eq ? "eq" : "ne";
const auto combine = eq ? "and" : "or";
cond = ir.value(string(combine) + " i1 " + cmp(op, a_lo, b_lo) + ", " + cmp(op, a_hi, b_hi));
} else {
const unsigned index_src = i.src[1];
if (!(index_src <= 105 || (index_src >= 128 && index_src <= 208) || index_src == 255))
refuse(i.pc, "invalid " + string(n) + " bit index");
auto idx = operand32(i, index_src);
auto upper = cmp("ne", ir.binary("and", idx, "32"), "0");
auto word = select(upper, a_hi, a_lo);
auto bit = ir.binary("and", shift("lshr", word, idx), "1");
cond = cmp(n == "s_bitcmp0_b64" ? "eq" : "ne", bit, "0");
}
write(128, ir.value("zext i1 " + cond + " to i32"));
return;
}
if (compute && n == "s_bfm_b64") {
if ((i.dst & 1) || i.dst > 104)
refuse(i.pc, "invalid s_bfm_b64 destination");
Expand Down
17 changes: 17 additions & 0 deletions tests/cmake/native_salu_cmp64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
if(TARGET native_compute_ir_dump AND EXISTS "${INTAKE_PYTHON}")
add_test(NAME native_salu_cmp64_ir COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/native_salu_cmp64_check.py" ir
"$<TARGET_FILE:native_compute_ir_dump>")
set_tests_properties(native_salu_cmp64_ir PROPERTIES TIMEOUT 60)
endif()
if(TARGET compile_dxil AND TARGET native_store_replay AND
EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${DXC_BIN_DIR}/dxil.dll")
add_test(NAME native_salu_cmp64_controls COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_SOURCE_DIR}/tests/native_salu_cmp64_check.py" controls
"$<TARGET_FILE:compile_dxil>" "${DXC_BIN_DIR}")
set_tests_properties(native_salu_cmp64_controls PROPERTIES TIMEOUT 60)
add_test(NAME native_salu_cmp64_hardware COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_SOURCE_DIR}/tests/native_salu_cmp64_check.py" hardware
"$<TARGET_FILE:native_store_replay>" "${DXC_BIN_DIR}")
set_tests_properties(native_salu_cmp64_hardware PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 60)
endif()
Loading
Loading