From 49a54b086fb3c51dd1cf9c80e49d3f8743741e63 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 12 Nov 2023 14:14:09 +0530 Subject: [PATCH] Use simde so SIMD speedups work on ARM as well --- bypy/sources.json | 9 +++++++++ docs/build.rst | 1 + kitty/simd-string.c | 14 +++++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/bypy/sources.json b/bypy/sources.json index f0f6c37c9..8754b5336 100644 --- a/bypy/sources.json +++ b/bypy/sources.json @@ -250,6 +250,15 @@ } }, + { + "name": "simde", + "unix": { + "filename": "simde-amalgamated-0.7.6.tar.xz", + "hash": "sha256:703eac1f2af7de1f7e4aea2286130b98e1addcc0559426e78304c92e2b4eb5e1", + "urls": ["https://github.com/simd-everywhere/simde/releases/download/v0.7.6/{filename}"] + } + }, + { "name": "wayland", "os": "linux", diff --git a/docs/build.rst b/docs/build.rst index 1734871ba..c7f3678cd 100644 --- a/docs/build.rst +++ b/docs/build.rst @@ -96,6 +96,7 @@ Run-time dependencies: Build-time dependencies: * ``gcc`` or ``clang`` +* ``simde`` * ``go`` >= _build_go_version (see :file:`go.mod` for go packages used during building) * ``pkg-config`` * For building on Linux in addition to the above dependencies you might also diff --git a/kitty/simd-string.c b/kitty/simd-string.c index 43b5123b6..aa3cc069c 100644 --- a/kitty/simd-string.c +++ b/kitty/simd-string.c @@ -5,9 +5,10 @@ * Distributed under terms of the GPL3 license. */ +#define SIMDE_ENABLE_NATIVE_ALIASES #include "data-types.h" #include "simd-string.h" -#include +#include static bool has_sse4_2 = false, has_avx2 = false; @@ -194,7 +195,18 @@ bool 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 + has_sse4_2 = true; has_avx2 = true; +#else +#ifdef __aarch64__ + // no idea how to probe ARM cpu for NEON support. This file uses pretty + // basic AVX2 and SSE4.2 intrinsics, so hopefully they work on ARM + has_sse4_2 = true; has_avx2 = true; +#else has_sse4_2 = __builtin_cpu_supports("sse4.2") != 0; has_avx2 = __builtin_cpu_supports("avx2"); +#endif +#endif if (has_avx2) { A(has_avx2, True); find_byte_not_in_range_impl = find_byte_not_in_range_avx2;