From d9ce927978b19c4eb6b698ae48fd570b407cf953 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= Date: Sat, 11 May 2013 01:47:11 +0200 Subject: [PATCH] rshift test --- libavutil/Makefile | 1 + libavutil/ceilrshift.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 libavutil/ceilrshift.c diff --git a/libavutil/Makefile b/libavutil/Makefile index 30f733f..7a72e25 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -126,6 +126,7 @@ TESTPROGS = adler32 \ base64 \ blowfish \ bprint \ + ceilrshift \ cpu \ crc \ des \ diff --git a/libavutil/ceilrshift.c b/libavutil/ceilrshift.c new file mode 100644 index 0000000..5b5d983 --- /dev/null +++ b/libavutil/ceilrshift.c @@ -0,0 +1,69 @@ +#include +#include +#include "libavutil/log.h" +#include "libavutil/timer.h" + +#define CEIL_RSHIFT_1(x, n) (-((-(x)) >> (n))) +#define CEIL_RSHIFT_2(x, n) (((x) + (1<<(n)) - 1) >> (n)) + +#ifdef TEST +int main(int ac, char **av) +{ + int a, mode, max_shift; + + if (ac != 2 && ac != 3) { + printf("%s mode \n", av[0]); + return -1; + } + + mode = av[1][0] - '0'; + max_shift = ac == 3 ? atoi(av[2]) : 0; + + if (mode != 1 && mode != 2) + return -1; + +#define NON_CONST_SHIFT_TEST(m) do { \ + int b; \ + volatile int r; \ + for (a = 0; a < 1<<16; a++) { \ + START_TIMER; \ + for (b = 0; b < max_shift; b++) \ + r = CEIL_RSHIFT_##m(a, b); \ + STOP_TIMER("non-const shift + CEIL_RSHIFT_" #m); \ + } \ + (void)r; \ +} while (1) + +#define CONST_SHIFT_TEST(m) do { \ + volatile int r; \ + for (a = 0; a < 1<<16; a++) { \ + START_TIMER; \ + r = CEIL_RSHIFT_##m(a, 1); \ + r = CEIL_RSHIFT_##m(a, 2); \ + r = CEIL_RSHIFT_##m(a, 3); \ + r = CEIL_RSHIFT_##m(a, 4); \ + r = CEIL_RSHIFT_##m(a, 5); \ + r = CEIL_RSHIFT_##m(a, 6); \ + r = CEIL_RSHIFT_##m(a, 7); \ + r = CEIL_RSHIFT_##m(a, 8); \ + r = CEIL_RSHIFT_##m(a, 9); \ + r = CEIL_RSHIFT_##m(a, 10); \ + r = CEIL_RSHIFT_##m(a, 11); \ + r = CEIL_RSHIFT_##m(a, 12); \ + r = CEIL_RSHIFT_##m(a, 13); \ + STOP_TIMER("const shift CEIL_RSHIFT_" #m); \ + } \ + (void)r; \ +} while (1) + + if (mode == 1) { + if (max_shift) NON_CONST_SHIFT_TEST(1); + else CONST_SHIFT_TEST(1); + } else { + if (max_shift) NON_CONST_SHIFT_TEST(2); + else CONST_SHIFT_TEST(2); + } + + return 0; +} +#endif -- 1.8.2.2