Skip to content
Closed
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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2320,6 +2320,8 @@ if(EXISTS "${INTAKE_PYTHON}")
"$<TARGET_FILE:offscreen_check>" ${adapter} $<$<BOOL:${STARTUP_FXC}>:${STARTUP_FXC}>)
set_tests_properties(startup_inline_sampler_${adapter} PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77)
endforeach()
add_test(NAME startup_gfx2hlsl_bfm_b64_controls COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_SOURCE_DIR}/tests/startup_gfx2hlsl_bfm_b64_check.py")
add_test(NAME startup_gfx2hlsl_scalar_m0_controls COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_SOURCE_DIR}/tests/startup_gfx2hlsl_scalar_m0_check.py" controls)
foreach(adapter IN ITEMS warp hardware)
Expand Down
89 changes: 89 additions & 0 deletions tests/startup_gfx2hlsl_bfm_b64_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
"""s_bfm_b64 in tools/startup/gfx2hlsl.py (Part of #1723), the 64-bit twin of s_bfm_b32.

usage: startup_gfx2hlsl_bfm_b64_check.py

Pure Python, no GPU. Constant operands fold to two exact 32-bit words; run-time operands emit one block
that reads both sources before writing either destination register; unsupported shapes are refused.
"""
import sys
from pathlib import Path

HERE = Path(__file__).resolve().parent
sys.path.insert(0, str(HERE))
import startup_gfx2hlsl_scalar_m0_check as M # noqa: E402

G = M.G
SOP2_BFM_B64 = 0x25
DST = 20 # s[20:21]
CONST_W, CONST_O = 6, 7


def run(width_sym, offset_sym, *, dst=DST, w=CONST_W, o=CONST_O):
stage = M.ProbeStage()
stage.sym[CONST_W], stage.sym[CONST_O] = ('const', width_sym), ('const', offset_sym)
code = M.encode_sop2(SOP2_BFM_B64, dst, w, o)
_, name, asm, _ = M.D.decode_instruction(code, 0)
assert name == 's_bfm_b64', name
stage.one(name, asm)
return stage


def words(stage):
lo, hi = stage.sym[DST], stage.sym[DST + 1]
assert lo[0] == hi[0] == 'const', (lo, hi)
assert stage.lines == ['s%d = 0x%08xu;' % (DST, lo[1]), 's%d = 0x%08xu;' % (DST + 1, hi[1])], stage.lines
return lo[1], hi[1]


def controls():
# (width, offset) -> (low word, high word), written out by hand from the 64-bit definition.
cases = (
(0, 0, 0x00000000, 0x00000000),
(1, 0, 0x00000001, 0x00000000),
(16, 0, 0x0000ffff, 0x00000000),
(32, 0, 0xffffffff, 0x00000000), # the width the 32-bit op cannot express
(33, 0, 0xffffffff, 0x00000001),
(63, 0, 0xffffffff, 0x7fffffff),
(64, 0, 0x00000000, 0x00000000), # only bits [5:0] count: width 64 is width 0
(1, 63, 0x00000000, 0x80000000),
(4, 30, 0xc0000000, 0x00000003), # the mask crosses the word boundary
(8, 32, 0x00000000, 0x000000ff),
(32, 16, 0xffff0000, 0x0000ffff),
(16, 100, 0x00000000, 0x000ffff0), # offset 100 -> 36: bits 36..51
(1, 64, 0x00000001, 0x00000000), # only bits [5:0] of the offset count: offset 64 is offset 0
)
for width, offset, lo, hi in cases:
got = words(run(width, offset))
assert got == (lo, hi), (width, offset, '%08x %08x' % got)

# A run-time source keeps the mask in run-time code: both sources are read inside one block, so a
# destination that overlaps a source (s[6:7] = bfm(s6, s7)) cannot feed a half-written value back.
stage = M.ProbeStage()
_, name, asm, _ = M.D.decode_instruction(M.encode_sop2(SOP2_BFM_B64, 8, 8, 128 + 2), 0)
stage.one(name, asm)
assert stage.sym.get(8) is None and stage.sym.get(9) is None, stage.sym
block = [line for line in stage.lines if 'shl64' in line]
assert len(block) == 1 and block[0].count('s8 = ') == 1 and block[0].count('s9 = ') == 1, stage.lines
assert block[0].index('ud') < block[0].index('s8 = '), block[0]
assert {8, 9} <= stage.used_s, stage.used_s

