diff --git a/tests/semantic/test_shader_ir_lit_neg.py b/tests/semantic/test_shader_ir_lit_neg.py new file mode 100644 index 000000000..1532b9a89 --- /dev/null +++ b/tests/semantic/test_shader_ir_lit_neg.py @@ -0,0 +1,85 @@ +"""Semantic end-to-end tests for negative LLVM 23 lit(-V) operands in shader_ir + rdna2spirv. + +Verifies that lit(-1) and lit(-0x10) keep their negative integer value (0xFFFFFFFF / 0xFFFFFFF0) +rather than being rewritten to VOP3 neg(1) / neg(0x10) (sign-bit flip 0x80000001 / 0x80000010), +while -lit(...) still applies VOP3 FP negation. +""" +from __future__ import annotations + +import gc +import os +import struct +import sys +import tempfile +import unittest +import warnings + +HERE = os.path.dirname(os.path.abspath(__file__)) +ROOT = os.path.dirname(os.path.dirname(HERE)) +TOOLS_DIR = os.environ.get("LEONIDA_TOOLS_DIR") or os.path.join(ROOT, "tools") + +sys.dont_write_bytecode = True +for _p in (HERE, TOOLS_DIR): + if _p not in sys.path: + sys.path.insert(0, _p) + +import rdna2spirv # noqa: E402 +import spirv_mini_interp as si # noqa: E402 + +STUB_DXBC = b"DXBC" + bytes(24) + struct.pack(" dict[int, int]: + with tempfile.TemporaryDirectory() as tmp: + os.mkdir(os.path.join(tmp, "disasm")) + os.mkdir(os.path.join(tmp, "fssm")) + src = os.path.join(tmp, "disasm", f"cs_{name}.s") + with open(src, "w", encoding="utf-8", newline="\n") as f: + f.write(f"; cs_{name}\n") + for ln in lines: + f.write(f"\t{ln}\n") + with open(os.path.join(tmp, f"cs_{name}.dxbc"), "wb") as f: + f.write(STUB_DXBC) + with open(os.path.join(tmp, "fssm", f"cs_{name}.fssm"), "wb") as f: + hdr = bytearray(0x138) + hdr[0:4] = b"FSSM" + struct.pack_into(" 2 and core.startswith("|") and core.endswith("|")