[FFmpeg-cvslog] avcodec/arm/mpegvideo_arm: Use static_assert to check offsets

Andreas Rheinhardt git at videolan.org
Sun Mar 31 02:05:39 EET 2024


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Thu Mar 28 19:58:47 2024 +0100| [e4e6377afcd1a201573c970ebf16fe6eabde58a4] | committer: Andreas Rheinhardt

avcodec/arm/mpegvideo_arm: Use static_assert to check offsets

Also move AV_CHECK_OFFSET to its only user, namely
lavc/arm/mpegvideo_arm.c and rename it to CHECK_OFFSET.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e4e6377afcd1a201573c970ebf16fe6eabde58a4
---

 libavcodec/arm/mpegvideo_arm.c | 20 ++++++++++++--------
 libavutil/internal.h           |  8 --------
 2 files changed, 12 insertions(+), 16 deletions(-)

diff --git a/libavcodec/arm/mpegvideo_arm.c b/libavcodec/arm/mpegvideo_arm.c
index 008ef18eea..28a3f2cdd9 100644
--- a/libavcodec/arm/mpegvideo_arm.c
+++ b/libavcodec/arm/mpegvideo_arm.c
@@ -18,8 +18,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include <assert.h>
+
 #include "libavutil/attributes.h"
-#include "libavutil/internal.h"
 #include "libavutil/arm/cpu.h"
 #include "libavcodec/avcodec.h"
 #include "libavcodec/mpegvideo.h"
@@ -27,13 +28,16 @@
 #include "asm-offsets.h"
 
 #if HAVE_NEON
-AV_CHECK_OFFSET(MpegEncContext, y_dc_scale,       Y_DC_SCALE);
-AV_CHECK_OFFSET(MpegEncContext, c_dc_scale,       C_DC_SCALE);
-AV_CHECK_OFFSET(MpegEncContext, ac_pred,          AC_PRED);
-AV_CHECK_OFFSET(MpegEncContext, block_last_index, BLOCK_LAST_INDEX);
-AV_CHECK_OFFSET(MpegEncContext, inter_scantable.raster_end,
-                INTER_SCANTAB_RASTER_END);
-AV_CHECK_OFFSET(MpegEncContext, h263_aic,         H263_AIC);
+#define CHECK_OFFSET(s, m, o)          \
+    static_assert(offsetof(s, m) == o, \
+                  "Hardcoded ASM offset of " #s " field " #o " needs to be updated.");
+CHECK_OFFSET(MpegEncContext, y_dc_scale,       Y_DC_SCALE);
+CHECK_OFFSET(MpegEncContext, c_dc_scale,       C_DC_SCALE);
+CHECK_OFFSET(MpegEncContext, ac_pred,          AC_PRED);
+CHECK_OFFSET(MpegEncContext, block_last_index, BLOCK_LAST_INDEX);
+CHECK_OFFSET(MpegEncContext, inter_scantable.raster_end,
+             INTER_SCANTAB_RASTER_END);
+CHECK_OFFSET(MpegEncContext, h263_aic,         H263_AIC);
 #endif
 
 void ff_dct_unquantize_h263_inter_neon(MpegEncContext *s, int16_t *block,
diff --git a/libavutil/internal.h b/libavutil/internal.h
index 461c0df9ad..e0b2c74b21 100644
--- a/libavutil/internal.h
+++ b/libavutil/internal.h
@@ -76,14 +76,6 @@
 
 #define FF_MEMORY_POISON 0x2a
 
-/* Check if the hard coded offset of a struct member still matches reality.
- * Induce a compilation failure if not.
- */
-#define AV_CHECK_OFFSET(s, m, o) struct check_##o {    \
-        int x_##o[offsetof(s, m) == o? 1: -1];         \
-    }
-
-
 #define FF_ALLOC_TYPED_ARRAY(p, nelem)  (p = av_malloc_array(nelem, sizeof(*p)))
 #define FF_ALLOCZ_TYPED_ARRAY(p, nelem) (p = av_calloc(nelem, sizeof(*p)))
 



More information about the ffmpeg-cvslog mailing list