[FFmpeg-devel] [PATCH 2/3] avutil/mem_internal: define DECLARE_ALIGNED as C11's _Alignas

Rémi Denis-Courmont remi at remlab.net
Fri Nov 15 15:47:36 EET 2024



Le 15 novembre 2024 12:56:23 GMT+02:00, Zhao Zhili <quinkblack at foxmail.com> a écrit :
>From: Zhao Zhili <zhilizhao at tencent.com>
>
>_Alignas is portable than compiler's specific __attribute__. It do
>have a limitation, that _Alignas don't support specify aligment on
>the declarations of struct (it works for specify alignment on struct
>fields),
> which only used by avcodec/cavs, and is removed now.

IIRC, _Alignas() is deprecated by C23. Can't we use the proper c11/c23 alignas() instead?

>---
> libavutil/mem_internal.h | 26 +++++++-------------------
> 1 file changed, 7 insertions(+), 19 deletions(-)
>
>diff --git a/libavutil/mem_internal.h b/libavutil/mem_internal.h
>index 20f9b3e3f2..b77157bfa0 100644
>--- a/libavutil/mem_internal.h
>+++ b/libavutil/mem_internal.h
>@@ -73,26 +73,14 @@
>  * @param v Name of the variable
>  */
> 
>-#if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1110 || defined(__SUNPRO_C)
>-    #define DECLARE_ALIGNED_T(n,t,v)    t __attribute__ ((aligned (n))) v
>-    #define DECLARE_ASM_ALIGNED(n,t,v)  t __attribute__ ((aligned (n))) v
>-    #define DECLARE_ASM_CONST(n,t,v)    const t __attribute__ ((aligned (n))) v
>-#elif defined(__DJGPP__)
>-    #define DECLARE_ALIGNED_T(n,t,v)    t __attribute__ ((aligned (FFMIN(n, 16)))) v
>-    #define DECLARE_ASM_ALIGNED(n,t,v)  t av_used __attribute__ ((aligned (FFMIN(n, 16)))) v
>-    #define DECLARE_ASM_CONST(n,t,v)    static const t av_used __attribute__ ((aligned (FFMIN(n, 16)))) v
>-#elif defined(__GNUC__) || defined(__clang__)
>-    #define DECLARE_ALIGNED_T(n,t,v)    t __attribute__ ((aligned (n))) v
>-    #define DECLARE_ASM_ALIGNED(n,t,v)  t av_used __attribute__ ((aligned (n))) v
>-    #define DECLARE_ASM_CONST(n,t,v)    static const t av_used __attribute__ ((aligned (n))) v
>-#elif defined(_MSC_VER)
>-    #define DECLARE_ALIGNED_T(n,t,v)    __declspec(align(n)) t v
>-    #define DECLARE_ASM_ALIGNED(n,t,v)  __declspec(align(n)) t v
>-    #define DECLARE_ASM_CONST(n,t,v)    __declspec(align(n)) static const t v
>+#if defined(__DJGPP__)
>+    #define DECLARE_ALIGNED_T(n,t,v)    _Alignas(FFMIN(n, 16)) t v
>+    #define DECLARE_ASM_ALIGNED(n,t,v)  _Alignas(FFMIN(n, 16)) t av_used v
>+    #define DECLARE_ASM_CONST(n,t,v)    _Alignas(FFMIN(n, 16)) static const t av_used v
> #else
>-    #define DECLARE_ALIGNED_T(n,t,v)    t v
>-    #define DECLARE_ASM_ALIGNED(n,t,v)  t v
>-    #define DECLARE_ASM_CONST(n,t,v)    static const t v
>+    #define DECLARE_ALIGNED_T(n,t,v)    _Alignas(n) t v
>+    #define DECLARE_ASM_ALIGNED(n,t,v)  _Alignas(n) t av_used v
>+    #define DECLARE_ASM_CONST(n,t,v)    _Alignas(n) static const t av_used v
> #endif
> 
> #if HAVE_SIMD_ALIGN_64


More information about the ffmpeg-devel mailing list