# SCC is not touched.
assert not any('scc' in line for line in stage.lines), stage.lines

for dst in (M.M0, 106):
try:
run(1, 1, dst=dst)
except G.Unsupported:
pass
else:
raise AssertionError('destination %d should be refused' % dst)


def main():
controls()
print('startup s_bfm_b64 controls passed')
return 0


if __name__ == '__main__':
sys.exit(main())
33 changes: 33 additions & 0 deletions tools/startup/gfx2hlsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,39 @@ def op_s_bfm_b32(self, ops, mods):
self.set_s(d, '(((1u << (%s & 31)) - 1) << (%s & 31))' % (self.u(ops[1]), self.u(ops[2])))
return None

def op_s_bfm_b64(self, ops, mods):
"""64-bit bitfield mask: D = ((1 << S0[5:0]) - 1) << S1[5:0]; both sources are 32-bit, SCC is untouched."""
Comment on lines +923 to +924

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Document the new startup translation capability

This adds a supported startup-translator instruction without updating README or docs/experiments.md; the existing s_bfm_b64 experiment documents the separate pixel_aot translator. AGENTS.md requires updating the public capability record when support changes. Record the supported/refused operand scope and python3 -B tests/startup_gfx2hlsl_bfm_b64_check.py reproduction command, explicitly distinguishing the Python controls from unverified GPU execution.

AGENTS.md reference: AGENTS.md:L207-L208

Useful? React with 👍 / 👎.

if mods or len(ops) != 3:
raise Unsupported('s_bfm_b64 with %d operands and modifiers %s' % (len(ops), mods))
dst = reg_range(ops[0])
if not dst or dst[0] != 's' or dst[2] != dst[1] + 1 or dst[2] > 105:
raise Unsupported('s_bfm_b64 destination %s' % ops[0])
vals = []
for o in ops[1:3]:
r = reg_range(o)
if r and r[0] == 's':
vals.append(self.is_const(r[1]))
else:
try:
vals.append(int(o, 0))
except ValueError:
vals.append(None)
d = dst[1]
if None not in vals:
value = (((1 << (vals[0] & 63)) - 1) << (vals[1] & 63)) & 0xffffffffffffffff
self.set_s(d, '0x%08xu' % (value & 0xffffffff), ('const', value & 0xffffffff))
self.set_s(d + 1, '0x%08xu' % (value >> 32), ('const', value >> 32))
Comment on lines +943 to +944

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Clear destination lane-mask tags when writing the bitfield

If a destination SGPR previously held a lane mask, this handler overwrites its numeric value without removing its entry from self.masks. For example, the decoded sequence s_mov_b64 s[20:21], exec; s_bfm_b64 s[20:21], 4, 4; s_or_b32 s22, s20, 0 emits the final assignment as (0x000000f0u | 0x00000000u) & 1, producing zero instead of 0xf0 and consequently setting SCC incorrectly. Clear both destination mask tags in the constant and runtime paths so subsequent scalar operations do not truncate the numeric result to one bit.

Useful? React with 👍 / 👎.

return None
# The mask words are built so no 32-bit shift sees a count of 32 or more, then shl64 moves them;
# both sources are read before either destination register is written (D may overlap S0/S1).
width, offset = self.u(ops[1]), self.u(ops[2])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject lane-mask sources used as integer counts

When a source is exec_lo, vcc_lo, or a mask-tagged SGPR, self.u() supplies the per-lane 0/1 projection rather than the wave's 32-bit mask. For example, on an all-active wave, the accepted instruction s_bfm_b64 s[20:21], exec_lo, 0 emits bw = exec & 63u and produces 1, whereas the actual exec_lo is 0xffffffff, giving width 63 and result 0x7fffffffffffffff. Refuse these sources, as the scalar complement handlers do for lane masks, unless their full-wave numeric values can be represented.

Useful? React with 👍 / 👎.

self.emit('{ uint bw = (%s) & 63u; uint2 t = shl64(bw >= 32u ? 0xffffffffu : ((1u << (bw & 31u)) - 1u),'
' bw > 32u ? ((1u << ((bw - 32u) & 31u)) - 1u) : 0u, %s); s%d = t.x; s%d = t.y; }' % (width, offset, d, d + 1))
for r in (d, d + 1):
self.sym.pop(r, None)
self.used_s.add(r)
return None

def op_s_load_dwordx8(self, ops, mods):
self.op_s_load_dwordx4(ops, mods, 8)

Expand Down
Loading