okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-022-needsfmt: needs-format issue fixes (#3418, #3417, #3358 tests/build)5a9b4f4fc

main
3.3 KiB66 linesraw
1"""Tests for tools/check_isa_guard.py's policy (#795): which functions may hold wider-ISA instructions.  No binary, no GPU.
2
3    python -m unittest tools.test_check_isa_guard
4"""
5from __future__ import annotations
6
7import sys
8import unittest
9from pathlib import Path
10
11sys.path.insert(0, str(Path(__file__).resolve().parent))
12import check_isa_guard as G  # noqa: E402
13
14
15class WideInstruction(unittest.TestCase):
16    def test_evex_prefix_is_wide(self):
17        self.assertTrue(G.is_wide(0x62, "vmovups", "zmm0, zmmword ptr [rcx]"))
18        self.assertTrue(G.is_wide(0x62, "vpmullq", "xmm0, xmm0, xmm6"))      # EVEX with xmm0-15 operands only
19
20    def test_vex_avx2_is_not(self):
21        self.assertFalse(G.is_wide(0xC4, "vpinsrd", "xmm1, xmm1, dword ptr [r13 + r9*4 + 0x405fc0], 3"))
22        self.assertFalse(G.is_wide(0xC5, "vmovdqu", "ymm0, ymmword ptr [r14]"))
23
24    def test_avx_vnni_and_registers_above_15(self):
25        self.assertTrue(G.is_wide(0xC4, "vpdpbusd", "ymm0, ymm1, ymm2"))
26        self.assertTrue(G.is_wide(0xC5, "vpxor", "ymm17, ymm17, ymm17"))
27        self.assertTrue(G.is_wide(0xC5, "kmovb", "k1, eax"))
28
29
30class Policy(unittest.TestCase):
31    def test_kernel_in_an_anonymous_namespace_of_a_wide_file_is_fine(self):
32        self.assertIsNone(G.judge("??$gu_rows@$0BA@$00@?A0xa1d599f5@cpu@kernels@strata@@YAXXZ",
33                                  "strata_kernels_cpu:iq_avx512.cpp.obj", "", False, False, False))
34        self.assertIsNone(G.judge("strata::kernels::cpu::(anonymous namespace)::gu_rows<18, 1>(int)", None, "", False,
35                                  False, True))
36
37    def test_trellis_rows_entry_point_is_fine(self):
38        """#3358: tq_avx512.cpp's rows function is behind cpu_avx512_ok() like the other wide kernels."""
39        name = "strata::kernels::cpu::tq_detail::tq_rows_avx512(int, unsigned char const*, unsigned long, int)"
40        self.assertIsNone(G.judge(name, "tq_avx512.cpp.o", "", False, False, True))
41        self.assertIsNotNone(G.judge(name, "tq_cpu.cpp.o", "", False, False, True))      # the same code elsewhere is not
42
43    def test_listed_public_entry_point_is_fine(self):
44        self.assertIsNone(G.judge("?act_quant_q8_1@cpu@kernels@strata@@YAXPEBMHAEAUActQ@123@@Z",
45                                  "strata_kernels_cpu:expert.cpp.obj", "", False, False, False))
46
47    def test_the_probe_must_not_be_wide(self):
48        self.assertIsNotNone(G.judge("?cpu_features@cpu@kernels@strata@@YA?AUCpuFeatures@123@XZ",
49                                     "strata_kernels_cpu:expert.cpp.obj", "", False, False, False))
50        self.assertIsNotNone(G.judge("strata::kernels::cpu::cpu_features()", None, "", False, False, True))
51        self.assertIsNotNone(G.judge("strata::kernels::cpu::iq512_supported(int)", None, "", False, False, True))
52
53    def test_weak_symbol_is_a_violation_even_in_a_wide_file(self):
54        why = G.judge("std::vector<float, std::allocator<float> >::_M_realloc_insert(float const&)", None, "", False,
55                      True, True)
56        self.assertIn("weak", why)
57
58    def test_wide_code_in_another_object_is_a_violation(self):
59        self.assertIsNotNone(G.judge("?f@@YAXXZ", "strata_kernels_cpu:pool.cpp.obj", "", False, False, False))
60
61    def test_msvc_vectorizer_guard_is_accepted(self):
62        self.assertIsNone(G.judge("?bench@@YAHXZ", "iq_avx2_parity.cpp.obj", "", True, False, False))
63
64
65if __name__ == "__main__":
66    unittest.main()