From 75d52daeb5184d226ef184eda6aed10b51867881 Mon Sep 17 00:00:00 2001 From: Mark Horvath Date: Mon, 19 Feb 2024 10:57:27 +0100 Subject: [PATCH] Rename swap to swap_scalable Otherwise in some C++ Standard Library implementations our implementation could collide with std::swap. Also, the NEON path changed to use std::swap. --- intrinsiccv/include/intrinsiccv/sve2.h | 11 ++++++++++- intrinsiccv/include/intrinsiccv/utils.h | 9 --------- .../src/conversions/yuv_to_rgb_neon.cpp | 18 ++++++++++-------- intrinsiccv/src/conversions/yuv_to_rgb_sc.h | 4 +--- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/intrinsiccv/include/intrinsiccv/sve2.h b/intrinsiccv/include/intrinsiccv/sve2.h index 3bfae8108..7fe117a6f 100644 --- a/intrinsiccv/include/intrinsiccv/sve2.h +++ b/intrinsiccv/include/intrinsiccv/sve2.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2023 Arm Limited and/or its affiliates +// SPDX-FileCopyrightText: 2023 - 2024 Arm Limited and/or its affiliates // // SPDX-License-Identifier: Apache-2.0 @@ -768,6 +768,15 @@ using SeparableFilter3x3 = SeparableFilter; template using SeparableFilter5x5 = SeparableFilter; +// Swap two variables, since some C++ Standard Library implementations do not +// allow using std::swap for SVE vectors. +template +static inline void swap_scalable(T &a, T &b) INTRINSICCV_STREAMING_COMPATIBLE { + T tmp = a; + a = b; + b = tmp; +} + } // namespace intrinsiccv::sve2 #endif // INTRINSICCV_SVE2_H diff --git a/intrinsiccv/include/intrinsiccv/utils.h b/intrinsiccv/include/intrinsiccv/utils.h index 785c5a1ca..c6d4652a9 100644 --- a/intrinsiccv/include/intrinsiccv/utils.h +++ b/intrinsiccv/include/intrinsiccv/utils.h @@ -61,15 +61,6 @@ static T rounding_shift_right(T value, return (value + (1UL << (shift - 1))) >> shift; } -// Swap two variables, since non-Android toolchains do not allow using std::swap -// for SVE vectors. -template -static inline void swap(T &a, T &b) INTRINSICCV_STREAMING_COMPATIBLE { - T tmp = a; - a = b; - b = tmp; -} - // When placed in a loop, it effectively disables loop vectorization. static inline void disable_loop_vectorization() INTRINSICCV_STREAMING_COMPATIBLE { diff --git a/intrinsiccv/src/conversions/yuv_to_rgb_neon.cpp b/intrinsiccv/src/conversions/yuv_to_rgb_neon.cpp index 0b6102b88..04861ee8c 100644 --- a/intrinsiccv/src/conversions/yuv_to_rgb_neon.cpp +++ b/intrinsiccv/src/conversions/yuv_to_rgb_neon.cpp @@ -2,6 +2,8 @@ // // SPDX-License-Identifier: Apache-2.0 +#include + #include "intrinsiccv/conversions/yuv_to_rgb.h" #include "intrinsiccv/intrinsiccv.h" #include "intrinsiccv/neon.h" @@ -80,8 +82,8 @@ class YUVSpToRGBxOrBGRx final : public UnrollOnce { // Swap U and V channels for NV21 (order is V, U). if (is_nv21_) { - swap(u_l, v_l); - swap(u_h, v_h); + std::swap(u_l, v_l); + std::swap(u_h, v_h); } // R - Y = Rbase + Weight(RV) * V = @@ -172,8 +174,8 @@ class YUVSpToRGBxOrBGRx final : public UnrollOnce { rgba1.val[3] = vdupq_n_u8(0xFF); if constexpr (BGR) { - swap(rgba0.val[0], rgba0.val[2]); - swap(rgba1.val[0], rgba1.val[2]); + std::swap(rgba0.val[0], rgba0.val[2]); + std::swap(rgba1.val[0], rgba1.val[2]); } // Store RGB pixels to memory. @@ -192,8 +194,8 @@ class YUVSpToRGBxOrBGRx final : public UnrollOnce { rgb1.val[2] = vcombine_u8(b1.val[0], b1.val[1]); if constexpr (BGR) { - swap(rgb0.val[0], rgb0.val[2]); - swap(rgb1.val[0], rgb1.val[2]); + std::swap(rgb0.val[0], rgb0.val[2]); + std::swap(rgb1.val[0], rgb1.val[2]); } // Store RGB pixels to memory. @@ -222,7 +224,7 @@ class YUVSpToRGBxOrBGRx final : public UnrollOnce { v_m128 = uv_row[1] - 128; uv_row += 2; if (is_nv21_) { - swap(u_m128, v_m128); + std::swap(u_m128, v_m128); } } @@ -238,7 +240,7 @@ class YUVSpToRGBxOrBGRx final : public UnrollOnce { b = rounding_shift_right(b, kWeightScale); if constexpr (BGR) { - swap(r, b); + std::swap(r, b); } rgbx_rows[selector][0] = saturating_cast(r); diff --git a/intrinsiccv/src/conversions/yuv_to_rgb_sc.h b/intrinsiccv/src/conversions/yuv_to_rgb_sc.h index 5d935ca95..aedfcc62a 100644 --- a/intrinsiccv/src/conversions/yuv_to_rgb_sc.h +++ b/intrinsiccv/src/conversions/yuv_to_rgb_sc.h @@ -5,8 +5,6 @@ #ifndef INTRINSICCV_YUV_TO_RGB_SC_H #define INTRINSICCV_YUV_TO_RGB_SC_H -#include - #include "intrinsiccv/conversions/yuv_to_rgb.h" #include "intrinsiccv/intrinsiccv.h" #include "intrinsiccv/sve2.h" @@ -81,7 +79,7 @@ class YUVSpToRGBxOrBGRx final { if (is_nv21_) { // Swap U and V channels for NV21 (order is V, U). - swap(u, v); + swap_scalable(u, v); } svint32_t u_b = svmovlb(u); -- GitLab