loongarch: Fix RGBToY SIMD

Add missing RGBToYMatrixRow_Any_{LSX,LASX} and kAddY offset fix so
RAW/RGB24 to YUV works on LoongArch.

Change-Id: I4c990a3705d7f521fa6d0c9e7e01f1e36f81c379
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8292090
Reviewed-by: Wan-Teh Chang <wtc@google.com>
Reviewed-by: Frank Barchard <fbarchard@google.com>
Commit-Queue: Wan-Teh Chang <wtc@google.com>
This commit is contained in:
yuanhecai 2026-08-25 19:29:00 +08:00 committed by libyuv-scoped@luci-project-accounts.iam.gserviceaccount.com
parent 2fed9193c9
commit 60102bd795
6 changed files with 52 additions and 14 deletions

View File

@ -797,6 +797,7 @@ extern "C" {
#define HAS_YUY2TOUV422ROW_LSX
#define HAS_YUY2TOYROW_LSX
#define HAS_ARGBTOYMATRIXROW_LSX
#define HAS_RGBTOYMATRIXROW_LSX
#endif
#if !defined(LIBYUV_DISABLE_LSX) && defined(__loongarch_sx)

View File

@ -3399,6 +3399,14 @@ static int RAWToI444Matrix(const uint8_t* src_raw,
}
}
#endif
#if defined(HAS_RGBTOYMATRIXROW_LSX)
if (TestCpuFlag(kCpuHasLSX)) {
RGBToYMatrixRow = RGBToYMatrixRow_Any_LSX;
if (IS_ALIGNED(width, 16)) {
RGBToYMatrixRow = RGBToYMatrixRow_LSX;
}
}
#endif
#if defined(HAS_RGBTOYMATRIXROW_LASX)
if (TestCpuFlag(kCpuHasLASX)) {
RGBToYMatrixRow = RGBToYMatrixRow_Any_LASX;
@ -3822,6 +3830,14 @@ int RGB24ToJ400(const uint8_t* src_rgb24,
}
}
#endif
#if defined(HAS_RGBTOYMATRIXROW_LSX)
if (TestCpuFlag(kCpuHasLSX)) {
RGBToYMatrixRow = RGBToYMatrixRow_Any_LSX;
if (IS_ALIGNED(width, 16)) {
RGBToYMatrixRow = RGBToYMatrixRow_LSX;
}
}
#endif
#if defined(HAS_RGBTOYMATRIXROW_LASX)
if (TestCpuFlag(kCpuHasLASX)) {
RGBToYMatrixRow = RGBToYMatrixRow_Any_LASX;
@ -3911,6 +3927,14 @@ int RAWToJ400(const uint8_t* src_raw,
}
}
#endif
#if defined(HAS_RGBTOYMATRIXROW_LSX)
if (TestCpuFlag(kCpuHasLSX)) {
RGBToYMatrixRow = RGBToYMatrixRow_Any_LSX;
if (IS_ALIGNED(width, 16)) {
RGBToYMatrixRow = RGBToYMatrixRow_LSX;
}
}
#endif
#if defined(HAS_RGBTOYMATRIXROW_LASX)
if (TestCpuFlag(kCpuHasLASX)) {
RGBToYMatrixRow = RGBToYMatrixRow_Any_LASX;

View File

@ -2306,6 +2306,14 @@ static int RAWToNVMatrix(const uint8_t* src_raw,
}
}
#endif
#if defined(HAS_RGBTOYMATRIXROW_LSX)
if (TestCpuFlag(kCpuHasLSX)) {
RGBToYMatrixRow = RGBToYMatrixRow_Any_LSX;
if (IS_ALIGNED(width, 16)) {
RGBToYMatrixRow = RGBToYMatrixRow_LSX;
}
}
#endif
#if defined(HAS_RGBTOYMATRIXROW_LASX)
if (TestCpuFlag(kCpuHasLASX)) {
RGBToYMatrixRow = RGBToYMatrixRow_Any_LASX;

View File

@ -2349,8 +2349,12 @@ ANY11MC(ARGB4444ToYMatrixRow_Any_NEON, ARGB4444ToYMatrixRow_NEON, 2, 15)
#ifdef HAS_ARGBTOYMATRIXROW_LSX
ANY11MC(ARGBToYMatrixRow_Any_LSX, ARGBToYMatrixRow_LSX, 4, 15)
#endif
#ifdef HAS_RGBTOYMATRIXROW_LSX
ANY11MC(RGBToYMatrixRow_Any_LSX, RGBToYMatrixRow_LSX, 3, 15)
#endif
#ifdef HAS_ARGBTOYMATRIXROW_LASX
ANY11MC(ARGBToYMatrixRow_Any_LASX, ARGBToYMatrixRow_LASX, 4, 31)
ANY11MC(RGBToYMatrixRow_Any_LASX, RGBToYMatrixRow_LASX, 3, 31)
#endif
#ifdef HAS_ARGBTOYMATRIXROW_RVV
ANY11MC(ARGBToYMatrixRow_Any_RVV, ARGBToYMatrixRow_RVV, 4, 15)

View File

@ -1933,10 +1933,10 @@ void ARGBToYMatrixRow_LASX(const uint8_t* src_argb,
}
void RGBToYMatrixRow_LASX(const uint8_t* src_rgba,
uint8_t* dst_y,
int width,
const struct ArgbConstants* c) {
int8_t shuff[128] = {
uint8_t* dst_y,
int width,
const struct ArgbConstants* c) {
static const int8_t shuff[128] = {
0, 2, 3, 5, 6, 8, 9, 11, 12, 14, 15, 17, 18, 20, 21, 23,
0, 2, 3, 5, 6, 8, 9, 11, 12, 14, 15, 17, 18, 20, 21, 23,
24, 26, 27, 29, 30, 0, 1, 3, 4, 6, 7, 9, 10, 12, 13, 15,
@ -1949,7 +1949,7 @@ void RGBToYMatrixRow_LASX(const uint8_t* src_rgba,
"xvldrepl.b $xr0, %3, 0 \n\t" // load rgbconstants
"xvldrepl.b $xr1, %3, 1 \n\t" // load rgbconstants
"xvldrepl.b $xr2, %3, 2 \n\t" // load rgbconstants
"xvldrepl.h $xr3, %3, 4 \n\t" // load rgbconstants
"xvldrepl.h $xr3, %3, 96 \n\t" // load rgbconstants
"xvld $xr4, %4, 0 \n\t" // load shuff
"xvld $xr5, %4, 32 \n\t"
"xvld $xr6, %4, 64 \n\t"

View File

@ -2646,19 +2646,20 @@ void ARGBToYMatrixRow_LSX(const uint8_t* src_argb,
}
void RGBToYMatrixRow_LSX(const uint8_t* src_rgba,
uint8_t* dst_y,
int width,
const struct ArgbConstants* c) {
int8_t shuff[64] = {0, 2, 3, 5, 6, 8, 9, 11, 12, 14, 15, 17, 18,
20, 21, 23, 24, 26, 27, 29, 30, 0, 1, 3, 4, 6,
7, 9, 10, 12, 13, 15, 1, 0, 4, 0, 7, 0, 10,
0, 13, 0, 16, 0, 19, 0, 22, 0, 25, 0, 28, 0,
31, 0, 2, 0, 5, 0, 8, 0, 11, 0, 14, 0};
uint8_t* dst_y,
int width,
const struct ArgbConstants* c) {
static const int8_t shuff[64] = {
0, 2, 3, 5, 6, 8, 9, 11, 12, 14, 15, 17, 18, 20, 21, 23,
24, 26, 27, 29, 30, 0, 1, 3, 4, 6, 7, 9, 10, 12, 13, 15,
1, 0, 4, 0, 7, 0, 10, 0, 13, 0, 16, 0, 19, 0, 22, 0,
25, 0, 28, 0, 31, 0, 2, 0, 5, 0, 8, 0, 11, 0, 14, 0,
};
asm volatile(
"vldrepl.b $vr0, %3, 0 \n\t" // load rgbconstants
"vldrepl.b $vr1, %3, 1 \n\t" // load rgbconstants
"vldrepl.b $vr2, %3, 2 \n\t" // load rgbconstants
"vldrepl.h $vr3, %3, 4 \n\t" // load rgbconstants
"vldrepl.h $vr3, %3, 96 \n\t" // load rgbconstants
"vld $vr4, %4, 0 \n\t" // load shuff
"vld $vr5, %4, 16 \n\t"
"vld $vr6, %4, 32 \n\t"