diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-10-10 23:11:54 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-10-10 23:11:54 +0200 |
commit | 21667ee291f4b8d1c8aff8a41cfbe46299424b44 (patch) | |
tree | bcda581e9ecaf46498d1204da5e7441f1a3dc28d /src | |
parent | 45e8749ed0b44748ab888807fe111c8d26196548 (diff) |
normalize_coord: don't use IMUL
Diffstat (limited to 'src')
-rw-r--r-- | src/object.cpp | 16 |
1 files 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<int tile_size> constexpr inline Pair<int, int8_t> 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 }; } |