Files
mandy/tests/semantic/test_float_to_int.py
AlxcBTW 14887e6828 Translator: honour V# OOB_SELECT in MUBUF/MTBUF bounds checks
buffer_address() picked the bounds check from the stride alone and never read
word3. It now reads OOB_SELECT (bits 29:28) and applies the rule measured
natively on RDNA2 (gfx1036, docs/buffer_bounds.md; Mesa's GFX11 column): a
dword is out of range in mode 0 at idx >= NR or off + 4 > stride, mode 1 at
idx >= NR, mode 2 at NR == 0, mode 3 (RAW) at offs + 4 > NR, where off is
inst_offset + vaddr and offs adds soffset. A literal word3 folds the mode, a
run-time one selects with OpSelect.

Builds on the raw tail rule of #443 (per-dword loads): x2..x4 loads AND stores
are per dword in modes 0 and 3 (a store that straddled the edge used to write
past it), modes 1 and 2 take the whole access, a typed element
(buffer_load/store_format) is all or nothing at its format's size, an atomic
checks its dword's end. Measured on a Radeon 880M (gfx1150), a valid proxy for
RDNA2: 504 buffer_load_dword cases over idxen/offen/inst_offset/soffset at the
stride and record edges agree with the rules, plus the x2/x4, typed and atomic
edges.

Swizzle (V# word1 bit 31 SWIZZLE_ENABLE, word3 bit 23 ADD_TID_ENABLE; Mesa
gfx10-rsrc.json lines 326 and 337): a literal V# with either is Unsupported in
every mode; a run-time one is translated unswizzled (documented known gap).

A V# with word3 = 0 is mode 0 / stride 0 and so always out of range, as on
hardware: the harness output V# (vk_compute_test, interpreter push constants),
cs_bounds, cs_fmt_1010102, cs_store, mem_diff and the format tests now say
OOB_SELECT 3 (or 1 with a stride) explicitly.

Tests: tests/semantic/test_buffer_oob_select.py (33 hand-tabulated cases plus
multi-dword stores, typed elements and the swizzle gate, literal and run-time
V#), GPU tests cs_oob_select.asm and cs_oob_tail.asm (the second tells the end
check from Mesa's GFX10 start check). docs/design.md, Buffer bounds checking,
has the per-mode rule; docs/buffer_bounds.md notes the translator reads it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 07:40:20 +01:00

45 lines
1.9 KiB
Python

"""VOP1 conversions with known binary32 inputs and integer output words."""
import struct
import unittest
import support
# Input bits, unsigned result, signed result (as an untyped 32-bit word).
CASES = (
(0x00000000, 0, 0), # +0
(0x80000000, 0, 0), # -0
(0x00000001, 0, 0), # subnormal
(0x3FC00000, 1, 1), # +1.5
(0xBFC00000, 0, 0xFFFFFFFF), # -1.5
(0x4EFFFFFF, 0x7FFFFF80, 0x7FFFFF80), # largest binary32 below +2^31
(0x4F000000, 0x80000000, 0x7FFFFFFF), # +2^31
(0x4F7FFFFF, 0xFFFFFF00, 0x7FFFFFFF), # largest binary32 below +2^32
(0x4F800000, 0xFFFFFFFF, 0x7FFFFFFF), # +2^32
(0xCEFFFFFF, 0, 0x80000080), # -(2^31 - 128)
(0xCF000000, 0, 0x80000000), # -2^31
(0xCF000001, 0, 0x80000000), # next binary32 below -2^31
(0x7F800000, 0xFFFFFFFF, 0x7FFFFFFF), # +infinity
(0xFF800000, 0, 0x80000000), # -infinity
(0x7F800001, 0, 0), # first positive NaN encoding
(0xFFC00000, 0, 0), # negative quiet NaN
)
class FloatToIntTest(unittest.TestCase):
def test_saturating_conversions(self):
# Five user SGPRs, with s4 carrying the input after the output V#.
fssm = bytes(0x138) + struct.pack("<4I", 0x808A, 1, 1, 1)
spv = support.translate_fixture("cs_cvt_f32_sat", fssm=fssm)
for bits, unsigned, signed in CASES:
with self.subTest(bits=f"{bits:08x}"):
memory = {}
support.run_fragment(
spv, inputs={"%wg_id": (0, 0, 0), "%local_id": (0, 0, 0)},
push_constants=[0, 0, 8, 0x31016FAC, bits] + [0] * 27, memory=memory)
self.assertEqual(memory, {0: unsigned, 4: signed})
if __name__ == "__main__":
unittest.main()