Files
mandy/tests/semantic/test_vsharp_sext48.py
c4k3ss 3b1556e00d tests: five newer main tests taught the pair form of lower_addr64
The mesh-compute module stores, the chained scalar constant fold, the LDS
d16 negative controls, the V# 48-bit sign extension and the wave32 lane
select negative control all looked for the 64-bit idiom (OpConvertUToPtr,
OpIMul %ulong, the %ulong shift pair) or for the first constant 16 or 31
in the module, which lower_addr64 now declares as its own. Each accepts
both forms; the counts and the negative controls are unchanged.
2026-11-28 14:48:45 +02:00

49 lines
2.0 KiB
Python

"""Imported buffer V#s carry a signed 48-bit offset from the Vulkan heap base."""
from pathlib import Path
import re
import unittest
import support
class VSharpSignExtensionTest(unittest.TestCase):
def test_negative_base_and_carry_out_of_bit_47(self):
name = "ps_vsharp_sext48"
fixture = Path(support.HERE) / "fixtures" / f"{name}.asm"
spv = support.translate_listing(name, fixture.read_bytes())
# Both effective VAs must be sign-extended by shifting 16 bits in each direction before rebasing: two
# 64-bit shifts with --int64-addresses, or, lowered to (low, high) pairs by lower_addr64, the high
# word's arithmetic shift right by 16 (the left shift by 16 spreads over both words).
shifts = re.findall(r"^(%\w+) = OpConstant %uint 16$", spv, re.M)
self.assertTrue(shifts)
extended = []
for shift in shifts:
extended += re.findall(
rf"(%\w+) = OpShiftLeftLogical %ulong %\w+ {shift}\s+"
rf"(%\w+) = OpShiftRightArithmetic %ulong \1 {shift}\s+"
r"%\w+ = OpIAdd %ulong %heap_base \2\b",
spv,
)
if "%ulong" not in spv:
extended = [m for shift in shifts
for m in re.findall(rf"^\s*%\w+ = OpShiftRightArithmetic %int %\w+ {shift}$", spv, re.M)]
self.assertEqual(len(extended), 2)
# The second base+offset sum carries out of the low 48 bits and lands on the heap base itself.
heap = 0x100002000
below, at_base = 0x12345678, 0x9abcdef0
words = support.mrt0_words(
spv, push_constants=[0] * 32 + [heap & 0xffffffff, heap >> 32],
memory={heap - 48: below, heap: at_base},
)
self.assertEqual(words, [below, at_base, below, at_base])
translator = support.rdna2spirv
metadata = translator.shader_meta(translator.translate.last_gen, spv)
self.assertIs(metadata.get("vsharp_base_sign_extended"), True)
if __name__ == "__main__":
unittest.main()