shader: add s_add_i32 and s_sub_i32 with signed-overflow SCC

#185 left both forms unsupported because the pinned XML says only
"carry-out" for them. The AMD RDNA 2 ISA reference guide (GPUOpen,
section 12.1 SOP2 Instructions, p. 101-102, and section 5.3 Scalar
Condition Code, p. 33) defines SCC for both as signed overflow:
add overflows when the operands share a sign that the result lacks;
subtract when the operands' signs differ and the result's sign differs
from S0's. The guide also confirms the unsigned rules used in #185.

Adds both forms to the generated opcodes, the decoder, the reference
(exact signed result must fit in i32), the independent interpreter (the
guide's sign-bit rule over its ripple adder) and the translator, plus
400 boundary programs, eight hand-worked overflow and no-overflow cases
(-1 + 1 and 0 - 1 carry or borrow but do not overflow) and two signed
overflows in the scalar ALU fixture. Inverting the overflow rule in any
one implementation fails three tests. s_min_i32 and the other SOP2
forms stay unsupported.

Refs #185

Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
This commit is contained in:
elforeign committed 2026-11-24 01:48:52 -06:00
1 parent 1212280ab8
commit 425327a0f2
18 files changed
+248 -63

No files matched your search

+8 -6
View File
@@ -1,7 +1,9 @@
0000: t0 = load.u32 input[index]
0034: branch.uniform 0x0040 taken=true
0040: t2 = const.u32 0x7ffffffe
0044: t3 = const.u32 0xfffffff0
0048: t4 = xor.b32 t2, t3
004c: t5 = xor.b32 t0, t4
0050: store.u32 output[index], t5
003c: branch.uniform 0x0048 taken=true
0048: t2 = const.u32 0x7ffffffe
004c: t3 = const.u32 0xfffffff0
0050: t4 = xor.b32 t2, t3
0054: t5 = const.u32 0x80000000
0058: t6 = xor.b32 t4, t5
005c: t7 = xor.b32 t0, t6
0060: store.u32 output[index], t7
+4 -2
View File
@@ -8,6 +8,8 @@ kernel void xenora_compute(
uint t2 = 0x7ffffffeu;
uint t3 = 0xfffffff0u;
uint t4 = t2 ^ t3;
uint t5 = t0 ^ t4;
output[index] = t5;
uint t5 = 0x80000000u;
uint t6 = t4 ^ t5;
uint t7 = t0 ^ t6;
output[index] = t7;
}
Binary file not shown.
+6 -1
View File
@@ -1,7 +1,8 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Original SOP2 vectors: a carry chain through s_add_u32/s_addc_u32, a borrow
// chain through s_sub_u32/s_subb_u32, bitwise results feeding SCC, an SCC
// branch, and SGPR results moved into VGPRs. Expected: input ^ 0x8000000e.
// branch, signed overflow, and SGPR results moved into VGPRs.
// Expected: input ^ 0x0000000e.
.text
buffer_load_dword v1, v0, s[0:3], 0 idxen
s_waitcnt vmcnt(0)
@@ -13,6 +14,8 @@ s_subb_u32 s11, s9, s8 // s11 = 0x7ffffffe, SCC = 0
s_xor_b32 s12, s11, s10 // s12 = 0x80000001, SCC = 1
s_and_b32 s13, s12, s9 // s13 = 0x80000000, SCC = 1
s_or_b32 s14, s13, -16 // s14 = 0xfffffff0, SCC = 1
s_add_i32 s16, s9, -1 // s16 = 0x7fffffff, SCC = 1 (signed overflow)
s_sub_i32 s17, s16, -1 // s17 = 0x80000000, SCC = 1 (signed overflow)
s_and_b32 s15, s14, 15 // s15 = 0, SCC = 0
s_cbranch_scc0 .Lzero
v_mov_b32_e32 v2, 0
@@ -21,6 +24,8 @@ s_branch .Ldone
v_mov_b32_e32 v2, s11
v_mov_b32_e32 v3, s14
v_xor_b32_e32 v2, v2, v3
v_mov_b32_e32 v4, s17
v_xor_b32_e32 v2, v2, v4
v_xor_b32_e32 v2, v1, v2
.Ldone:
buffer_store_dword v2, v0, s[4:7], 0 idxen