From 73342411bc7aa1a9b965d6b3f0b3d6ceecaa2420 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 24 Jan 2024 22:04:28 +0530 Subject: [PATCH] Dont build any SIMD code when the target is neither ARM64 nor x86/amd64 --- kitty/simd-string-impl.h | 8 ++++++++ setup.py | 9 ++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/kitty/simd-string-impl.h b/kitty/simd-string-impl.h index 6ea2be62b..17aa7d91a 100644 --- a/kitty/simd-string-impl.h +++ b/kitty/simd-string-impl.h @@ -4,6 +4,13 @@ * Distributed under terms of the GPL3 license. */ +#pragma once +#ifdef KITTY_NO_SIMD +bool utf8_decode_to_esc_128(UTF8Decoder *d, const uint8_t *src, size_t src_sz) { fatal("No SIMD implementations for this CPU"); } +bool utf8_decode_to_esc_256(UTF8Decoder *d, const uint8_t *src, size_t src_sz) { fatal("No SIMD implementations for this CPU"); } +const uint8_t* find_either_of_two_bytes_128(const uint8_t *haystack, const size_t sz, const uint8_t a, const uint8_t b) { fatal("No SIMD implementations for this CPU"); } +const uint8_t* find_either_of_two_bytes_256(const uint8_t *haystack, const size_t sz, const uint8_t a, const uint8_t b) { fatal("No SIMD implementations for this CPU"); } +#else #ifndef KITTY_SIMD_LEVEL #define KITTY_SIMD_LEVEL 128 #endif @@ -574,3 +581,4 @@ invalid_utf8: #undef sum_bytes #undef is_zero #undef print_register_as_bytes +#endif // KITTY_NO_SIMD diff --git a/setup.py b/setup.py index b57f77a36..3b6a53b57 100755 --- a/setup.py +++ b/setup.py @@ -709,12 +709,11 @@ def get_source_specific_defines(env: Env, src: str) -> Tuple[str, List[str], Opt def get_source_specific_cflags(env: Env, src: str) -> List[str]: ans = list(env.cflags) # SIMD specific flags, ignored for native optimizations as they give slightly better performance - if src == 'kitty/simd-string-128.c': + if src in ('kitty/simd-string-128.c', 'kitty/simd-string-256.c'): if env.binary_arch.isa in (ISA.AMD64, ISA.X86): - ans.append('-msse4.2') - elif src == 'kitty/simd-string-256.c': - if env.binary_arch.isa in (ISA.AMD64, ISA.X86): - ans.append('-mavx2') + ans.append('-msse4.2' if '128' in src else '-mavx2') + elif env.binary_arch.isa != ISA.ARM64: + ans.append('-DKITTY_NO_SIMD') elif src.startswith('3rdparty/base64/lib/arch/'): if env.binary_arch.isa in (ISA.AMD64, ISA.X86): q = src.split(os.path.sep)