Files
UnbiasedStrata/tools/test_check_isa_guard.py
Robert Karl 0197ae86eb Import PolyStrata v0.1.45-poly.1 (d0cd84dc) unmodified
The upstream release tree, every tracked file byte for byte, from
https://github.com/VecSzn/PolyStrata at tag v0.1.45-poly.1, commit
d0cd84dc6bd009d1d9e2191e4e28cc76b80f1ee3. Nothing added, removed or edited;
git diff against this commit is the whole story of the fork.

Verified: the commit's tree hash equals the upstream commit's tree hash.
2026-10-17 19:34:32 -07:00

61 lines
2.9 KiB
Python

"""Tests for tools/check_isa_guard.py's policy (#795): which functions may hold wider-ISA instructions. No binary, no GPU.
python -m unittest tools.test_check_isa_guard
"""
from __future__ import annotations
import sys
import unittest
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
import check_isa_guard as G # noqa: E402
class WideInstruction(unittest.TestCase):
def test_evex_prefix_is_wide(self):
self.assertTrue(G.is_wide(0x62, "vmovups", "zmm0, zmmword ptr [rcx]"))
self.assertTrue(G.is_wide(0x62, "vpmullq", "xmm0, xmm0, xmm6")) # EVEX with xmm0-15 operands only
def test_vex_avx2_is_not(self):
self.assertFalse(G.is_wide(0xC4, "vpinsrd", "xmm1, xmm1, dword ptr [r13 + r9*4 + 0x405fc0], 3"))
self.assertFalse(G.is_wide(0xC5, "vmovdqu", "ymm0, ymmword ptr [r14]"))
def test_avx_vnni_and_registers_above_15(self):
self.assertTrue(G.is_wide(0xC4, "vpdpbusd", "ymm0, ymm1, ymm2"))
self.assertTrue(G.is_wide(0xC5, "vpxor", "ymm17, ymm17, ymm17"))
self.assertTrue(G.is_wide(0xC5, "kmovb", "k1, eax"))
class Policy(unittest.TestCase):
def test_kernel_in_an_anonymous_namespace_of_a_wide_file_is_fine(self):
self.assertIsNone(G.judge("??$gu_rows@$0BA@$00@?A0xa1d599f5@cpu@kernels@strata@@YAXXZ",
"strata_kernels_cpu:iq_avx512.cpp.obj", "", False, False, False))
self.assertIsNone(G.judge("strata::kernels::cpu::(anonymous namespace)::gu_rows<18, 1>(int)", None, "", False,
False, True))
def test_listed_public_entry_point_is_fine(self):
self.assertIsNone(G.judge("?act_quant_q8_1@cpu@kernels@strata@@YAXPEBMHAEAUActQ@123@@Z",
"strata_kernels_cpu:expert.cpp.obj", "", False, False, False))
def test_the_probe_must_not_be_wide(self):
self.assertIsNotNone(G.judge("?cpu_features@cpu@kernels@strata@@YA?AUCpuFeatures@123@XZ",
"strata_kernels_cpu:expert.cpp.obj", "", False, False, False))
self.assertIsNotNone(G.judge("strata::kernels::cpu::cpu_features()", None, "", False, False, True))
self.assertIsNotNone(G.judge("strata::kernels::cpu::iq512_supported(int)", None, "", False, False, True))
def test_weak_symbol_is_a_violation_even_in_a_wide_file(self):
why = G.judge("std::vector<float, std::allocator<float> >::_M_realloc_insert(float const&)", None, "", False,
True, True)
self.assertIn("weak", why)
def test_wide_code_in_another_object_is_a_violation(self):
self.assertIsNotNone(G.judge("?f@@YAXXZ", "strata_kernels_cpu:pool.cpp.obj", "", False, False, False))
def test_msvc_vectorizer_guard_is_accepted(self):
self.assertIsNone(G.judge("?bench@@YAHXZ", "iq_avx2_parity.cpp.obj", "", True, False, False))
if __name__ == "__main__":
unittest.main()