41#ifndef CHECKASM_UTILS_H
42#define CHECKASM_UTILS_H
98#define checkasm_dist_standard ((CheckasmDist) { 0.0, 1.0 })
254#define CLEAR_BUF(buf) checkasm_clear(buf, sizeof(buf))
261#define RANDOMIZE_BUF(buf) checkasm_randomize(buf, sizeof(buf))
269#define INITIALIZE_BUF(buf) checkasm_init(buf, sizeof(buf))
320 unsigned max_ulp,
int len);
343 float eps,
unsigned max_ulp,
364 double eps,
unsigned len);
370#define float_near_ulp checkasm_float_near_ulp
371#define float_near_abs_eps checkasm_float_near_abs_eps
372#define float_near_abs_eps_ulp checkasm_float_near_abs_eps_ulp
373#define float_near_ulp_array checkasm_float_near_ulp_array
374#define float_near_abs_eps_array checkasm_float_near_abs_eps_array
375#define float_near_abs_eps_array_ulp checkasm_float_near_abs_eps_array_ulp
376#define double_near_abs_eps checkasm_double_near_abs_eps
377#define double_near_abs_eps_array checkasm_double_near_abs_eps_array
406 #define CHECKASM_ALIGN(x) __declspec(align(CHECKASM_ALIGNMENT)) x
408 #define CHECKASM_ALIGN(x) x __attribute__((aligned(CHECKASM_ALIGNMENT)))
416#define DECL_CHECK_FUNC(NAME, TYPE) \
417 int (NAME)(const char *const file, const int line, const TYPE *const buf1, \
418 const ptrdiff_t stride1, const TYPE *const buf2, const ptrdiff_t stride2, \
419 const int w, const int h, const char *const buf_name, const int align_w, \
420 const int align_h, const int padding)
422#define DECL_CHECKASM_CHECK_FUNC(type) \
423 CHECKASM_API DECL_CHECK_FUNC(checkasm_check_impl_##type, type)
425DECL_CHECKASM_CHECK_FUNC(
int);
426DECL_CHECKASM_CHECK_FUNC(int8_t);
427DECL_CHECKASM_CHECK_FUNC(int16_t);
428DECL_CHECKASM_CHECK_FUNC(int32_t);
430DECL_CHECKASM_CHECK_FUNC(
unsigned);
431DECL_CHECKASM_CHECK_FUNC(uint8_t);
432DECL_CHECKASM_CHECK_FUNC(uint16_t);
433DECL_CHECKASM_CHECK_FUNC(uint32_t);
439 const float *buf1, ptrdiff_t stride1,
440 const float *buf2, ptrdiff_t stride2,
441 int w,
int h,
const char *name,
442 unsigned max_ulp,
int align_w,
int align_h,
445#define checkasm_check_impl2(type) checkasm_check_impl_##type
446#define checkasm_check_impl(type) checkasm_check_impl2(type)
447#define checkasm_check1(type, ...) checkasm_check_impl_##type(__VA_ARGS__)
448#define checkasm_check2(type, ...) checkasm_check1(type, __FILE__, __LINE__, __VA_ARGS__)
480#define checkasm_check(type, ...) checkasm_check2(type, __VA_ARGS__, 0, 0, 0)
501#define checkasm_check_padded(type, ...) checkasm_check2(type, __VA_ARGS__)
522#define CHECKASM_ROUND(x, a) (((x) + ((a) - 1)) & ~((a) - 1))
553#define BUF_RECT(type, name, w, h) \
554 DECL_CHECK_FUNC(*checkasm_check_impl_##name##_type, type) \
555 = checkasm_check_impl_##type; \
556 CHECKASM_ALIGN(type name##_buf[((h) + 32) * (CHECKASM_ROUND(w, 64) + 64) + 64]); \
557 ptrdiff_t name##_stride = sizeof(type) * (CHECKASM_ROUND(w, 64) + 64); \
558 int name##_buf_h = (h) + 32; \
559 (void) checkasm_check_impl(name##_type); \
560 (void) name##_stride; \
561 (void) name##_buf_h; \
562 type *name = name##_buf + (CHECKASM_ROUND(w, 64) + 64) * 16 + 64
570#define CLEAR_BUF_RECT(name) CLEAR_BUF(name##_buf)
578#define INITIALIZE_BUF_RECT(name) INITIALIZE_BUF(name##_buf)
586#define RANDOMIZE_BUF_RECT(name) RANDOMIZE_BUF(name##_buf)
595#define checkasm_check_rect(rect1, ...) checkasm_check(rect1##_type, rect1, __VA_ARGS__)
604#define checkasm_check_rect_padded(rect1, ...) \
605 checkasm_check_padded(rect1##_type, rect1, __VA_ARGS__, 1, 1, 8)
620#define checkasm_check_rect_padded_align(rect1, ...) \
621 checkasm_check_padded(rect1##_type, rect1, __VA_ARGS__, 8)
Platform and compiler attribute macros.
#define CHECKASM_API
Symbol visibility attribute for public API functions.
Definition attributes.h:88
CHECKASM_API int checkasm_float_near_abs_eps_array(const float *a, const float *b, float eps, int len)
Compare float arrays using absolute epsilon tolerance.
CHECKASM_API int checkasm_float_near_ulp_array(const float *a, const float *b, unsigned max_ulp, int len)
Compare float arrays using ULP tolerance.
CHECKASM_API int checkasm_float_near_ulp(float a, float b, unsigned max_ulp)
Compare floats using ULP (Units in Last Place) tolerance.
CHECKASM_API int checkasm_float_near_abs_eps_ulp(float a, float b, float eps, unsigned max_ulp)
Compare floats using both epsilon and ULP tolerances.
CHECKASM_API int checkasm_double_near_abs_eps_array(const double *a, const double *b, double eps, unsigned len)
Compare double arrays using absolute epsilon tolerance.
CHECKASM_API int checkasm_float_near_abs_eps(float a, float b, float eps)
Compare floats using absolute epsilon tolerance.
CHECKASM_API int checkasm_double_near_abs_eps(double a, double b, double eps)
Compare doubles using absolute epsilon tolerance.
CHECKASM_API int checkasm_float_near_abs_eps_array_ulp(const float *a, const float *b, float eps, unsigned max_ulp, int len)
Compare float arrays using both epsilon and ULP tolerances.
CHECKASM_API int checkasm_check_impl_float_ulp(const char *file, int line, const float *buf1, ptrdiff_t stride1, const float *buf2, ptrdiff_t stride2, int w, int h, const char *name, unsigned max_ulp, int align_w, int align_h, int padding)
Compare float buffers with ULP tolerance.
CHECKASM_API void checkasm_init_mask8(uint8_t *buf, int width, uint8_t mask)
Initialize a uint8_t buffer with pathological values within a mask.
CHECKASM_API void checkasm_randomize_normf(float *buf, int width)
Fill a float buffer with values from a standard normal distribution.
CHECKASM_API void checkasm_randomize(void *buf, size_t bytes)
Fill a buffer with uniformly chosen random bytes.
CHECKASM_API void checkasm_clear16(uint16_t *buf, int width, uint16_t val)
Fill a uint16_t buffer with a constant value.
CHECKASM_API void checkasm_clear(void *buf, size_t bytes)
Clear a buffer to a pre-determined pattern (currently 0xAA).
CHECKASM_API void checkasm_randomize_mask16(uint16_t *buf, int width, uint16_t mask)
Fill a uint16_t buffer with random values chosen uniformly within a mask.
CHECKASM_API void checkasm_randomize_rangef(float *buf, int width, float range)
Fill a float buffer with random values chosen uniformly below a limit.
CHECKASM_API void checkasm_randomize_mask8(uint8_t *buf, int width, uint8_t mask)
Fill a uint8_t buffer with random values chosen uniformly within a mask.
CHECKASM_API void checkasm_randomize_norm(double *buf, int width)
Fill a double buffer with values from a standard normal distribution.
CHECKASM_API void checkasm_randomize_dist(double *buf, int width, CheckasmDist dist)
Fill a double buffer with normally distributed random values.
CHECKASM_API void checkasm_randomize_range(double *buf, int width, double range)
Fill a double buffer with random values chosen uniformly below a limit.
CHECKASM_API void checkasm_randomize_distf(float *buf, int width, CheckasmDist dist)
Fill a float buffer with normally distributed random values.
CHECKASM_API void checkasm_init(void *buf, size_t bytes)
Initialize a buffer with pathological test patterns.
CHECKASM_API void checkasm_init_mask16(uint16_t *buf, int width, uint16_t mask)
Initialize a uint16_t buffer with pathological values within a mask.
CHECKASM_API void checkasm_clear8(uint8_t *buf, int width, uint8_t val)
Fill a uint8_t buffer with a constant value.
CHECKASM_API int32_t checkasm_rand_int32(void)
Generate a random 32-bit signed integer.
CHECKASM_API int checkasm_rand(void)
Generate a random non-negative integer.
CHECKASM_API double checkasm_randf(void)
Generate a random double-precision floating-point number.
CHECKASM_API uint32_t checkasm_rand_uint32(void)
Generate a random 32-bit unsigned integer.
Describes a normal (Gaussian) distribution.
Definition utils.h:89
double stddev
Definition utils.h:91
double mean
Definition utils.h:90
CHECKASM_API double checkasm_rand_norm(void)
Generate a random number from the standard normal distribution.
CHECKASM_API double checkasm_rand_dist(CheckasmDist dist)
Generate a normally distributed random number.