arm64 python: Avoid nested class in insn hook for 10x hook and 10% overall speedup (#2095)

* arm64 python: Avoid nested class in insn hook for 10x hook speedup

Promote CpReg to a module-level class to address unnecessary performance
reduction.  In a real-world use case tracing the emulation of real-world
machine code, this change reduces time spent in CpReg namedtuple
construction from 10% of overall time to below 1%, for a 10x speedup of
the insn hook itself, or a 10% overall speedup.  Measured using
cProfile, python 3.13.

* upgrade distro to 22.04

* revert to 22.04 for now

* also revert for wheels

---------

Co-authored-by: mio <mio@lazym.io>
This commit is contained in:
Daniel Roethlisberger
2025-02-10 07:56:34 +01:00
committed by GitHub
parent 1ba25def8e
commit e166cd93bb
3 changed files with 15 additions and 14 deletions

View File

@@ -471,7 +471,7 @@ jobs:
generators: 'Ninja' generators: 'Ninja'
} }
- { - {
os: ubuntu-latest, os: ubuntu-22.04,
arch: aarch64, arch: aarch64,
python-arch: aarch64, python-arch: aarch64,
python-ver: '3.8', python-ver: '3.8',
@@ -479,10 +479,10 @@ jobs:
artifact: 'ubuntu-cmake-aarch64.7z', artifact: 'ubuntu-cmake-aarch64.7z',
archiver: '7z a', archiver: '7z a',
generators: 'Ninja', generators: 'Ninja',
distro: ubuntu20.04 distro: ubuntu22.04
} }
- { - {
os: ubuntu-latest, os: ubuntu-22.04,
arch: ppc64le, arch: ppc64le,
python-arch: ppc, python-arch: ppc,
python-ver: '3.8', python-ver: '3.8',
@@ -490,7 +490,7 @@ jobs:
artifact: 'ubuntu-cmake-ppc64le.7z', artifact: 'ubuntu-cmake-ppc64le.7z',
archiver: '7z a', archiver: '7z a',
generators: 'Ninja', generators: 'Ninja',
distro: ubuntu20.04 distro: ubuntu22.04
} }
compiler: [ gcc ] compiler: [ gcc ]
steps: steps:

View File

@@ -55,9 +55,9 @@ jobs:
# x86_64 - musllinux # x86_64 - musllinux
- { os: ubuntu-latest, arch: x86_64, cibw_build: 'cp38-musllinux*', cibw_skip: '' } - { os: ubuntu-latest, arch: x86_64, cibw_build: 'cp38-musllinux*', cibw_skip: '' }
# aarch64 - manylinux # aarch64 - manylinux
- { os: ubuntu-latest, arch: aarch64, cibw_build: 'cp38-manylinux*', cibw_skip: '' } - { os: ubuntu-22.04, arch: aarch64, cibw_build: 'cp38-manylinux*', cibw_skip: '' }
# aarch64 - musllinux # aarch64 - musllinux
- { os: ubuntu-latest, arch: aarch64, cibw_build: 'cp38-musllinux*', cibw_skip: '' } - { os: ubuntu-22.04, arch: aarch64, cibw_build: 'cp38-musllinux*', cibw_skip: '' }
- { os: macos-13, arch: x86_64, cibw_build: 'cp38*', cibw_skip: '' } - { os: macos-13, arch: x86_64, cibw_build: 'cp38*', cibw_skip: '' }
- { os: macos-latest, arch: arm64, cibw_build: 'cp38*', cibw_skip: '' } - { os: macos-latest, arch: arm64, cibw_build: 'cp38*', cibw_skip: '' }
- { os: windows-2019, arch: AMD64, cibw_build: 'cp38*', cibw_skip: '' } - { os: windows-2019, arch: AMD64, cibw_build: 'cp38*', cibw_skip: '' }

View File

@@ -37,6 +37,15 @@ class UcRegCP64(UcTupledReg[ARM64CPReg]):
return self.val return self.val
class CpReg(NamedTuple):
crn: int
crm: int
op0: int
op1: int
op2: int
val: int
class UcAArch64(Uc): class UcAArch64(Uc):
"""Unicorn subclass for ARM64 architecture. """Unicorn subclass for ARM64 architecture.
""" """
@@ -57,14 +66,6 @@ class UcAArch64(Uc):
def __hook_insn_sys_cb(uc: Uc, reg: int, pcp_reg: Any, key: int) -> int: def __hook_insn_sys_cb(uc: Uc, reg: int, pcp_reg: Any, key: int) -> int:
cp_reg = ctypes.cast(pcp_reg, ctypes.POINTER(UcRegCP64)).contents cp_reg = ctypes.cast(pcp_reg, ctypes.POINTER(UcRegCP64)).contents
class CpReg(NamedTuple):
crn: int
crm: int
op0: int
op1: int
op2: int
val: int
cp_reg = CpReg(cp_reg.crn, cp_reg.crm, cp_reg.op0, cp_reg.op1, cp_reg.op2, cp_reg.val) cp_reg = CpReg(cp_reg.crn, cp_reg.crm, cp_reg.op0, cp_reg.op1, cp_reg.op2, cp_reg.val)
return callback(uc, reg, cp_reg, user_data) return callback(uc, reg, cp_reg, user_data)