From 7e9dc9c1fdfa7ecffb61c109d646080ed49c12e3 Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Fri, 5 Jul 2024 12:46:18 -0400 Subject: [PATCH] AK: Use bit_cast in SIMDExtras.h/AK::Detail::byte_reverse_impl This necessitates marking bit_cast as ALWAYS_INLINE since emitting it as a function call there will create an unnecessary potential SSE registers -> plain registers/memory round-trip. --- AK/BitCast.h | 2 +- AK/SIMDExtras.h | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/AK/BitCast.h b/AK/BitCast.h index a1f6f17d39f..32752c738f3 100644 --- a/AK/BitCast.h +++ b/AK/BitCast.h @@ -11,7 +11,7 @@ namespace AK { template -[[nodiscard]] constexpr inline T bit_cast(U const& a) +[[nodiscard]] constexpr ALWAYS_INLINE T bit_cast(U const& a) { #if (__has_builtin(__builtin_bit_cast)) return __builtin_bit_cast(T, a); diff --git a/AK/SIMDExtras.h b/AK/SIMDExtras.h index d8568cf6f9c..3147f2fb3a8 100644 --- a/AK/SIMDExtras.h +++ b/AK/SIMDExtras.h @@ -261,12 +261,11 @@ ALWAYS_INLINE static T byte_reverse_impl(T a, IndexSequence) // Hence this giant conditional using BytesVector = Conditional>>>>; static_assert(sizeof(BytesVector) == sizeof(T)); - // Note: Using __builtin_bit_cast instead of bit_cast to avoid a psabi warning from bit_cast - auto tmp = __builtin_shufflevector( - __builtin_bit_cast(BytesVector, a), - __builtin_bit_cast(BytesVector, a), - N - 1 - Idx...); - return __builtin_bit_cast(T, tmp); + return bit_cast( + __builtin_shufflevector( + bit_cast(a), + bit_cast(a), + N - 1 - Idx...)); } template