From 50108f29fbbcfbb0523b6d8bfdbeda971292acf5 Mon Sep 17 00:00:00 2001 From: George Steed Date: Mon, 10 Jun 2024 14:27:37 +0100 Subject: [PATCH] [AArch64] Add SVE2 implementation of I212ToAR30Row Observed reduction in runtime compared to the existing Neon code: Cortex-A510: -15.4% Cortex-A520: -3.8% Cortex-A715: -15.7% Cortex-A720: -15.6% Cortex-X2: -7.9% Cortex-X3: -5.7% Cortex-X4: -5.3% Cortex-X925: -4.8% Bug: b/42280942 Change-Id: I99846820682687c8e0f52d05f5aa3d50369fe0a2 Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/6025829 Reviewed-by: Justin Green Reviewed-by: Frank Barchard --- include/libyuv/row.h | 7 +++++++ source/convert_argb.cc | 5 +++++ source/row_sve.cc | 47 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/include/libyuv/row.h b/include/libyuv/row.h index 87d079eeb..63b659332 100644 --- a/include/libyuv/row.h +++ b/include/libyuv/row.h @@ -554,6 +554,7 @@ extern "C" { #define HAS_DIVIDEROW_16_SVE2 #define HAS_HALFFLOATROW_SVE2 #define HAS_I210TOARGBROW_SVE2 +#define HAS_I212TOAR30ROW_SVE2 #define HAS_I212TOARGBROW_SVE2 #define HAS_I400TOARGBROW_SVE2 #define HAS_I422ALPHATOARGBROW_SVE2 @@ -1144,6 +1145,12 @@ void I212ToAR30Row_NEON(const uint16_t* src_y, uint8_t* rgb_buf, const struct YuvConstants* yuvconstants, int width); +void I212ToAR30Row_SVE2(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); void I422ToARGBRow_NEON(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, diff --git a/source/convert_argb.cc b/source/convert_argb.cc index 0bcdce5b2..4afb5c218 100644 --- a/source/convert_argb.cc +++ b/source/convert_argb.cc @@ -1160,6 +1160,11 @@ int I012ToAR30Matrix(const uint16_t* src_y, I212ToAR30Row = I212ToAR30Row_NEON; } } +#endif +#if defined(HAS_I212TOAR30ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I212ToAR30Row = I212ToAR30Row_SVE2; + } #endif for (y = 0; y < height; ++y) { I212ToAR30Row(src_y, src_u, src_v, dst_ar30, yuvconstants, width); diff --git a/source/row_sve.cc b/source/row_sve.cc index 110555e2b..449ba02e7 100644 --- a/source/row_sve.cc +++ b/source/row_sve.cc @@ -2117,6 +2117,53 @@ void P410ToAR30Row_SVE2(const uint16_t* src_y, : "cc", "memory", YUVTORGB_SVE_REGS); } +void I212ToAR30Row_SVE2(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + uint64_t vl; + asm("cnth %0" : "=r"(vl)); + int width_last_y = width & (vl - 1); + width_last_y = width_last_y == 0 ? vl : width_last_y; + uint16_t limit = 0x3ff0; + asm volatile( + "ptrue p0.b \n" YUVTORGB_SVE_SETUP + "dup z23.h, %w[limit] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.h \n" + "1: \n" // + READI212_SVE I4XXTORGB_SVE STOREAR30_SVE + "subs %w[width], %w[width], %w[vl] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p1.h, wzr, %w[width_last_y] \n" // + READI212_SVE I4XXTORGB_SVE STOREAR30_SVE + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_ar30] "+r"(dst_ar30), // %[dst_ar30] + [width] "+r"(width) // %[width] + : [vl] "r"(vl), // %[vl] + [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias), // %[kRGBCoeffBias] + [width_last_y] "r"(width_last_y), // %[width_last_y] + [limit] "r"(limit) // %[limit] + : "cc", "memory", YUVTORGB_SVE_REGS); +} + void I212ToARGBRow_SVE2(const uint16_t* src_y, const uint16_t* src_u, const uint16_t* src_v,