From c9b11379ee3e282a82a53995b64160aead8bfa94 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 17 Jan 2022 11:49:30 +0100 Subject: Use clang builtins in gcc when available __builtin_convertvector since gcc 9 __builtin_shufflevector since gcc 12 Change-Id: I51f056473342054203016e87b4e048d0e8139f11 Reviewed-by: Peter Varga --- chromium/third_party/skia/include/private/SkVx.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/chromium/third_party/skia/include/private/SkVx.h b/chromium/third_party/skia/include/private/SkVx.h index 74cdabffe2d..2fcc42ed3a3 100644 --- a/chromium/third_party/skia/include/private/SkVx.h +++ b/chromium/third_party/skia/include/private/SkVx.h @@ -558,8 +558,8 @@ SI Vec<1,D> cast(const Vec<1,S>& src) { return (D)src.val; } template SI Vec cast(const Vec& src) { -#if SKVX_USE_SIMD && defined(__clang__) - return to_vec(__builtin_convertvector(to_vext(src), VExt)); +#if SKVX_USE_SIMD && (defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 9)) + return to_vec(__builtin_convertvector(to_vext(src), VExt)); #else return join(cast(src.lo), cast(src.hi)); #endif @@ -594,10 +594,22 @@ SINT Vec pin(const Vec& x, const Vec& lo, const Vec& hi) { // The only real restriction is that the output also be a legal N=power-of-two sknx::Vec. template SI Vec shuffle(const Vec& x) { -#if SKVX_USE_SIMD && defined(__clang__) +#if SKVX_USE_SIMD && (defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 12)) // TODO: can we just always use { x[Ix]... }? return to_vec(__builtin_shufflevector(to_vext(x), to_vext(x), Ix...)); #else +#if !defined(SKNX_NO_SIMD) && defined(__GNUC__) + if constexpr(sizeof...(Ix) == N) { + if constexpr(sizeof(T) == 1) + return to_vec(__builtin_shuffle(to_vext(x), VExt{Ix...})); + else if constexpr(sizeof(T) == 2) + return to_vec(__builtin_shuffle(to_vext(x), VExt{Ix...})); + else if constexpr(sizeof(T) == 4) + return to_vec(__builtin_shuffle(to_vext(x), VExt{Ix...})); + else if constexpr(sizeof(T) == 8) + return to_vec(__builtin_shuffle(to_vext(x), VExt{Ix...})); + } else +#endif return { x[Ix]... }; #endif } -- cgit v1.2.1