mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-08-27 03:42:49 +00:00
Ensure cpu is inited before calling cpu_supports()
This commit is contained in:
parent
c1793d8781
commit
2cb87861c0
2 changed files with 7 additions and 5 deletions
|
|
@ -24,6 +24,7 @@ _Pragma("clang diagnostic pop")
|
|||
#define FUNC(name) CONCAT_EXPAND(name##_, BITS)
|
||||
#define integer_t CONCAT_EXPAND(CONCAT_EXPAND(simde__m, BITS), i)
|
||||
#define shift_right_by_bytes128 simde_mm_srli_si128
|
||||
#define count_trailing_zeros __builtin_ctz
|
||||
|
||||
#if BITS == 128
|
||||
#define set1_epi8 simde_mm_set1_epi8
|
||||
|
|
@ -68,7 +69,7 @@ FUNC(find_either_of_two_bytes)(const uint8_t *haystack, const size_t sz, const u
|
|||
const integer_t matches = or_si(a_cmp, b_cmp);
|
||||
const int mask = movemask_epi8(matches);
|
||||
if (mask != 0) {
|
||||
size_t pos = __builtin_ctz(mask);
|
||||
size_t pos = count_trailing_zeros(mask);
|
||||
const uint8_t *ans = haystack + pos;
|
||||
if (ans < limit) return ans;
|
||||
}
|
||||
|
|
@ -128,7 +129,7 @@ FUNC(utf8_decode_to_esc)(UTF8Decoder *d, const uint8_t *src, size_t src_sz) {
|
|||
const integer_t esc_cmp = cmpeq_epi8(vec, esc_vec);
|
||||
const int esc_test_mask = movemask_epi8(esc_cmp);
|
||||
bool sentinel_found = false;
|
||||
const unsigned num_of_bytes_to_first_esc = __builtin_ctz(esc_test_mask);
|
||||
const unsigned num_of_bytes_to_first_esc = count_trailing_zeros(esc_test_mask);
|
||||
if (num_of_bytes_to_first_esc < src_sz) {
|
||||
sentinel_found = true;
|
||||
d->num_consumed = num_of_bytes_to_first_esc + 1; // esc is also consumed
|
||||
|
|
@ -136,7 +137,7 @@ FUNC(utf8_decode_to_esc)(UTF8Decoder *d, const uint8_t *src, size_t src_sz) {
|
|||
} else d->num_consumed = src_sz;
|
||||
|
||||
const int ascii_test_mask = movemask_epi8(vec);
|
||||
const unsigned num_of_bytes_to_first_non_ascii_byte = __builtin_ctz(ascii_test_mask);
|
||||
const unsigned num_of_bytes_to_first_non_ascii_byte = count_trailing_zeros(ascii_test_mask);
|
||||
|
||||
if (num_of_bytes_to_first_non_ascii_byte >= src_sz) { // no bytes with high bit (0x80) set, so just plain ASCII
|
||||
FUNC(output_plain_ascii)(d, vec, src_sz);
|
||||
|
|
|
|||
|
|
@ -117,13 +117,14 @@ bool
|
|||
init_simd(void *x) {
|
||||
PyObject *module = (PyObject*)x;
|
||||
if (PyModule_AddFunctions(module, module_methods) != 0) return false;
|
||||
__builtin_cpu_init();
|
||||
#define A(x, val) { Py_INCREF(Py_##val); if (0 != PyModule_AddObject(module, #x, Py_##val)) return false; }
|
||||
#ifdef __APPLE__
|
||||
#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");
|
||||
has_sse4_2 = __builtin_cpu_supports("sse4.2") != 0; has_avx2 = __builtin_cpu_supports("avx2") != 0;
|
||||
#endif
|
||||
#else
|
||||
#ifdef __aarch64__
|
||||
|
|
@ -131,7 +132,7 @@ init_simd(void *x) {
|
|||
// 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");
|
||||
has_sse4_2 = __builtin_cpu_supports("sse4.2") != 0; has_avx2 = __builtin_cpu_supports("avx2") != 0;
|
||||
#endif
|
||||
#endif
|
||||
if (has_avx2) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue