This will be useful to test more aggressively for failures to mark XMM
registers as clobbered in Win64 builds, and prevent regressions thereof.
---
configure | 13 ++++
libavcodec/x86/Makefile | 1 +
libavcodec/x86/w64xmmtest.c | 138 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 152 insertions(+), 0 deletions(-)
create mode 100644 libavcodec/x86/w64xmmtest.c
diff --git a/configure b/configure
index 49f9af2..d79fc41 100755
--- a/configure
+++ b/configure
@@ -116,6 +116,9 @@ Configuration options:
disable buffer boundary checking in bitreaders
(faster, but may crash)
--enable-memalign-hack emulate memalign, interferes with memory debuggers
+ --enable-win64-xmm-clobber-test
+ check XMM registers for clobbering (Win64-only;
+ should be used only for debugging purposes)
--disable-everything disable all components listed below
--disable-encoder=NAME disable encoder NAME
--enable-encoder=NAME enable encoder NAME
@@ -991,6 +994,7 @@ CONFIG_LIST="
vda
vdpau
version3
+ win64_xmm_clobber_test
x11grab
zlib
"
@@ -3064,6 +3068,15 @@ enabled extra_warnings && check_cflags -Winline
check_ldflags -Wl,--warn-common
check_ldflags
-Wl,-rpath-link=libpostproc:libswscale:libavfilter:libavdevice:libavformat:libavcodec:libavutil
test_ldflags -Wl,-Bsymbolic && append SHFLAGS -Wl,-Bsymbolic
+enabled win64_xmm_clobber_test && \
+ check_ldflags -Wl,--wrap,avcodec_open2 \
+ -Wl,--wrap,avcodec_decode_audio4 \
+ -Wl,--wrap,avcodec_decode_video2 \
+ -Wl,--wrap,avcodec_decode_subtitle2 \
+ -Wl,--wrap,avcodec_encode_audio2 \
+ -Wl,--wrap,avcodec_encode_video \
+ -Wl,--wrap,avcodec_encode_subtitle || \
+ disable win64_xmm_clobber_test
echo "X{};" > $TMPV
if test_ldflags -Wl,--version-script,$TMPV; then
diff --git a/libavcodec/x86/Makefile b/libavcodec/x86/Makefile
index 930ace7..1bdeae0 100644
--- a/libavcodec/x86/Makefile
+++ b/libavcodec/x86/Makefile
@@ -74,3 +74,4 @@ OBJS-$(HAVE_MMX) += x86/dsputil_mmx.o
\
x86/mpegvideo_mmx.o \
x86/simple_idct_mmx.o \
+OBJS-$(CONFIG_WIN64_XMM_CLOBBER_TEST) += x86/w64xmmtest.o
diff --git a/libavcodec/x86/w64xmmtest.c b/libavcodec/x86/w64xmmtest.c
new file mode 100644
index 0000000..61e7461
--- /dev/null
+++ b/libavcodec/x86/w64xmmtest.c
@@ -0,0 +1,138 @@
+/*
+ * check XMM registers for clobbers on Win64
+ * Copyright (c) 2008 Ramiro Polla <[email protected]>
+ *
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Libav is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ */
+
+#include <stdlib.h>
+#include <stdarg.h>
+
+#include "avcodec.h"
+#include "dsputil.h"
+
+#define testxmmclobbers(func, ...) \
+ LOCAL_ALIGNED_16(uint8_t, xmm, [2][10*16]); \
+ int ret; \
+ __asm volatile( \
+ "movaps %%xmm6 , 0x00(%0)\n\t" \
+ "movaps %%xmm7 , 0x10(%0)\n\t" \
+ "movaps %%xmm8 , 0x20(%0)\n\t" \
+ "movaps %%xmm9 , 0x30(%0)\n\t" \
+ "movaps %%xmm10, 0x40(%0)\n\t" \
+ "movaps %%xmm11, 0x50(%0)\n\t" \
+ "movaps %%xmm12, 0x60(%0)\n\t" \
+ "movaps %%xmm13, 0x70(%0)\n\t" \
+ "movaps %%xmm14, 0x80(%0)\n\t" \
+ "movaps %%xmm15, 0x90(%0)\n\t" \
+ ::"r"(xmm[0]) : "memory"); \
+ ret = __real_avcodec_ ## func(__VA_ARGS__); \
+ __asm volatile( \
+ "movaps %%xmm6 , 0x00(%0)\n\t" \
+ "movaps %%xmm7 , 0x10(%0)\n\t" \
+ "movaps %%xmm8 , 0x20(%0)\n\t" \
+ "movaps %%xmm9 , 0x30(%0)\n\t" \
+ "movaps %%xmm10, 0x40(%0)\n\t" \
+ "movaps %%xmm11, 0x50(%0)\n\t" \
+ "movaps %%xmm12, 0x60(%0)\n\t" \
+ "movaps %%xmm13, 0x70(%0)\n\t" \
+ "movaps %%xmm14, 0x80(%0)\n\t" \
+ "movaps %%xmm15, 0x90(%0)\n\t" \
+ ::"r"(xmm[1]) : "memory"); \
+ if (memcmp(xmm[0], xmm[1], 10*16)) { \
+ int i; \
+ av_log(avctx, AV_LOG_ERROR, \
+ "XMM REGS CLOBBERED IN %s!\n", \
+ __func__); \
+ for (i = 0; i < 10*16; i++) \
+ if (xmm[0][i] != xmm[1][i]) \
+ av_log(avctx, AV_LOG_ERROR, \
+ "xmm[0][%x] = %02x, " \
+ "xmm[1][%x] = %02x\n", \
+ i, xmm[0][i], \
+ i, xmm[1][i]); \
+ abort(); \
+ } \
+ return ret
+
+#define wrap(func) \
+int __real_ ## func; \
+int __wrap_ ## func; \
+int __wrap_ ## func
+
+wrap(avcodec_open2(AVCodecContext *avctx,
+ AVCodec *codec,
+ AVDictionary **options))
+{
+ testxmmclobbers(open2, avctx, codec, options);
+}
+
+wrap(avcodec_decode_audio4(AVCodecContext *avctx,
+ AVFrame *frame,
+ int *got_frame_ptr,
+ AVPacket *avpkt))
+{
+ testxmmclobbers(decode_audio4, avctx, frame,
+ got_frame_ptr, avpkt);
+}
+
+wrap(avcodec_decode_video2(AVCodecContext *avctx,
+ AVFrame *picture,
+ int *got_picture_ptr,
+ AVPacket *avpkt))
+{
+ testxmmclobbers(decode_video2, avctx, picture,
+ got_picture_ptr, avpkt);
+}
+
+wrap(avcodec_decode_subtitle2(AVCodecContext *avctx,
+ AVSubtitle *sub,
+ int *got_sub_ptr,
+ AVPacket *avpkt))
+{
+ testxmmclobbers(decode_subtitle2, avctx, sub,
+ got_sub_ptr, avpkt);
+}
+
+wrap(avcodec_encode_audio2(AVCodecContext *avctx,
+ AVPacket *avpkt,
+ const AVFrame *frame,
+ int *got_packet_ptr))
+{
+ testxmmclobbers(encode_audio2, avctx, avpkt, frame,
+ got_packet_ptr);
+}
+
+wrap(avcodec_encode_video(AVCodecContext *avctx,
+ uint8_t *buf, int buf_size,
+ const AVFrame *pict))
+{
+ testxmmclobbers(encode_video, avctx, buf,
+ buf_size, pict);
+}
+
+wrap(avcodec_encode_subtitle(AVCodecContext *avctx,
+ uint8_t *buf, int buf_size,
+ const AVSubtitle *sub))
+{
+ testxmmclobbers(encode_subtitle, avctx, buf,
+ buf_size, sub);
+}
--
1.7.2.1
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel