From 8d6ed4c45f576dbf8e242c26238d6c8dab81a888 Mon Sep 17 00:00:00 2001 From: Paul Adenot Date: Fri, 29 Nov 2024 08:21:12 +0000 Subject: [PATCH] Bug 1921862 - Refresh and reappply the patch on top of libaom. r=media-playback-reviewers,aosmond Differential Revision: https://phabricator.services.mozilla.com/D230507 --- media/libaom/mmloadusi64.patch | 50 ++++++++++----------- third_party/aom/aom_dsp/x86/synonyms.h | 11 +++++ third_party/aom/aom_dsp/x86/synonyms_avx2.h | 15 +++++++ 3 files changed, 51 insertions(+), 25 deletions(-) diff --git a/media/libaom/mmloadusi64.patch b/media/libaom/mmloadusi64.patch index adf2a84d0bc4..0126b611c1e7 100644 --- a/media/libaom/mmloadusi64.patch +++ b/media/libaom/mmloadusi64.patch @@ -1,19 +1,19 @@ diff --git a/aom_dsp/x86/synonyms.h b/aom_dsp/x86/synonyms.h --- a/aom_dsp/x86/synonyms.h +++ b/aom_dsp/x86/synonyms.h -@@ -41,23 +41,34 @@ static INLINE __m128i xx_loadl_64(const void *a) { - static INLINE __m128i xx_load_128(const void *a) { +@@ -41,23 +41,34 @@ static inline __m128i xx_loadl_64(const + static inline __m128i xx_load_128(const void *a) { return _mm_load_si128((const __m128i *)a); } - - static INLINE __m128i xx_loadu_128(const void *a) { + + static inline __m128i xx_loadu_128(const void *a) { return _mm_loadu_si128((const __m128i *)a); } - + +// _mm_loadu_si64 has been introduced in GCC 9, reimplement the function +// manually on older compilers. +#if !defined(__clang__) && __GNUC_MAJOR__ < 9 -+static INLINE __m128i xx_loadu_2x64(const void *hi, const void *lo) { ++static inline __m128i xx_loadu_2x64(const void *hi, const void *lo) { + __m64 hi_, lo_; + memcpy(&hi_, hi, sizeof(hi_)); + memcpy(&lo_, lo, sizeof(lo_)); @@ -23,44 +23,44 @@ diff --git a/aom_dsp/x86/synonyms.h b/aom_dsp/x86/synonyms.h // Load 64 bits from each of hi and low, and pack into an SSE register // Since directly loading as `int64_t`s and using _mm_set_epi64 may violate // the strict aliasing rule, this takes a different approach - static INLINE __m128i xx_loadu_2x64(const void *hi, const void *lo) { + static inline __m128i xx_loadu_2x64(const void *hi, const void *lo) { return _mm_unpacklo_epi64(_mm_loadl_epi64((const __m128i *)lo), _mm_loadl_epi64((const __m128i *)hi)); } +#endif - - static INLINE void xx_storel_32(void *const a, const __m128i v) { + + static inline void xx_storel_32(void *const a, const __m128i v) { const int val = _mm_cvtsi128_si32(v); memcpy(a, &val, sizeof(val)); } - - static INLINE void xx_storel_64(void *const a, const __m128i v) { + + static inline void xx_storel_64(void *const a, const __m128i v) { _mm_storel_epi64((__m128i *)a, v); diff --git a/aom_dsp/x86/synonyms_avx2.h b/aom_dsp/x86/synonyms_avx2.h --- a/aom_dsp/x86/synonyms_avx2.h +++ b/aom_dsp/x86/synonyms_avx2.h -@@ -55,21 +55,36 @@ static INLINE __m256i yy_set2_epi16(int16_t a, int16_t b) { - - // Some compilers don't have _mm256_set_m128i defined in immintrin.h. We - // therefore define an equivalent function using a different intrinsic. - // ([ hi ], [ lo ]) -> [ hi ][ lo ] - static INLINE __m256i yy_set_m128i(__m128i hi, __m128i lo) { - return _mm256_insertf128_si256(_mm256_castsi128_si256(lo), hi, 1); +@@ -71,21 +71,36 @@ static inline __m256i yy_loadu_4x64(cons + __m128d v23 = _mm_loadh_pd(v2, (const double *)e3); + // Note this can be replaced with + // `_mm256_castpd_si256(_mm256_set_m128d(v23, v01))` if immintrin.h contains + // _mm256_set_m128d() with all supported compilers. This version is used to + // match the behavior with yy_set_m128i(). + return yy_set_m128i(_mm_castpd_si128(v23), _mm_castpd_si128(v01)); } - + +#define GCC_VERSION (__GNUC__ * 10000 \ + + __GNUC_MINOR__ * 100 \ + + __GNUC_PATCHLEVEL__) + +// _mm256_loadu2_m128i has been introduced in GCC 10.1 +#if !defined(__clang__) && GCC_VERSION < 101000 -+static INLINE __m256i yy_loadu2_128(const void *hi, const void *lo) { ++static inline __m256i yy_loadu2_128(const void *hi, const void *lo) { + __m128i mhi = _mm_loadu_si128((const __m128i *)(hi)); + __m128i mlo = _mm_loadu_si128((const __m128i *)(lo)); + return _mm256_set_m128i(mhi, mlo); +} +#else - static INLINE __m256i yy_loadu2_128(const void *hi, const void *lo) { + static inline __m256i yy_loadu2_128(const void *hi, const void *lo) { __m128i mhi = _mm_loadu_si128((const __m128i *)(hi)); __m128i mlo = _mm_loadu_si128((const __m128i *)(lo)); return yy_set_m128i(mhi, mlo); @@ -68,11 +68,11 @@ diff --git a/aom_dsp/x86/synonyms_avx2.h b/aom_dsp/x86/synonyms_avx2.h +#endif + +#undef GCC_VERSION - - static INLINE void yy_storeu2_128(void *hi, void *lo, const __m256i a) { + + static inline void yy_storeu2_128(void *hi, void *lo, const __m256i a) { _mm_storeu_si128((__m128i *)hi, _mm256_extracti128_si256(a, 1)); _mm_storeu_si128((__m128i *)lo, _mm256_castsi256_si128(a)); } - - static INLINE __m256i yy_roundn_epu16(__m256i v_val_w, int bits) { + + static inline __m256i yy_roundn_epu16(__m256i v_val_w, int bits) { const __m256i v_s_w = _mm256_srli_epi16(v_val_w, bits - 1); diff --git a/third_party/aom/aom_dsp/x86/synonyms.h b/third_party/aom/aom_dsp/x86/synonyms.h index 0f829821a996..bbaa0a0c4818 100644 --- a/third_party/aom/aom_dsp/x86/synonyms.h +++ b/third_party/aom/aom_dsp/x86/synonyms.h @@ -46,6 +46,16 @@ static inline __m128i xx_loadu_128(const void *a) { return _mm_loadu_si128((const __m128i *)a); } +// _mm_loadu_si64 has been introduced in GCC 9, reimplement the function +// manually on older compilers. +#if !defined(__clang__) && __GNUC_MAJOR__ < 9 +static inline __m128i xx_loadu_2x64(const void *hi, const void *lo) { + __m64 hi_, lo_; + memcpy(&hi_, hi, sizeof(hi_)); + memcpy(&lo_, lo, sizeof(lo_)); + return _mm_set_epi64(hi_, lo_); +} +#else // Load 64 bits from each of hi and low, and pack into an SSE register // Since directly loading as `int64_t`s and using _mm_set_epi64 may violate // the strict aliasing rule, this takes a different approach @@ -53,6 +63,7 @@ static inline __m128i xx_loadu_2x64(const void *hi, const void *lo) { return _mm_unpacklo_epi64(_mm_loadl_epi64((const __m128i *)lo), _mm_loadl_epi64((const __m128i *)hi)); } +#endif static inline void xx_storel_32(void *const a, const __m128i v) { const int val = _mm_cvtsi128_si32(v); diff --git a/third_party/aom/aom_dsp/x86/synonyms_avx2.h b/third_party/aom/aom_dsp/x86/synonyms_avx2.h index 20e6a4b23a04..5b8a79f8c445 100644 --- a/third_party/aom/aom_dsp/x86/synonyms_avx2.h +++ b/third_party/aom/aom_dsp/x86/synonyms_avx2.h @@ -76,11 +76,26 @@ static inline __m256i yy_loadu_4x64(const void *e3, const void *e2, return yy_set_m128i(_mm_castpd_si128(v23), _mm_castpd_si128(v01)); } +#define GCC_VERSION (__GNUC__ * 10000 \ + + __GNUC_MINOR__ * 100 \ + + __GNUC_PATCHLEVEL__) + +// _mm256_loadu2_m128i has been introduced in GCC 10.1 +#if !defined(__clang__) && GCC_VERSION < 101000 +static inline __m256i yy_loadu2_128(const void *hi, const void *lo) { + __m128i mhi = _mm_loadu_si128((const __m128i *)(hi)); + __m128i mlo = _mm_loadu_si128((const __m128i *)(lo)); + return _mm256_set_m128i(mhi, mlo); +} +#else static inline __m256i yy_loadu2_128(const void *hi, const void *lo) { __m128i mhi = _mm_loadu_si128((const __m128i *)(hi)); __m128i mlo = _mm_loadu_si128((const __m128i *)(lo)); return yy_set_m128i(mhi, mlo); } +#endif + +#undef GCC_VERSION static inline void yy_storeu2_128(void *hi, void *lo, const __m256i a) { _mm_storeu_si128((__m128i *)hi, _mm256_extracti128_si256(a, 1));