From e84d809348f60f062911758aeb01649a8df9f709 Mon Sep 17 00:00:00 2001 From: George Steed Date: Fri, 17 May 2024 17:11:25 +0100 Subject: [PATCH] [AArch64] Add SVE2 implementation of I410ToARGBRow Observed reduction in runtime compared to the existing Neon code: Cortex-A510: -37.9% Cortex-A520: -9.2% Cortex-A715: -14.3% Cortex-A720: -14.2% Cortex-X2: -10.9% Cortex-X3: -11.1% Cortex-X4: -12.5% Cortex-X925: -10.6% Bug: b/42280942 Change-Id: I6720b07c900c7dfbd849ee38e413e98b9374dac2 Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/6023581 Reviewed-by: Justin Green Reviewed-by: Frank Barchard --- include/libyuv/row.h | 7 +++++ source/convert_argb.cc | 15 ++++++++++ source/row_sve.cc | 63 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) diff --git a/include/libyuv/row.h b/include/libyuv/row.h index 802c75c1f..4f5e582d4 100644 --- a/include/libyuv/row.h +++ b/include/libyuv/row.h @@ -559,6 +559,7 @@ extern "C" { #define HAS_I212TOAR30ROW_SVE2 #define HAS_I212TOARGBROW_SVE2 #define HAS_I400TOARGBROW_SVE2 +#define HAS_I410TOARGBROW_SVE2 #define HAS_I422ALPHATOARGBROW_SVE2 #define HAS_I422TOARGB1555ROW_SVE2 #define HAS_I422TOARGB4444ROW_SVE2 @@ -1124,6 +1125,12 @@ void I410ToARGBRow_NEON(const uint16_t* src_y, uint8_t* rgb_buf, const struct YuvConstants* yuvconstants, int width); +void I410ToARGBRow_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 I210ToAR30Row_NEON(const uint16_t* src_y, const uint16_t* src_u, const uint16_t* src_v, diff --git a/source/convert_argb.cc b/source/convert_argb.cc index 6f41b4d43..dfcd4a7ce 100644 --- a/source/convert_argb.cc +++ b/source/convert_argb.cc @@ -1879,6 +1879,11 @@ int I410ToARGBMatrix(const uint16_t* src_y, } } #endif +#if defined(HAS_I410TOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I410ToARGBRow = I410ToARGBRow_SVE2; + } +#endif #if defined(HAS_I410TOARGBROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { I410ToARGBRow = I410ToARGBRow_Any_AVX2; @@ -7182,6 +7187,11 @@ static int I010ToARGBMatrixBilinear(const uint16_t* src_y, } } #endif +#if defined(HAS_I410TOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I410ToARGBRow = I410ToARGBRow_SVE2; + } +#endif #if defined(HAS_I410TOARGBROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { I410ToARGBRow = I410ToARGBRow_Any_AVX2; @@ -7295,6 +7305,11 @@ static int I210ToARGBMatrixLinear(const uint16_t* src_y, } } #endif +#if defined(HAS_I410TOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I410ToARGBRow = I410ToARGBRow_SVE2; + } +#endif #if defined(HAS_I410TOARGBROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { I410ToARGBRow = I410ToARGBRow_Any_AVX2; diff --git a/source/row_sve.cc b/source/row_sve.cc index 00b51872b..dac1d753d 100644 --- a/source/row_sve.cc +++ b/source/row_sve.cc @@ -121,6 +121,21 @@ extern "C" { "prfm pldl1keep, [%[src_uv], 256] \n" \ "tbl z1.b, {z1.b}, z22.b \n" +#define READI410_SVE \ + "ld1h {z3.h}, p1/z, [%[src_y]] \n" \ + "lsl z0.h, z3.h, #6 \n" \ + "usra z0.h, z3.h, #4 \n" \ + "ld1h {z1.h}, p1/z, [%[src_u]] \n" \ + "ld1h {z2.h}, p1/z, [%[src_v]] \n" \ + "incb %[src_y] \n" \ + "incb %[src_u] \n" \ + "incb %[src_v] \n" \ + "prfm pldl1keep, [%[src_y], 448] \n" \ + "prfm pldl1keep, [%[src_u], 128] \n" \ + "prfm pldl1keep, [%[src_v], 128] \n" \ + "uqshrnb z1.b, z1.h, #2 \n" \ + "uqshrnb z2.b, z2.h, #2 \n" + // We need different predicates for the UV components since we are reading // 32-bit (pairs of UV) elements rather than 16-bit Y elements. #define READP410_SVE \ @@ -2120,6 +2135,54 @@ void P210ToAR30Row_SVE2(const uint16_t* src_y, : "cc", "memory", YUVTORGB_SVE_REGS); } +void I410ToARGBRow_SVE2(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* dst_argb, + 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; + asm volatile( + "ptrue p0.b \n" YUVTORGB_SVE_SETUP + "dup z19.b, #255 \n" // A + "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" // + READI410_SVE I4XXTORGB_SVE RGBTOARGB8_SVE + "subs %w[width], %w[width], %w[vl] \n" + "st2h {z16.h, z17.h}, p1, [%[dst_argb]] \n" + "add %[dst_argb], %[dst_argb], %[vl], lsl #2 \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" // + READI410_SVE I4XXTORGB_SVE RGBTOARGB8_SVE + "st2h {z16.h, z17.h}, p1, [%[dst_argb]] \n" + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [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] + : "cc", "memory", YUVTORGB_SVE_REGS); +} + void P410ToARGBRow_SVE2(const uint16_t* src_y, const uint16_t* src_uv, uint8_t* dst_argb,