From 8742fb8cceec53f8e2489a93567359212df6d35d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 16 Nov 2023 21:35:02 +0530 Subject: [PATCH] Detect availability of intrinsics on intel macs just in case --- kitty/simd-string.c | 6 +++++- kitty_tests/main.py | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/kitty/simd-string.c b/kitty/simd-string.c index 7c57b6fd9..b9dc529d3 100644 --- a/kitty/simd-string.c +++ b/kitty/simd-string.c @@ -243,8 +243,12 @@ init_simd(void *x) { PyObject *module = (PyObject*)x; #define A(x, val) { Py_INCREF(Py_##val); if (0 != PyModule_AddObject(module, #x, Py_##val)) return false; } #ifdef __APPLE__ - // Modern Apple Intel processors should all support AVX2. And simde takes care of NEON on Apple Silicon +#ifdef __arm64__ + // simde takes care of NEON on Apple Silicon has_sse4_2 = true; has_avx2 = true; +#else + has_sse4_2 = __builtin_cpu_supports("sse4.2") != 0; has_avx2 = __builtin_cpu_supports("avx2"); +#endif #else #ifdef __aarch64__ // no idea how to probe ARM cpu for NEON support. This file uses pretty diff --git a/kitty_tests/main.py b/kitty_tests/main.py index 0b7432ffe..3ad9319a2 100644 --- a/kitty_tests/main.py +++ b/kitty_tests/main.py @@ -298,6 +298,8 @@ def env_for_python_tests(report_env: bool = False) -> Iterator[None]: if os.environ.get('CI') == 'true' or report_env: print('Using PATH in test environment:', path) print('Python:', python_for_type_check()) + from kitty.fast_data_types import has_avx2, has_sse4_2 + print(f'Intrinsics: {has_avx2=} {has_sse4_2=}') with TemporaryDirectory() as tdir, env_vars( HOME=tdir,