From 21667ee291f4b8d1c8aff8a41cfbe46299424b44 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 10 Oct 2023 23:11:54 +0200 Subject: normalize_coord: don't use IMUL --- src/object.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/object.cpp b/src/object.cpp index ca47df9d..0605fcf3 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -24,18 +24,20 @@ constexpr auto object_id_lessp = [](const auto& a, const auto& b) { return a->id template constexpr inline Pair normalize_coord(const int8_t cur, const int new_off) { - constexpr auto half_tile = (int8_t)(tile_size/2); - const auto tmp = cur + new_off; + constexpr int8_t half_tile = tile_size/2; + const int tmp = cur + new_off; auto x = (int8_t)(tmp % tile_size); auto t = tmp / tile_size; auto a = Math::abs(x); auto s = Math::sign(x); - auto b = (volatile bool)(x >= half_tile | x < -half_tile); -#if defined __GNUG__ && !defined __clang__ - asm volatile ("" : "+r"(b)); + bool b = x >= half_tile | x < -half_tile; + int tmask = -(volatile int)b; + int8_t xmask = -(volatile int8_t)b; +#if defined __GNUG__ + asm volatile ("" : "+r"(tmask), "+r"(xmask)); #endif - t += s * b; - x = (int8_t)((tile_size - a)*-s) * b | x * !b; + t += s & tmask; + x = (int8_t)((tile_size - a)*-s) & xmask | (int8_t)(x & ~xmask); return { t, (int8_t)x }; } -- cgit v1.2.3