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