mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00: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
9c583154b0
commit
7e9dc9c1fd
Notes:
sideshowbarker
2024-07-18 02:44:27 +09:00
Author: https://github.com/DanShaders Commit: https://github.com/LadybirdBrowser/ladybird/commit/7e9dc9c1fdf Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/617
2 changed files with 6 additions and 7 deletions
|
@ -11,7 +11,7 @@
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
template<typename T, typename U>
|
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))
|
#if (__has_builtin(__builtin_bit_cast))
|
||||||
return __builtin_bit_cast(T, a);
|
return __builtin_bit_cast(T, a);
|
||||||
|
|
|
@ -261,12 +261,11 @@ ALWAYS_INLINE static T byte_reverse_impl(T a, IndexSequence<Idx...>)
|
||||||
// Hence this giant conditional
|
// 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>>>>>;
|
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));
|
static_assert(sizeof(BytesVector) == sizeof(T));
|
||||||
// Note: Using __builtin_bit_cast instead of bit_cast to avoid a psabi warning from bit_cast
|
return bit_cast<T>(
|
||||||
auto tmp = __builtin_shufflevector(
|
__builtin_shufflevector(
|
||||||
__builtin_bit_cast(BytesVector, a),
|
bit_cast<BytesVector>(a),
|
||||||
__builtin_bit_cast(BytesVector, a),
|
bit_cast<BytesVector>(a),
|
||||||
N - 1 - Idx...);
|
N - 1 - Idx...));
|
||||||
return __builtin_bit_cast(T, tmp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<SIMDVector T, size_t... Idx>
|
template<SIMDVector T, size_t... Idx>
|
||||||
|
|
Loading…
Reference in a new issue