[FFmpeg-devel] [PATCH 04/17] lavu/mem: move the DECLARE_ALIGNED macro family to mem_internal on next bump

Anton Khirnov anton at khirnov.net
Thu May 28 23:15:46 EEST 2020


They are not properly namespaced and not intended for public use.
---
 libavutil/mem.h          |  6 ++++
 libavutil/mem_internal.h | 70 ++++++++++++++++++++++++++++++++++++++++
 libavutil/version.h      |  4 ++-
 3 files changed, 79 insertions(+), 1 deletion(-)

diff --git a/libavutil/mem.h b/libavutil/mem.h
index 5fb1a02dd9..e21a1feaae 100644
--- a/libavutil/mem.h
+++ b/libavutil/mem.h
@@ -33,6 +33,7 @@
 #include "attributes.h"
 #include "error.h"
 #include "avutil.h"
+#include "version.h"
 
 /**
  * @addtogroup lavu_mem
@@ -49,6 +50,10 @@
  * dealing with memory consistently possible on all platforms.
  *
  * @{
+ */
+
+#if FF_API_DECLARE_ALIGNED
+/**
  *
  * @defgroup lavu_mem_macros Alignment Macros
  * Helper macros for declaring aligned variables.
@@ -125,6 +130,7 @@
 /**
  * @}
  */
+#endif
 
 /**
  * @defgroup lavu_mem_attrs Function Attributes
diff --git a/libavutil/mem_internal.h b/libavutil/mem_internal.h
index 6fdbcb016e..c25c28ed1a 100644
--- a/libavutil/mem_internal.h
+++ b/libavutil/mem_internal.h
@@ -23,6 +23,76 @@
 
 #include "avassert.h"
 #include "mem.h"
+#include "version.h"
+
+#if !FF_API_DECLARE_ALIGNED
+/**
+ * @def DECLARE_ALIGNED(n,t,v)
+ * Declare a variable that is aligned in memory.
+ *
+ * @code{.c}
+ * DECLARE_ALIGNED(16, uint16_t, aligned_int) = 42;
+ * DECLARE_ALIGNED(32, uint8_t, aligned_array)[128];
+ *
+ * // The default-alignment equivalent would be
+ * uint16_t aligned_int = 42;
+ * uint8_t aligned_array[128];
+ * @endcode
+ *
+ * @param n Minimum alignment in bytes
+ * @param t Type of the variable (or array element)
+ * @param v Name of the variable
+ */
+
+/**
+ * @def DECLARE_ASM_ALIGNED(n,t,v)
+ * Declare an aligned variable appropriate for use in inline assembly code.
+ *
+ * @code{.c}
+ * DECLARE_ASM_ALIGNED(16, uint64_t, pw_08) = UINT64_C(0x0008000800080008);
+ * @endcode
+ *
+ * @param n Minimum alignment in bytes
+ * @param t Type of the variable (or array element)
+ * @param v Name of the variable
+ */
+
+/**
+ * @def DECLARE_ASM_CONST(n,t,v)
+ * Declare a static constant aligned variable appropriate for use in inline
+ * assembly code.
+ *
+ * @code{.c}
+ * DECLARE_ASM_CONST(16, uint64_t, pw_08) = UINT64_C(0x0008000800080008);
+ * @endcode
+ *
+ * @param n Minimum alignment in bytes
+ * @param t Type of the variable (or array element)
+ * @param v Name of the variable
+ */
+
+#if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1110 || defined(__SUNPRO_C)
+    #define DECLARE_ALIGNED(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(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(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(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
+#else
+    #define DECLARE_ALIGNED(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
+#endif
+#endif
 
 static inline int ff_fast_malloc(void *ptr, unsigned int *size, size_t min_size, int zero_realloc)
 {
diff --git a/libavutil/version.h b/libavutil/version.h
index 7acecf5a97..f8cd0b5f8a 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -129,7 +129,9 @@
 #ifndef FF_API_PSEUDOPAL
 #define FF_API_PSEUDOPAL                (LIBAVUTIL_VERSION_MAJOR < 57)
 #endif
-
+#ifndef FF_API_DECLARE_ALIGNED
+#define FF_API_DECLARE_ALIGNED          (LIBAVUTIL_VERSION_MAJOR < 57)
+#endif
 
 /**
  * @}
-- 
2.26.2



More information about the ffmpeg-devel mailing list