This source file includes following definitions.
- __rdtsc
#ifndef _TESTHARNESS_H_
#define _TESTHARNESS_H_ 1
#include "common.h"
#include "primitives.h"
#if _MSC_VER
#pragma warning(disable: 4324)
#endif
#define PIXEL_MIN 0
#define SHORT_MAX 32767
#define SHORT_MIN -32767
#define UNSIGNED_SHORT_MAX 65535
using namespace X265_NS;
extern const char* lumaPartStr[NUM_PU_SIZES];
extern const char* const* chromaPartStr[X265_CSP_COUNT];
class TestHarness
{
public:
TestHarness() {}
virtual ~TestHarness() {}
virtual bool testCorrectness(const EncoderPrimitives& ref, const EncoderPrimitives& opt) = 0;
virtual void measureSpeed(const EncoderPrimitives& ref, const EncoderPrimitives& opt) = 0;
virtual const char *getName() const = 0;
protected:
int m_ok;
uint64_t m_rand;
};
#ifdef _MSC_VER
#include <intrin.h>
#elif HAVE_RDTSC
#include <intrin.h>
#elif defined(__GNUC__)
static inline uint32_t __rdtsc(void)
{
uint32_t a = 0;
#if X265_ARCH_X86
asm volatile("rdtsc" : "=a" (a) ::"edx");
#elif X265_ARCH_ARM
a = clock();
#endif
return a;
}
#endif
#define BENCH_RUNS 1000
#define REPORT_SPEEDUP(RUNOPT, RUNREF, ...) \
{ \
uint32_t cycles = 0; int runs = 0; \
RUNOPT(__VA_ARGS__); \
for (int ti = 0; ti < BENCH_RUNS; ti++) { \
uint32_t t0 = (uint32_t)__rdtsc(); \
RUNOPT(__VA_ARGS__); \
RUNOPT(__VA_ARGS__); \
RUNOPT(__VA_ARGS__); \
RUNOPT(__VA_ARGS__); \
uint32_t t1 = (uint32_t)__rdtsc() - t0; \
if (t1 * runs <= cycles * 4 && ti > 0) { cycles += t1; runs++; } \
} \
uint32_t refcycles = 0; int refruns = 0; \
RUNREF(__VA_ARGS__); \
for (int ti = 0; ti < BENCH_RUNS / 4; ti++) { \
uint32_t t0 = (uint32_t)__rdtsc(); \
RUNREF(__VA_ARGS__); \
RUNREF(__VA_ARGS__); \
RUNREF(__VA_ARGS__); \
RUNREF(__VA_ARGS__); \
uint32_t t1 = (uint32_t)__rdtsc() - t0; \
if (t1 * refruns <= refcycles * 4 && ti > 0) { refcycles += t1; refruns++; } \
} \
x265_emms(); \
float optperf = (10.0f * cycles / runs) / 4; \
float refperf = (10.0f * refcycles / refruns) / 4; \
printf("\t%3.2fx ", refperf / optperf); \
printf("\t %-8.2lf \t %-8.2lf\n", optperf, refperf); \
}
extern "C" {
#if X265_ARCH_X86
int PFX(stack_pagealign)(int (*func)(), int align);
intptr_t PFX(checkasm_call)(intptr_t (*func)(), int *ok, ...);
float PFX(checkasm_call_float)(float (*func)(), int *ok, ...);
#elif X265_ARCH_ARM == 0
#define PFX(stack_pagealign)(func, align) func()
#endif
#if X86_64
void PFX(checkasm_stack_clobber)(uint64_t clobber, ...);
#define checked(func, ...) ( \
m_ok = 1, m_rand = (rand() & 0xffff) * 0x0001000100010001ULL, \
PFX(checkasm_stack_clobber)(m_rand, m_rand, m_rand, m_rand, m_rand, m_rand, m_rand, m_rand, \
m_rand, m_rand, m_rand, m_rand, m_rand, m_rand, m_rand, m_rand, \
m_rand, m_rand, m_rand, m_rand, m_rand), \
PFX(checkasm_call)((intptr_t(*)())func, &m_ok, 0, 0, 0, 0, __VA_ARGS__))
#define checked_float(func, ...) ( \
m_ok = 1, m_rand = (rand() & 0xffff) * 0x0001000100010001ULL, \
PFX(checkasm_stack_clobber)(m_rand, m_rand, m_rand, m_rand, m_rand, m_rand, m_rand, m_rand, \
m_rand, m_rand, m_rand, m_rand, m_rand, m_rand, m_rand, m_rand, \
m_rand, m_rand, m_rand, m_rand, m_rand), \
PFX(checkasm_call_float)((float(*)())func, &m_ok, 0, 0, 0, 0, __VA_ARGS__))
#define reportfail() if (!m_ok) { fflush(stdout); fprintf(stderr, "stack clobber check failed at %s:%d", __FILE__, __LINE__); abort(); }
#elif ARCH_X86
#define checked(func, ...) PFX(checkasm_call)((intptr_t(*)())func, &m_ok, __VA_ARGS__);
#define checked_float(func, ...) PFX(checkasm_call_float)((float(*)())func, &m_ok, __VA_ARGS__);
#else
#define checked(func, ...) func(__VA_ARGS__)
#define checked_float(func, ...) func(__VA_ARGS__)
#define reportfail()
#endif
}
#endif