Go to the documentation of this file.
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)
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__)
482 #define checkasm_check2d(type, ...) checkasm_check2(type, __VA_ARGS__, 0, 0, 0)
504 #define checkasm_check2d_padded(type, ...) checkasm_check2(type, __VA_ARGS__)
526 #define checkasm_check1d(type, buf1, buf2, len, ...) \
527 checkasm_check2d(type, buf1, 0, buf2, 0, len, 1, __VA_ARGS__)
546 #define checkasm_check1d_padded(type, buf1, buf2, len, name, align, padding) \
547 checkasm_check2d_padded(type, buf1, 0, buf2, 0, len, 1, name, align, 0, padding)
553 #define checkasm_check checkasm_check2d
554 #define checkasm_check_padded checkasm_check2d_padded
574 #define CHECKASM_ROUND(x, a) (((x) + ((a) - 1)) & ~((a) - 1))
605 #define BUF_RECT(type, name, w, h) \
606 DECL_CHECK_FUNC(*checkasm_check_impl_##name##_type, type) \
607 = checkasm_check_impl_##type; \
608 CHECKASM_ALIGN(type name##_buf[((h) + 32) * (CHECKASM_ROUND(w, 64) + 64) + 64]); \
609 const int name##_buf_w = CHECKASM_ROUND(w, 64) + 64; \
610 const int name##_buf_h = (h) + 32; \
611 ptrdiff_t name##_stride = sizeof(type) * name##_buf_w; \
612 (void) checkasm_check_impl(name##_type); \
613 (void) name##_stride; \
614 (void) name##_buf_h; \
615 type *name = name##_buf + name##_buf_w * 16 + 64
623 #define CLEAR_BUF_RECT(name) CLEAR_BUF(name##_buf)
631 #define INITIALIZE_BUF_RECT(name) INITIALIZE_BUF(name##_buf)
639 #define RANDOMIZE_BUF_RECT(name) RANDOMIZE_BUF(name##_buf)
648 #define checkasm_check_rect(rect1, ...) checkasm_check2d(rect1##_type, rect1, __VA_ARGS__)
657 #define checkasm_check_rect_padded(rect1, ...) \
658 checkasm_check2d_padded(rect1##_type, rect1, __VA_ARGS__, 1, 1, 8)
673 #define checkasm_check_rect_padded_align(rect1, ...) \
674 checkasm_check2d_padded(rect1##_type, rect1, __VA_ARGS__, 8)
685 #define CHECK_BUF_RECT(buf1, buf2, w, h) \
686 checkasm_check_rect_padded(buf1, buf1##_stride, buf2, buf2##_stride, w, h, \
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_randomize_dist(double *buf, int width, CheckasmDist dist)
Fill a double buffer with normally distributed random values.
double stddev
Standard deviation (spread) of the distribution.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
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 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 void checkasm_clear8(uint8_t *buf, int width, uint8_t val)
Fill a uint8_t buffer with a constant value.
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 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 double checkasm_randf(void)
Generate a random double-precision floating-point number.
CHECKASM_API void checkasm_randomize_range(double *buf, int width, double range)
Fill a double buffer with random values chosen uniformly below a limit.
Platform and compiler attribute macros.
static double val(void *priv, double ch)
CHECKASM_API int checkasm_float_near_abs_eps(float a, float b, float eps)
Compare floats using absolute epsilon tolerance.
CHECKASM_API void checkasm_randomize_norm(double *buf, int width)
Fill a double buffer with values from a standard normal distribution.
CHECKASM_API int32_t checkasm_rand_int32(void)
Generate a random 32-bit signed integer.
CHECKASM_API void checkasm_init(void *buf, size_t bytes)
Initialize a buffer with pathological test patterns.
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 void checkasm_randomize(void *buf, size_t bytes)
Fill a buffer with uniformly chosen random bytes.
double mean
Mean (center) of the distribution.
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 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 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 double checkasm_rand_norm(void)
Generate a random number from the standard normal distribution.
CHECKASM_API void checkasm_randomize_normf(float *buf, int width)
Fill a float buffer with values from a standard normal distribution.
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
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.
Describes a normal (Gaussian) distribution.
#define DECL_CHECKASM_CHECK_FUNC(type)
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 void checkasm_randomize_rangef(float *buf, int width, float range)
Fill a float buffer with random values chosen uniformly below a limit.
#define CHECKASM_API
Symbol visibility attribute for public API functions.
CHECKASM_API int checkasm_rand(void)
Generate a random non-negative integer.
CHECKASM_API void checkasm_clear(void *buf, size_t bytes)
Clear a buffer to a pre-determined pattern (currently 0xAA)
CHECKASM_API void checkasm_clear16(uint16_t *buf, int width, uint16_t val)
Fill a uint16_t buffer with a constant value.
CHECKASM_API double checkasm_rand_dist(CheckasmDist dist)
Generate a normally distributed random number.
CHECKASM_API int checkasm_double_near_abs_eps(double a, double b, double eps)
Compare doubles using absolute epsilon tolerance.
CHECKASM_API uint32_t checkasm_rand_uint32(void)
Generate a random 32-bit unsigned integer.