• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * check XMM registers for clobbers on Win64
3  * Copyright (c) 2008 Ramiro Polla <ramiro.polla@gmail.com>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #ifndef AVUTIL_X86_W64XMMTEST_H
23 #define AVUTIL_X86_W64XMMTEST_H
24 
25 #include <inttypes.h>
26 #include <stdint.h>
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <string.h>
30 
31 #include "libavutil/bswap.h"
32 
33 #define storexmmregs(mem)               \
34     __asm__ volatile(                   \
35         "movups %%xmm6 , 0x00(%0)\n\t"  \
36         "movups %%xmm7 , 0x10(%0)\n\t"  \
37         "movups %%xmm8 , 0x20(%0)\n\t"  \
38         "movups %%xmm9 , 0x30(%0)\n\t"  \
39         "movups %%xmm10, 0x40(%0)\n\t"  \
40         "movups %%xmm11, 0x50(%0)\n\t"  \
41         "movups %%xmm12, 0x60(%0)\n\t"  \
42         "movups %%xmm13, 0x70(%0)\n\t"  \
43         "movups %%xmm14, 0x80(%0)\n\t"  \
44         "movups %%xmm15, 0x90(%0)\n\t"  \
45         :: "r"(mem) : "memory")
46 
47 #define testxmmclobbers(func, ctx, ...)                         \
48     uint64_t xmm[2][10][2];                                     \
49     int ret;                                                    \
50     storexmmregs(xmm[0]);                                       \
51     ret = __real_ ## func(ctx, __VA_ARGS__);                    \
52     storexmmregs(xmm[1]);                                       \
53     if (memcmp(xmm[0], xmm[1], sizeof(xmm[0]))) {               \
54         int i;                                                  \
55         av_log(ctx, AV_LOG_ERROR,                               \
56                "XMM REGS CLOBBERED IN %s!\n", #func);           \
57         for (i = 0; i < 10; i ++)                               \
58             if (xmm[0][i][0] != xmm[1][i][0] ||                 \
59                 xmm[0][i][1] != xmm[1][i][1]) {                 \
60                 av_log(ctx, AV_LOG_ERROR,                       \
61                        "xmm%-2d = %016"PRIx64"%016"PRIx64"\n",  \
62                        6 + i, av_bswap64(xmm[0][i][0]),         \
63                        av_bswap64(xmm[0][i][1]));               \
64                 av_log(ctx, AV_LOG_ERROR,                       \
65                          "     -> %016"PRIx64"%016"PRIx64"\n",  \
66                        av_bswap64(xmm[1][i][0]),                \
67                        av_bswap64(xmm[1][i][1]));               \
68             }                                                   \
69         abort();                                                \
70     }                                                           \
71     return ret
72 
73 #define wrap(func)      \
74 int __real_ ## func;    \
75 int __wrap_ ## func;    \
76 int __wrap_ ## func
77 
78 #endif /* AVUTIL_X86_W64XMMTEST_H */
79