Merge pull request #1362: check_isa scans the instructions of a linked .exe or .dll too, not only objects (ShannoonRuaaa)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Valiantsin DzerakhandClaude Opus 5.5 committed 2026-11-22 16:22:08 +03:00
commit 6af609e1b1
3 files changed
+78 -1

No files matched your search

+72
View File
@@ -0,0 +1,72 @@
"""tools/check_isa.py finds instructions above x86-64-v2 in objects and in linked images.
python tests/check_isa_test.py
The disassembly below is llvm-objdump -d --no-show-raw-insn output for one AVX2 function, once from an object (short
indented addresses) and once from a linked .exe (9+ hex digits at the start of the line). Standard library only.
"""
import subprocess
import sys
import unittest
from pathlib import Path
from unittest import mock
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'tools'))
import check_isa # noqa: E402
OBJECT = '''
avx.o:\tfile format coff-x86-64
Disassembly of section .text:
0000000000000000 <sum8>:
0: \tvmovdqu\t(%rcx), %ymm0
4: \tvpaddd\t%ymm0, %ymm1, %ymm0
8: \tvzeroupper
b: \tretq
'''
LINKED = '''
avx.exe:\tfile format coff-x86-64
Disassembly of section .text:
00000001400014b0 <sum8>:
1400014b0: \tvmovdqu\t(%rcx), %ymm0
1400014b4: \tvpshufd\t$0x55, %ymm0, %ymm1 # ymm1 = ymm0[1,1,1,1,5,5,5,5]
1400014b9: \tvpaddd\t%ymm0, %ymm1, %ymm0
1400014bd: \tvzeroupper
1400014c0: \tretq
00000001400014d0 <main>:
1400014d0: \tsubq\t$0x28, %rsp
1400014d4: \tpopcntl\t%eax, %eax
1400014d8: \taddq\t$0x28, %rsp
1400014dc: \tretq
'''
def scan(text):
done = subprocess.CompletedProcess([], 0, text, '')
with mock.patch.object(check_isa.subprocess, 'run', return_value=done):
return check_isa.scan_one(Path('x'), 'llvm-objdump')
class ScanTest(unittest.TestCase):
def test_an_object_is_scanned(self):
hits = scan(OBJECT)
self.assertEqual(set(hits), {('avx.o', 'sum8')})
self.assertEqual(hits[('avx.o', 'sum8')]['vpaddd'], 1)
def test_a_linked_image_is_scanned(self):
hits = scan(LINKED)
self.assertEqual(set(hits), {('avx.exe', 'sum8')}) # main's popcnt is x86-64-v2
self.assertEqual(sum(hits[('avx.exe', 'sum8')].values()), 4)
def test_function_headers_and_blank_lines_are_not_instructions(self):
self.assertEqual(scan('\nDisassembly of section .text:\n\n00000001400014b0 <vfoo>:\n'), {})
if __name__ == '__main__':
unittest.main()
+1
View File
@@ -48,6 +48,7 @@ TESTS = {
# ---- no game files, no build ----
'flags_check': ('.venv', None, [], ''),
'excl_mt': ('.venv', None, [], ''),
'check_isa_test': ('.venv', None, [], ''),
'pack_shader_cache_test': ('.venv', None, [], ''),
'spin_waits_test': ('.venv', None, [], ''),
'worktree_test': ('.venv', None, [], ''),
+5 -1
View File
@@ -33,6 +33,7 @@ NON_V2 = {'andn', 'bextr', 'blsi', 'blsmsk', 'blsr', 'bzhi', 'shlx', 'shrx', 'sa
'pclmulqdq', 'rdrand', 'rdseed'}
PREFIXES = {'rep', 'repe', 'repz', 'repne', 'repnz', 'lock', 'notrack', 'data16', 'cs', 'ds', 'es', 'ss', 'fs', 'gs'}
WIDE = re.compile(r'%[yz]mm\d|%k[0-7]\b')
INSN = re.compile(r'^\s*[0-9a-f]+:')
# Function -> the runtime check that keeps it off CPUs without the instructions.
DISPATCHED = {
@@ -89,7 +90,10 @@ def scan_one(path, objdump):
if m:
func = m.group(1)
continue
if not line[:1].isspace():
# An instruction line starts with its address: short and indented in an object, 9+ hex digits at the start of
# the line in a linked .exe or .dll. Testing for leading whitespace alone skipped every instruction of a linked
# image and reported it clean.
if not INSN.match(line):
continue
mn = mnemonic(line)
if mn and func not in DISPATCHED and is_non_v2(line, mn):