aports/community/firefox-esr/loong0005-Fix-libyuv-build-with-LSX-LASX.patch

405 lines
18 KiB
Diff

Patch-Source: https://github.com/xen0n/loongson-overlay/blob/master/www-client/firefox/files/firefox-125-loong/0004-Fix-libyuv-build-with-LSX-LASX.patch
This is needed when building with Clang 19, as LSX is now enabled by default:
https://releases.llvm.org/19.1.0/tools/clang/docs/ReleaseNotes.html#loongarch-support
--
From f4889c3a19eb0991d2f468ac29955f6a8b73c164 Mon Sep 17 00:00:00 2001
From: WANG Xuerui <xen0n@gentoo.org>
Date: Sun, 31 Dec 2023 13:16:33 +0800
Subject: [PATCH 4/9] Fix libyuv build with LSX & LASX
This is not of upstream quality, and will not be upstreamed as-is.
This is only meant as a quick-and-dirty build fix for LoongArch early
adopters.
Signed-off-by: WANG Xuerui <xen0n@gentoo.org>
---
media/libyuv/libyuv/BUILD.gn | 37 +++++++++++++++++++++
media/libyuv/libyuv/libyuv.gni | 2 ++
media/libyuv/libyuv/libyuv.gypi | 5 +++
media/libyuv/libyuv/source/row_lasx.cc | 46 ++++++++++++++++----------
media/libyuv/libyuv/source/row_lsx.cc | 30 +++++++++++------
5 files changed, 92 insertions(+), 28 deletions(-)
diff --git a/media/libyuv/libyuv/BUILD.gn b/media/libyuv/libyuv/BUILD.gn
index a72ff06558..7d70848be9 100644
--- a/media/libyuv/libyuv/BUILD.gn
+++ b/media/libyuv/libyuv/BUILD.gn
@@ -69,6 +69,14 @@ group("libyuv") {
deps += [ ":libyuv_msa" ]
}
+ if (libyuv_use_lsx) {
+ deps += [ ":libyuv_lsx" ]
+ }
+
+ if (libyuv_use_lasx) {
+ deps += [ ":libyuv_lasx" ]
+ }
+
if (!is_ios && !libyuv_disable_jpeg) {
# Make sure that clients of libyuv link with libjpeg. This can't go in
# libyuv_internal because in Windows x64 builds that will generate a clang
@@ -90,6 +98,7 @@ static_library("libyuv_internal") {
"include/libyuv/convert_from.h",
"include/libyuv/convert_from_argb.h",
"include/libyuv/cpu_id.h",
+ "include/libyuv/loongson_intrinsics.h",
"include/libyuv/mjpeg_decoder.h",
"include/libyuv/planar_functions.h",
"include/libyuv/rotate.h",
@@ -229,6 +238,34 @@ if (libyuv_use_msa) {
}
}
+if (libyuv_use_lsx) {
+ static_library("libyuv_lsx") {
+ sources = [
+ # LSX Source Files
+ "source/rotate_lsx.cc",
+ "source/row_lsx.cc",
+ "source/scale_lsx.cc",
+ ]
+
+ deps = [ ":libyuv_internal" ]
+
+ public_configs = [ ":libyuv_config" ]
+ }
+}
+
+if (libyuv_use_lasx) {
+ static_library("libyuv_lasx") {
+ sources = [
+ # LASX Source Files
+ "source/row_lasx.cc",
+ ]
+
+ deps = [ ":libyuv_internal" ]
+
+ public_configs = [ ":libyuv_config" ]
+ }
+}
+
if (libyuv_include_tests) {
config("libyuv_unittest_warnings_config") {
if (!is_win) {
diff --git a/media/libyuv/libyuv/libyuv.gni b/media/libyuv/libyuv/libyuv.gni
index 852f08ca9d..8e5bd40e4e 100644
--- a/media/libyuv/libyuv/libyuv.gni
+++ b/media/libyuv/libyuv/libyuv.gni
@@ -20,4 +20,6 @@ declare_args() {
(current_cpu == "mips64el" || current_cpu == "mipsel") && mips_use_msa
libyuv_use_mmi =
(current_cpu == "mips64el" || current_cpu == "mipsel") && mips_use_mmi
+ libyuv_use_lsx = current_cpu == "loong64"
+ libyuv_use_lasx = current_cpu == "loong64"
}
diff --git a/media/libyuv/libyuv/libyuv.gypi b/media/libyuv/libyuv/libyuv.gypi
index 48936aa7b0..9c19abf9c3 100644
--- a/media/libyuv/libyuv/libyuv.gypi
+++ b/media/libyuv/libyuv/libyuv.gypi
@@ -18,6 +18,7 @@
'include/libyuv/convert_from.h',
'include/libyuv/convert_from_argb.h',
'include/libyuv/cpu_id.h',
+ 'include/libyuv/loongson_intrinsics.h',
'include/libyuv/macros_msa.h',
'include/libyuv/mjpeg_decoder.h',
'include/libyuv/planar_functions.h',
@@ -57,6 +58,7 @@
'source/rotate_argb.cc',
'source/rotate_common.cc',
'source/rotate_gcc.cc',
+ 'source/rotate_lsx.cc',
'source/rotate_msa.cc',
'source/rotate_neon.cc',
'source/rotate_neon64.cc',
@@ -64,6 +66,8 @@
'source/row_any.cc',
'source/row_common.cc',
'source/row_gcc.cc',
+ 'source/row_lasx.cc',
+ 'source/row_lsx.cc',
'source/row_msa.cc',
'source/row_neon.cc',
'source/row_neon64.cc',
@@ -73,6 +77,7 @@
'source/scale_argb.cc',
'source/scale_common.cc',
'source/scale_gcc.cc',
+ 'source/scale_lsx.cc',
'source/scale_msa.cc',
'source/scale_neon.cc',
'source/scale_neon64.cc',
diff --git a/media/libyuv/libyuv/source/row_lasx.cc b/media/libyuv/libyuv/source/row_lasx.cc
index 29ac9254d9..8c325483b1 100644
--- a/media/libyuv/libyuv/source/row_lasx.cc
+++ b/media/libyuv/libyuv/source/row_lasx.cc
@@ -543,8 +543,8 @@ void I422ToARGB4444Row_LASX(const uint8_t* src_y,
__m256i vec_yb, vec_yg, vec_ub, vec_vr, vec_ug, vec_vg;
__m256i vec_ubvr, vec_ugvg;
__m256i const_0x80 = __lasx_xvldi(0x80);
- __m256i alpha = {0xF000F000F000F000, 0xF000F000F000F000, 0xF000F000F000F000,
- 0xF000F000F000F000};
+ __m256i alpha = {static_cast<long long>(0xF000F000F000F000), static_cast<long long>(0xF000F000F000F000), static_cast<long long>(0xF000F000F000F000),
+ static_cast<long long>(0xF000F000F000F000)};
__m256i mask = {0x00F000F000F000F0, 0x00F000F000F000F0, 0x00F000F000F000F0,
0x00F000F000F000F0};
@@ -595,8 +595,8 @@ void I422ToARGB1555Row_LASX(const uint8_t* src_y,
__m256i vec_yb, vec_yg, vec_ub, vec_vr, vec_ug, vec_vg;
__m256i vec_ubvr, vec_ugvg;
__m256i const_0x80 = __lasx_xvldi(0x80);
- __m256i alpha = {0x8000800080008000, 0x8000800080008000, 0x8000800080008000,
- 0x8000800080008000};
+ __m256i alpha = {static_cast<long long>(0x8000800080008000), static_cast<long long>(0x8000800080008000), static_cast<long long>(0x8000800080008000),
+ static_cast<long long>(0x8000800080008000)};
YUVTORGB_SETUP(yuvconstants, vec_ub, vec_vr, vec_ug, vec_vg, vec_yg, vec_yb);
vec_ubvr = __lasx_xvilvl_h(vec_ub, vec_vr);
@@ -799,8 +799,8 @@ void ARGBToUVRow_LASX(const uint8_t* src_argb0,
0x0009000900090009, 0x0009000900090009};
__m256i control = {0x0000000400000000, 0x0000000500000001, 0x0000000600000002,
0x0000000700000003};
- __m256i const_0x8080 = {0x8080808080808080, 0x8080808080808080,
- 0x8080808080808080, 0x8080808080808080};
+ __m256i const_0x8080 = {static_cast<long long>(0x8080808080808080), static_cast<long long>(0x8080808080808080),
+ static_cast<long long>(0x8080808080808080), static_cast<long long>(0x8080808080808080)};
for (x = 0; x < len; x++) {
DUP4_ARG2(__lasx_xvld, src_argb0, 0, src_argb0, 32, src_argb0, 64,
@@ -1037,8 +1037,8 @@ void ARGBToUV444Row_LASX(const uint8_t* src_argb,
__m256i const_38 = __lasx_xvldi(38);
__m256i const_94 = __lasx_xvldi(94);
__m256i const_18 = __lasx_xvldi(18);
- __m256i const_0x8080 = {0x8080808080808080, 0x8080808080808080,
- 0x8080808080808080, 0x8080808080808080};
+ __m256i const_0x8080 = {static_cast<long long>(0x8080808080808080), static_cast<long long>(0x8080808080808080),
+ static_cast<long long>(0x8080808080808080), static_cast<long long>(0x8080808080808080)};
__m256i control = {0x0000000400000000, 0x0000000500000001, 0x0000000600000002,
0x0000000700000003};
for (x = 0; x < len; x++) {
@@ -1609,8 +1609,8 @@ void ARGB1555ToUVRow_LASX(const uint8_t* src_argb1555,
__m256i const_38 = __lasx_xvldi(0x413);
__m256i const_94 = __lasx_xvldi(0x42F);
__m256i const_18 = __lasx_xvldi(0x409);
- __m256i const_8080 = {0x8080808080808080, 0x8080808080808080,
- 0x8080808080808080, 0x8080808080808080};
+ __m256i const_8080 = {static_cast<long long>(0x8080808080808080), static_cast<long long>(0x8080808080808080),
+ static_cast<long long>(0x8080808080808080), static_cast<long long>(0x8080808080808080)};
for (x = 0; x < len; x++) {
DUP4_ARG2(__lasx_xvld, src_argb1555, 0, src_argb1555, 32, next_argb1555, 0,
@@ -1726,8 +1726,8 @@ void RGB565ToUVRow_LASX(const uint8_t* src_rgb565,
__m256i const_38 = __lasx_xvldi(0x413);
__m256i const_94 = __lasx_xvldi(0x42F);
__m256i const_18 = __lasx_xvldi(0x409);
- __m256i const_8080 = {0x8080808080808080, 0x8080808080808080,
- 0x8080808080808080, 0x8080808080808080};
+ __m256i const_8080 = {static_cast<long long>(0x8080808080808080), static_cast<long long>(0x8080808080808080),
+ static_cast<long long>(0x8080808080808080), static_cast<long long>(0x8080808080808080)};
for (x = 0; x < len; x++) {
DUP4_ARG2(__lasx_xvld, src_rgb565, 0, src_rgb565, 32, next_rgb565, 0,
@@ -1793,8 +1793,8 @@ void RGB24ToUVRow_LASX(const uint8_t* src_rgb24,
__m256i const_38 = __lasx_xvldi(0x413);
__m256i const_94 = __lasx_xvldi(0x42F);
__m256i const_18 = __lasx_xvldi(0x409);
- __m256i const_8080 = {0x8080808080808080, 0x8080808080808080,
- 0x8080808080808080, 0x8080808080808080};
+ __m256i const_8080 = {static_cast<long long>(0x8080808080808080), static_cast<long long>(0x8080808080808080),
+ static_cast<long long>(0x8080808080808080), static_cast<long long>(0x8080808080808080)};
__m256i shuff0_b = {0x15120F0C09060300, 0x00000000001E1B18,
0x15120F0C09060300, 0x00000000001E1B18};
__m256i shuff1_b = {0x0706050403020100, 0x1D1A1714110A0908,
@@ -1856,8 +1856,8 @@ void RAWToUVRow_LASX(const uint8_t* src_raw,
__m256i const_38 = __lasx_xvldi(0x413);
__m256i const_94 = __lasx_xvldi(0x42F);
__m256i const_18 = __lasx_xvldi(0x409);
- __m256i const_8080 = {0x8080808080808080, 0x8080808080808080,
- 0x8080808080808080, 0x8080808080808080};
+ __m256i const_8080 = {static_cast<long long>(0x8080808080808080), static_cast<long long>(0x8080808080808080),
+ static_cast<long long>(0x8080808080808080), static_cast<long long>(0x8080808080808080)};
__m256i shuff0_r = {0x15120F0C09060300, 0x00000000001E1B18,
0x15120F0C09060300, 0x00000000001E1B18};
__m256i shuff1_r = {0x0706050403020100, 0x1D1A1714110A0908,
@@ -2000,11 +2000,13 @@ void NV21ToARGBRow_LASX(const uint8_t* src_y,
}
}
+#ifndef RgbConstants
struct RgbConstants {
uint8_t kRGBToY[4];
uint16_t kAddY;
uint16_t pad;
};
+#define RgbConstants RgbConstants
// RGB to JPeg coefficients
// B * 0.1140 coefficient = 29
@@ -2030,6 +2032,7 @@ static const struct RgbConstants kRgb24I601Constants = {{25, 129, 66, 0},
static const struct RgbConstants kRawI601Constants = {{66, 129, 25, 0},
0x1080,
0};
+#endif // RgbConstaints
// ARGB expects first 3 values to contain RGB and 4th value is ignored.
static void ARGBToYMatrixRow_LASX(const uint8_t* src_argb,
@@ -2242,8 +2245,8 @@ void ARGBToUVJRow_LASX(const uint8_t* src_argb,
__m256i const_21 = __lasx_xvldi(0x415);
__m256i const_53 = __lasx_xvldi(0x435);
__m256i const_10 = __lasx_xvldi(0x40A);
- __m256i const_8080 = {0x8080808080808080, 0x8080808080808080,
- 0x8080808080808080, 0x8080808080808080};
+ __m256i const_8080 = {static_cast<long long>(0x8080808080808080), static_cast<long long>(0x8080808080808080),
+ static_cast<long long>(0x8080808080808080), static_cast<long long>(0x8080808080808080)};
__m256i shuff = {0x1614060412100200, 0x1E1C0E0C1A180A08, 0x1715070513110301,
0x1F1D0F0D1B190B09};
@@ -2296,6 +2299,13 @@ void ARGBToUVJRow_LASX(const uint8_t* src_argb,
}
}
+// undef for unified sources build
+#undef YUVTORGB_SETUP
+#undef YUVTORGB
+#undef I444TORGB
+#undef STOREARGB
+#undef RGBTOUV
+
#ifdef __cplusplus
} // extern "C"
} // namespace libyuv
diff --git a/media/libyuv/libyuv/source/row_lsx.cc b/media/libyuv/libyuv/source/row_lsx.cc
index 9c1e16f22e..91221ff03c 100644
--- a/media/libyuv/libyuv/source/row_lsx.cc
+++ b/media/libyuv/libyuv/source/row_lsx.cc
@@ -407,7 +407,7 @@ void ARGB1555ToUVRow_LSX(const uint8_t* src_argb1555,
__m128i const_38 = __lsx_vldi(0x413);
__m128i const_94 = __lsx_vldi(0x42F);
__m128i const_18 = __lsx_vldi(0x409);
- __m128i const_8080 = {0x8080808080808080, 0x8080808080808080};
+ __m128i const_8080 = {static_cast<long long>(0x8080808080808080), static_cast<long long>(0x8080808080808080)};
for (x = 0; x < len; x++) {
DUP4_ARG2(__lsx_vld, src_argb1555, 0, src_argb1555, 16, next_argb1555, 0,
@@ -516,7 +516,7 @@ void RGB565ToUVRow_LSX(const uint8_t* src_rgb565,
__m128i const_38 = __lsx_vldi(0x413);
__m128i const_94 = __lsx_vldi(0x42F);
__m128i const_18 = __lsx_vldi(0x409);
- __m128i const_8080 = {0x8080808080808080, 0x8080808080808080};
+ __m128i const_8080 = {static_cast<long long>(0x8080808080808080), static_cast<long long>(0x8080808080808080)};
for (x = 0; x < len; x++) {
DUP4_ARG2(__lsx_vld, src_rgb565, 0, src_rgb565, 16, next_rgb565, 0,
@@ -577,7 +577,7 @@ void RGB24ToUVRow_LSX(const uint8_t* src_rgb24,
__m128i const_38 = __lsx_vldi(0x413);
__m128i const_94 = __lsx_vldi(0x42F);
__m128i const_18 = __lsx_vldi(0x409);
- __m128i const_8080 = {0x8080808080808080, 0x8080808080808080};
+ __m128i const_8080 = {static_cast<long long>(0x8080808080808080), static_cast<long long>(0x8080808080808080)};
__m128i shuff0_b = {0x15120F0C09060300, 0x00000000001E1B18};
__m128i shuff1_b = {0x0706050403020100, 0x1D1A1714110A0908};
__m128i shuff0_g = {0x1613100D0A070401, 0x00000000001F1C19};
@@ -630,7 +630,7 @@ void RAWToUVRow_LSX(const uint8_t* src_raw,
__m128i const_38 = __lsx_vldi(0x413);
__m128i const_94 = __lsx_vldi(0x42F);
__m128i const_18 = __lsx_vldi(0x409);
- __m128i const_8080 = {0x8080808080808080, 0x8080808080808080};
+ __m128i const_8080 = {static_cast<long long>(0x8080808080808080), static_cast<long long>(0x8080808080808080)};
__m128i shuff0_r = {0x15120F0C09060300, 0x00000000001E1B18};
__m128i shuff1_r = {0x0706050403020100, 0x1D1A1714110A0908};
__m128i shuff0_g = {0x1613100D0A070401, 0x00000000001F1C19};
@@ -865,7 +865,7 @@ void BGRAToUVRow_LSX(const uint8_t* src_bgra,
__m128i const_38 = __lsx_vldi(0x413);
__m128i const_94 = __lsx_vldi(0x42F);
__m128i const_18 = __lsx_vldi(0x409);
- __m128i const_8080 = {0x8080808080808080, 0x8080808080808080};
+ __m128i const_8080 = {static_cast<long long>(0x8080808080808080), static_cast<long long>(0x8080808080808080)};
for (x = 0; x < len; x++) {
DUP4_ARG2(__lsx_vld, src_bgra, 0, src_bgra, 16, src_bgra, 32, src_bgra, 48,
@@ -913,7 +913,7 @@ void ABGRToUVRow_LSX(const uint8_t* src_abgr,
__m128i const_38 = __lsx_vldi(0x413);
__m128i const_94 = __lsx_vldi(0x42F);
__m128i const_18 = __lsx_vldi(0x409);
- __m128i const_8080 = {0x8080808080808080, 0x8080808080808080};
+ __m128i const_8080 = {static_cast<long long>(0x8080808080808080), static_cast<long long>(0x8080808080808080)};
for (x = 0; x < len; x++) {
DUP4_ARG2(__lsx_vld, src_abgr, 0, src_abgr, 16, src_abgr, 32, src_abgr, 48,
@@ -961,7 +961,7 @@ void RGBAToUVRow_LSX(const uint8_t* src_rgba,
__m128i const_38 = __lsx_vldi(0x413);
__m128i const_94 = __lsx_vldi(0x42F);
__m128i const_18 = __lsx_vldi(0x409);
- __m128i const_8080 = {0x8080808080808080, 0x8080808080808080};
+ __m128i const_8080 = {static_cast<long long>(0x8080808080808080), static_cast<long long>(0x8080808080808080)};
for (x = 0; x < len; x++) {
DUP4_ARG2(__lsx_vld, src_rgba, 0, src_rgba, 16, src_rgba, 32, src_rgba, 48,
@@ -1010,7 +1010,7 @@ void ARGBToUVJRow_LSX(const uint8_t* src_argb,
__m128i const_21 = __lsx_vldi(0x415);
__m128i const_53 = __lsx_vldi(0x435);
__m128i const_10 = __lsx_vldi(0x40A);
- __m128i const_8080 = {0x8080808080808080, 0x8080808080808080};
+ __m128i const_8080 = {static_cast<long long>(0x8080808080808080), static_cast<long long>(0x8080808080808080)};
for (x = 0; x < len; x++) {
DUP4_ARG2(__lsx_vld, src_argb, 0, src_argb, 16, src_argb, 32, src_argb, 48,
@@ -1388,7 +1388,7 @@ void ARGBBlendRow_LSX(const uint8_t* src_argb,
__m128i const_256 = __lsx_vldi(0x500);
__m128i zero = __lsx_vldi(0);
__m128i alpha = __lsx_vldi(0xFF);
- __m128i control = {0xFF000000FF000000, 0xFF000000FF000000};
+ __m128i control = {static_cast<long long>(0xFF000000FF000000), static_cast<long long>(0xFF000000FF000000)};
for (x = 0; x < len; x++) {
DUP4_ARG2(__lsx_vld, src_argb, 0, src_argb, 16, src_argb1, 0, src_argb1, 16,
@@ -1434,7 +1434,7 @@ void ARGBQuantizeRow_LSX(uint8_t* dst_argb,
__m128i vec_offset = __lsx_vreplgr2vr_b(interval_offset);
__m128i vec_scale = __lsx_vreplgr2vr_w(scale);
__m128i zero = __lsx_vldi(0);
- __m128i control = {0xFF000000FF000000, 0xFF000000FF000000};
+ __m128i control = {static_cast<long long>(0xFF000000FF000000), static_cast<long long>(0xFF000000FF000000)};
for (x = 0; x < len; x++) {
DUP4_ARG2(__lsx_vld, dst_argb, 0, dst_argb, 16, dst_argb, 32, dst_argb, 48,
@@ -1643,11 +1643,13 @@ void HalfFloatRow_LSX(const uint16_t* src,
}
}
+#ifndef RgbConstants
struct RgbConstants {
uint8_t kRGBToY[4];
uint16_t kAddY;
uint16_t pad;
};
+#define RgbConstants RgbConstants
// RGB to JPeg coefficients
// B * 0.1140 coefficient = 29
@@ -1673,6 +1675,7 @@ static const struct RgbConstants kRgb24I601Constants = {{25, 129, 66, 0},
static const struct RgbConstants kRawI601Constants = {{66, 129, 25, 0},
0x1080,
0};
+#endif // RgbConstaints
// ARGB expects first 3 values to contain RGB and 4th value is ignored.
static void ARGBToYMatrixRow_LSX(const uint8_t* src_argb,
@@ -1853,6 +1856,13 @@ void RAWToYRow_LSX(const uint8_t* src_raw, uint8_t* dst_y, int width) {
RGBToYMatrixRow_LSX(src_raw, dst_y, width, &kRawI601Constants);
}
+// undef for unified sources build
+#undef YUVTORGB_SETUP
+#undef YUVTORGB
+#undef I444TORGB
+#undef STOREARGB
+#undef RGBTOUV
+
#ifdef __cplusplus
} // extern "C"
} // namespace libyuv
--
2.45.0