diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile index 909f2f00ad..8be6eec905 100644 --- a/tests/checkasm/Makefile +++ b/tests/checkasm/Makefile @@ -17,8 +17,7 @@ CHECKASMDIRS := $(sort $(dir $(CHECKASMOBJS))) $(CHECKASMOBJS): | $(CHECKASMDIRS) OBJDIRS += $(CHECKASMDIRS) -# We rely on function pointers intentionally declared without specified argument types. -tests/checkasm/%.o: CFLAGS := $(CFLAGS:-Wstrict-prototypes=-Wno-strict-prototypes) -Umain +tests/checkasm/checkasm.o: CFLAGS += -Umain CHECKASM := tests/checkasm/checkasm$(EXESUF) diff --git a/tests/checkasm/bswapdsp.c b/tests/checkasm/bswapdsp.c index b93c5bd1e0..5f7555037d 100644 --- a/tests/checkasm/bswapdsp.c +++ b/tests/checkasm/bswapdsp.c @@ -43,6 +43,8 @@ #define check_bswap(type) \ do { \ int w; \ + declare_func(void, type *dst, const type *src, int w); \ + \ for (w = 0; w < BUF_SIZE / sizeof(type); w++) { \ int offset = (BUF_SIZE / sizeof(type) - w) & 15; /* Test various alignments */ \ randomize_buffers(); \ diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c index 4eb14ddec4..7ec8d67f4a 100644 --- a/tests/checkasm/checkasm.c +++ b/tests/checkasm/checkasm.c @@ -111,7 +111,7 @@ static const struct { typedef struct CheckasmFuncVersion { struct CheckasmFuncVersion *next; - intptr_t (*func)(); + void *func; int ok; int cpu; int iterations; @@ -387,10 +387,10 @@ int main(int argc, char *argv[]) /* Decide whether or not the specified function needs to be tested and * allocate/initialize data structures if needed. Returns a pointer to a * reference function if the function should be tested, otherwise NULL */ -intptr_t (*checkasm_check_func(intptr_t (*func)(), const char *name, ...))() +void *checkasm_check_func(void *func, const char *name, ...) { char name_buf[256]; - intptr_t (*ref)() = func; + void *ref = func; CheckasmFuncVersion *v; int name_length; va_list arg; diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h index fdec55e1c0..8028224245 100644 --- a/tests/checkasm/checkasm.h +++ b/tests/checkasm/checkasm.h @@ -33,7 +33,7 @@ void checkasm_check_bswapdsp(void); void checkasm_check_h264pred(void); void checkasm_check_h264qpel(void); -intptr_t (*checkasm_check_func(intptr_t (*func)(), const char *name, ...))() av_printf_format(2, 3); +void *checkasm_check_func(void *func, const char *name, ...) av_printf_format(2, 3); int checkasm_bench_func(void); void checkasm_fail_func(const char *msg, ...) av_printf_format(1, 2); void checkasm_update_bench(int iterations, uint64_t cycles); @@ -42,14 +42,16 @@ void checkasm_report(const char *name, ...) av_printf_format(1, 2); extern AVLFG checkasm_lfg; #define rnd() av_lfg_get(&checkasm_lfg) -static av_unused intptr_t (*func_ref)(); -static av_unused intptr_t (*func_new)(); +static av_unused void *func_ref, *func_new; #define BENCH_RUNS 1000 /* Trade-off between accuracy and speed */ /* Decide whether or not the specified function needs to be tested */ -#define check_func(func, ...) ((func_new = (intptr_t (*)())func) &&\ - (func_ref = checkasm_check_func(func_new, __VA_ARGS__))) +#define check_func(func, ...) (func_ref = checkasm_check_func((func_new = func), __VA_ARGS__)) + +/* Declare the function prototype. The first argument is the return value, the remaining + * arguments are the function parameters. Naming parameters is optional. */ +#define declare_func(ret, ...) declare_new(ret, __VA_ARGS__) typedef ret func_type(__VA_ARGS__) /* Indicate that the current test has failed */ #define fail() checkasm_fail_func("%s:%d", av_basename(__FILE__), __LINE__) @@ -58,18 +60,16 @@ static av_unused intptr_t (*func_new)(); #define report checkasm_report /* Call the reference function */ -#define call_ref(...) func_ref(__VA_ARGS__) +#define call_ref(...) ((func_type *)func_ref)(__VA_ARGS__) #if ARCH_X86 && HAVE_YASM /* Verifies that clobbered callee-saved registers are properly saved and restored */ -intptr_t checkasm_checked_call(intptr_t (*func)(), ...); -#endif +void checkasm_checked_call(void *func, ...); -/* Call the function */ -#if ARCH_X86_64 && HAVE_YASM +#if ARCH_X86_64 /* Evil hack: detect incorrect assumptions that 32-bit ints are zero-extended to 64-bit. * This is done by clobbering the stack with junk around the stack pointer and calling the - * assembly function through x264_checkasm_call with added dummy arguments which forces all + * assembly function through checked_call() with added dummy arguments which forces all * real arguments to be passed on the stack and not in registers. For 32-bit arguments the * upper half of the 64-bit register locations on the stack will now contain junk which will * cause misbehaving functions to either produce incorrect output or segfault. Note that @@ -77,14 +77,20 @@ intptr_t checkasm_checked_call(intptr_t (*func)(), ...); * and false negatives is theoretically possible, but there can never be any false positives. */ void checkasm_stack_clobber(uint64_t clobber, ...); +#define declare_new(ret, ...) ret (*checked_call)(void *, int, int, int, int, int, __VA_ARGS__)\ + = (void *)checkasm_checked_call; #define CLOB (UINT64_C(0xdeadbeefdeadbeef)) #define call_new(...) (checkasm_stack_clobber(CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,\ CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB),\ - checkasm_checked_call(func_new, 0, 0, 0, 0, 0, __VA_ARGS__)) -#elif ARCH_X86_32 && HAVE_YASM -#define call_new(...) checkasm_checked_call(func_new, __VA_ARGS__) + checked_call(func_new, 0, 0, 0, 0, 0, __VA_ARGS__)) +#elif ARCH_X86_32 +#define declare_new(ret, ...) ret (*checked_call)(void *, __VA_ARGS__) = (void *)checkasm_checked_call; +#define call_new(...) checked_call(func_new, __VA_ARGS__) +#endif #else -#define call_new(...) func_new(__VA_ARGS__) +#define declare_new(ret, ...) +/* Call the function */ +#define call_new(...) ((func_type *)func_new)(__VA_ARGS__) #endif /* Benchmark the function */ @@ -92,7 +98,7 @@ void checkasm_stack_clobber(uint64_t clobber, ...); #define bench_new(...)\ do {\ if (checkasm_bench_func()) {\ - intptr_t (*tfunc)() = func_new;\ + func_type *tfunc = func_new;\ uint64_t tsum = 0;\ int ti, tcount = 0;\ for (ti = 0; ti < BENCH_RUNS; ti++) {\ diff --git a/tests/checkasm/h264pred.c b/tests/checkasm/h264pred.c index 5e9a7c1e17..ad1b02758d 100644 --- a/tests/checkasm/h264pred.c +++ b/tests/checkasm/h264pred.c @@ -144,14 +144,16 @@ static void check_pred4x4(H264PredContext *h, uint8_t *buf0, uint8_t *buf1, if (chroma_format == 1) { uint8_t *topright = buf0 + 2*16; int pred_mode; + declare_func(void, uint8_t *src, const uint8_t *topright, ptrdiff_t stride); + for (pred_mode = 0; pred_mode < 15; pred_mode++) { if (check_pred_func(h->pred4x4[pred_mode], "4x4", pred4x4_modes[codec][pred_mode])) { randomize_buffers(); - call_ref(src0, topright, (ptrdiff_t)12*SIZEOF_PIXEL); - call_new(src1, topright, (ptrdiff_t)12*SIZEOF_PIXEL); + call_ref(src0, topright, 12*SIZEOF_PIXEL); + call_new(src1, topright, 12*SIZEOF_PIXEL); if (memcmp(buf0, buf1, BUF_SIZE)) fail(); - bench_new(src1, topright, (ptrdiff_t)12*SIZEOF_PIXEL); + bench_new(src1, topright, 12*SIZEOF_PIXEL); } } } @@ -161,15 +163,17 @@ static void check_pred8x8(H264PredContext *h, uint8_t *buf0, uint8_t *buf1, int codec, int chroma_format, int bit_depth) { int pred_mode; + declare_func(void, uint8_t *src, ptrdiff_t stride); + for (pred_mode = 0; pred_mode < 11; pred_mode++) { if (check_pred_func(h->pred8x8[pred_mode], (chroma_format == 2) ? "8x16" : "8x8", pred8x8_modes[codec][pred_mode])) { randomize_buffers(); - call_ref(src0, (ptrdiff_t)24*SIZEOF_PIXEL); - call_new(src1, (ptrdiff_t)24*SIZEOF_PIXEL); + call_ref(src0, 24*SIZEOF_PIXEL); + call_new(src1, 24*SIZEOF_PIXEL); if (memcmp(buf0, buf1, BUF_SIZE)) fail(); - bench_new(src1, (ptrdiff_t)24*SIZEOF_PIXEL); + bench_new(src1, 24*SIZEOF_PIXEL); } } } @@ -179,14 +183,16 @@ static void check_pred16x16(H264PredContext *h, uint8_t *buf0, uint8_t *buf1, { if (chroma_format == 1) { int pred_mode; + declare_func(void, uint8_t *src, ptrdiff_t stride); + for (pred_mode = 0; pred_mode < 9; pred_mode++) { if (check_pred_func(h->pred16x16[pred_mode], "16x16", pred16x16_modes[codec][pred_mode])) { randomize_buffers(); - call_ref(src0, (ptrdiff_t)48); - call_new(src1, (ptrdiff_t)48); + call_ref(src0, 48); + call_new(src1, 48); if (memcmp(buf0, buf1, BUF_SIZE)) fail(); - bench_new(src1, (ptrdiff_t)48); + bench_new(src1, 48); } } } @@ -197,6 +203,8 @@ static void check_pred8x8l(H264PredContext *h, uint8_t *buf0, uint8_t *buf1, { if (chroma_format == 1 && codec_ids[codec] == AV_CODEC_ID_H264) { int pred_mode; + declare_func(void, uint8_t *src, int topleft, int topright, ptrdiff_t stride); + for (pred_mode = 0; pred_mode < 12; pred_mode++) { if (check_pred_func(h->pred8x8l[pred_mode], "8x8l", pred4x4_modes[codec][pred_mode])) { int neighbors; @@ -208,11 +216,11 @@ static void check_pred8x8l(H264PredContext *h, uint8_t *buf0, uint8_t *buf1, continue; /* Those aren't allowed according to the spec */ randomize_buffers(); - call_ref(src0, has_topleft, has_topright, (ptrdiff_t)24*SIZEOF_PIXEL); - call_new(src1, has_topleft, has_topright, (ptrdiff_t)24*SIZEOF_PIXEL); + call_ref(src0, has_topleft, has_topright, 24*SIZEOF_PIXEL); + call_new(src1, has_topleft, has_topright, 24*SIZEOF_PIXEL); if (memcmp(buf0, buf1, BUF_SIZE)) fail(); - bench_new(src1, has_topleft, has_topright, (ptrdiff_t)24*SIZEOF_PIXEL); + bench_new(src1, has_topleft, has_topright, 24*SIZEOF_PIXEL); } } } diff --git a/tests/checkasm/h264qpel.c b/tests/checkasm/h264qpel.c index 63b9a517a8..fb7a1db62d 100644 --- a/tests/checkasm/h264qpel.c +++ b/tests/checkasm/h264qpel.c @@ -55,6 +55,7 @@ void checkasm_check_h264qpel(void) LOCAL_ALIGNED_16(uint8_t, dst1, [BUF_SIZE]); H264QpelContext h; int op, bit_depth, i, j; + declare_func(void, uint8_t *dst, const uint8_t *src, ptrdiff_t stride); for (op = 0; op < 2; op++) { qpel_mc_func (*tab)[16] = op ? h.avg_h264_qpel_pixels_tab : h.put_h264_qpel_pixels_tab; @@ -67,11 +68,11 @@ void checkasm_check_h264qpel(void) for (j = 0; j < 16; j++) if (check_func(tab[i][j], "%s_h264_qpel_%d_mc%d%d_%d", op_name, size, j & 3, j >> 2, bit_depth)) { randomize_buffers(); - call_ref(dst0, src0, (ptrdiff_t)size * SIZEOF_PIXEL); - call_new(dst1, src1, (ptrdiff_t)size * SIZEOF_PIXEL); + call_ref(dst0, src0, size * SIZEOF_PIXEL); + call_new(dst1, src1, size * SIZEOF_PIXEL); if (memcmp(buf0, buf1, BUF_SIZE) || memcmp(dst0, dst1, BUF_SIZE)) fail(); - bench_new(dst1, src1, (ptrdiff_t)size * SIZEOF_PIXEL); + bench_new(dst1, src1, size * SIZEOF_PIXEL); } } } diff --git a/tests/checkasm/x86/checkasm.asm b/tests/checkasm/x86/checkasm.asm index 82d4076332..377fd373c0 100644 --- a/tests/checkasm/x86/checkasm.asm +++ b/tests/checkasm/x86/checkasm.asm @@ -82,7 +82,7 @@ cglobal stack_clobber, 1,2 %endif ;----------------------------------------------------------------------------- -; intptr_t checkasm_checked_call(intptr_t (*func)(), ...) +; void checkasm_checked_call(void *func, ...) ;----------------------------------------------------------------------------- INIT_XMM cglobal checked_call, 2,15,16,max_args*8+8 @@ -162,7 +162,7 @@ cglobal checked_call, 2,15,16,max_args*8+8 %define n6 dword 0x33627ba7 ;----------------------------------------------------------------------------- -; intptr_t checkasm_checked_call(intptr_t (*func)(), ...) +; void checkasm_checked_call(void *func, ...) ;----------------------------------------------------------------------------- cglobal checked_call, 1,7 mov r3, n3