mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-22 09:21:57 -05:00
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.
This commit is contained in:
parent
56b7f9e404
commit
2b65b62c6e
2 changed files with 6 additions and 7 deletions
|
@ -11,7 +11,7 @@
|
|||
namespace AK {
|
||||
|
||||
template<typename T, typename U>
|
||||
[[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);
|
||||
|
|
|
@ -254,12 +254,11 @@ ALWAYS_INLINE static T byte_reverse_impl(T a, IndexSequence<Idx...>)
|
|||
// Hence this giant conditional
|
||||
using BytesVector = Conditional<sizeof(T) == 2, u8x2, Conditional<sizeof(T) == 4, u8x4, Conditional<sizeof(T) == 8, u8x8, Conditional<sizeof(T) == 16, u8x16, Conditional<sizeof(T) == 32, u8x32, void>>>>>;
|
||||
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<T>(
|
||||
__builtin_shufflevector(
|
||||
bit_cast<BytesVector>(a),
|
||||
bit_cast<BytesVector>(a),
|
||||
N - 1 - Idx...));
|
||||
}
|
||||
|
||||
template<SIMDVector T, size_t... Idx>
|
||||
|
|
Loading…
Reference in a new issue