From: "Ronald S. Bultje" <[email protected]>
This will be useful to test more aggressively for failures to mark XMM
registers as clobbered in Win64 builds, and prevent regressions thereof.
---
configure | 14 +++++
libavcodec/Makefile | 3 +
libavcodec/w64xmmtest.c | 138 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 155 insertions(+), 0 deletions(-)
create mode 100644 libavcodec/w64xmmtest.c
diff --git a/configure b/configure
index 49f9af2..460db2b 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-test-xmm-clobber
+ 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_test_xmm_clobber
x11grab
zlib
"
@@ -2583,6 +2587,16 @@ case $target_os in
;;
esac
+enabled win64_test_xmm_clobber && \
+ 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_test_xmm_clobber
+
echo "config:$arch:$subarch:$cpu:$target_os:$cc_ident:$LIBAV_CONFIGURATION"
>config.fate
check_cpp_condition stdlib.h "defined(__PIC__) || defined(__pic__) ||
defined(PIC)" && enable pic
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 6308e82..580e31c 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -663,6 +663,9 @@ OBJS-$(CONFIG_TEXT2MOVSUB_BSF) += movsub_bsf.o
OBJS-$(HAVE_PTHREADS) += pthread.o
OBJS-$(HAVE_W32THREADS) += pthread.o
+# Win64 XMM clobber stuff
+OBJS-$(CONFIG_WIN64_TEST_XMM_CLOBBER) += w64xmmtest.o
+
OBJS-$(CONFIG_MLIB) += mlib/dsputil_mlib.o \
# inverse.o contains the ff_inverse table definition, which is used by
diff --git a/libavcodec/w64xmmtest.c b/libavcodec/w64xmmtest.c
new file mode 100644
index 0000000..61e7461
--- /dev/null
+++ b/libavcodec/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.7.4
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel