commit: 3689bc25e032bc741fa51924a36b7e98dec09d59
Author: Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Mon Jun 16 17:30:36 2025 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Jun 16 17:31:23 2025 +0000
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=3689bc25
media-libs/faac: backport fix for unaligned access
There's some fixes in 1.31.1 already (which is actually why I looked
for a bump to begin with, as I noticed GPFs in dmesg when arch testing)
but there's this as well in master post-tag.
Signed-off-by: Sam James <sam <AT> gentoo.org>
.../{faac-1.31.1.ebuild => faac-1.31.1-r1.ebuild} | 4 ++
media-libs/faac/files/faac-1.31.1-unaligned.patch | 78 ++++++++++++++++++++++
2 files changed, 82 insertions(+)
diff --git a/media-libs/faac/faac-1.31.1.ebuild
b/media-libs/faac/faac-1.31.1-r1.ebuild
similarity index 94%
rename from media-libs/faac/faac-1.31.1.ebuild
rename to media-libs/faac/faac-1.31.1-r1.ebuild
index fba2fd8b44fa..4c00c177fa5d 100644
--- a/media-libs/faac/faac-1.31.1.ebuild
+++ b/media-libs/faac/faac-1.31.1-r1.ebuild
@@ -14,6 +14,10 @@ LICENSE="LGPL-2.1 MPEG-4"
SLOT="0"
KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~loong ~mips ~ppc ~ppc64 ~riscv
~sparc ~x86 ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos"
+PATCHES=(
+ "${FILESDIR}"/${P}-unaligned.patch
+)
+
src_prepare() {
default
eautoreconf
diff --git a/media-libs/faac/files/faac-1.31.1-unaligned.patch
b/media-libs/faac/files/faac-1.31.1-unaligned.patch
new file mode 100644
index 000000000000..49a4b2072b55
--- /dev/null
+++ b/media-libs/faac/files/faac-1.31.1-unaligned.patch
@@ -0,0 +1,78 @@
+https://github.com/knik0/faac/commit/cb10c59666a3631547a9037c1576a34d8ca52df1
+
+From cb10c59666a3631547a9037c1576a34d8ca52df1 Mon Sep 17 00:00:00 2001
+From: enWILLYado <[email protected]>
+Date: Mon, 2 Jun 2025 16:40:03 +0200
+Subject: [PATCH] Fix SIMD calls (#59)
+
+* Fix SIMD calls
+
+Fast SIMD calls and secure align for result.
+
+* Update quantize.c
+
+Potential unaligned memory location.
+
+* Update quantize.c
+
+Only fix unaligned memory access.
+---
+ libfaac/quantize.c | 24 ++++++++++++++++++++----
+ 1 file changed, 20 insertions(+), 4 deletions(-)
+
+diff --git a/libfaac/quantize.c b/libfaac/quantize.c
+index 870737a..02586c9 100644
+--- a/libfaac/quantize.c
++++ b/libfaac/quantize.c
+@@ -40,6 +40,19 @@
+ # define bit_SSE2 (1 << 26)
+ #endif
+
++#ifdef __SSE2__
++#ifdef _MSC_VER /* visual c++ */
++#define ALIGN16_BEG __declspec(align(16))
++#define ALIGN16_END
++#else /* gcc or icc */
++#define ALIGN16_BEG
++#define ALIGN16_END __attribute__((aligned(16)))
++#endif
++#else
++#define ALIGN16_BEG
++#define ALIGN16_END
++#endif
++
+ #ifdef __GNUC__
+ #define GCC_VERSION (__GNUC__ * 10000 \
+ + __GNUC_MINOR__ * 100 \
+@@ -182,7 +195,7 @@ static void qlevel(CoderInfo *coderInfo,
+ int sfac;
+ double rmsx;
+ double etot;
+- int xitab[8 * MAXSHORTBAND];
++ int ALIGN16_BEG xitab[8 * MAXSHORTBAND] ALIGN16_END;
+ int *xi;
+ int start, end;
+ const double *xr;
+@@ -242,15 +255,18 @@ static void qlevel(CoderInfo *coderInfo,
+ #ifdef __SSE2__
+ if (sse2)
+ {
++ const __m128 zero = _mm_setzero_ps();
++ const __m128 sfac = _mm_set1_ps(sfacfix);
++ const __m128 magic = _mm_set1_ps(MAGIC_NUMBER);
+ for (cnt = 0; cnt < end; cnt += 4)
+ {
+ __m128 x = {xr[cnt], xr[cnt + 1], xr[cnt + 2], xr[cnt + 3]};
+
+- x = _mm_max_ps(x, _mm_sub_ps((__m128){0, 0, 0, 0}, x));
+- x = _mm_mul_ps(x, (__m128){sfacfix, sfacfix, sfacfix,
sfacfix});
++ x = _mm_max_ps(x, _mm_sub_ps(zero, x));
++ x = _mm_mul_ps(x, sfac);
+ x = _mm_mul_ps(x, _mm_sqrt_ps(x));
+ x = _mm_sqrt_ps(x);
+- x = _mm_add_ps(x, (__m128){MAGIC_NUMBER, MAGIC_NUMBER,
MAGIC_NUMBER, MAGIC_NUMBER});
++ x = _mm_add_ps(x, magic);
+
+ *(__m128i*)(xi + cnt) = _mm_cvttps_epi32(x);
+ }
+