diff options
author | Erik Schnetter <schnetter@gmail.com> | 2013-11-25 15:01:05 -0500 |
---|---|---|
committer | Erik Schnetter <schnetter@gmail.com> | 2013-11-25 15:01:05 -0500 |
commit | 17a851a74ca26f78ff15b54f318031784ae8969a (patch) | |
tree | 85cd30316974b4e5000652c8ec8d9682e9bb44c0 | |
parent | 65acfefa515e33e3ea0066197f9bf979e4235b91 (diff) | |
download | vecmathlib-17a851a74ca26f78ff15b54f318031784ae8969a.zip vecmathlib-17a851a74ca26f78ff15b54f318031784ae8969a.tar.gz |
Run benchmarks of all functions, not just some
-rw-r--r-- | bench.cc | 274 |
1 files changed, 184 insertions, 90 deletions
@@ -87,33 +87,129 @@ void save_result(realvec_t result) for (int i=0; i<realvec_t::size; ++i) { global_result += result[i]; } + // Check global accumulator to prevent optimisation + if (! vml_std::isfinite(global_result)) { + cout << "\n" + << "WARNING: Global accumulator is not finite\n"; + } } template<typename T> inline T nop(T x) { return x; } +template<typename T> inline T fneg(T x) { return -x; } + +template<typename T> inline T fadd(T x, T y) { return x+y; } +template<typename T> inline T fsub(T x, T y) { return x-y; } +template<typename T> inline T fmul(T x, T y) { return x*y; } +template<typename T> inline T fdiv(T x, T y) { return x/y; } + +template<typename T> inline T frexp0(T x) +{ + typename T::intvec_t ir; + return frexp(x, &ir); +} +template<typename T> inline typename T::intvec_t frexp1(T x) +{ + typename T::intvec_t ir; + frexp(x, &ir); + return ir; +} + +template<typename T> inline T ldexps(T x, T y) +{ + typename T::intvec_t iy = convert_int(y); + return ldexp(x, iy[0]); +} +template<typename T> inline T ldexpv(T x, T y) +{ + typename T::intvec_t iy = convert_int(y); + return ldexp(x, iy); +} + + + #define DECLARE_FUNCTOR(FUNC, XMIN, XMAX) \ template<typename T> \ struct functor_##FUNC { \ static typename T::real_t get_xmin() { return XMIN; } \ static typename T::real_t get_xmax() { return XMAX; } \ static const char* name() { return #FUNC; } \ - T operator()(T x) { return FUNC(x); } \ + T operator()(T x) { \ + return FUNC(x); \ + } \ + } + +#define DECLARE_BFUNCTOR(FUNC, XMIN, XMAX) \ + template<typename T> \ + struct functor_##FUNC { \ + static typename T::real_t get_xmin() { return XMIN; } \ + static typename T::real_t get_xmax() { return XMAX; } \ + static const char* name() { return #FUNC; } \ + T operator()(T x) { \ + typename T::boolvec_t res = FUNC(x); \ + return convert_float(convert_int(res)); \ + } \ + } + +#define DECLARE_IFUNCTOR(FUNC, XMIN, XMAX) \ + template<typename T> \ + struct functor_##FUNC { \ + static typename T::real_t get_xmin() { return XMIN; } \ + static typename T::real_t get_xmax() { return XMAX; } \ + static const char* name() { return #FUNC; } \ + T operator()(T x) { \ + typename T::intvec_t res = FUNC(x); \ + return convert_float(res); \ + } \ } +#define DECLARE_FUNCTOR2(FUNC, XMIN, XMAX, YOFFSET) \ + template<typename T> \ + struct functor_##FUNC { \ + static typename T::real_t get_xmin() { return XMIN; } \ + static typename T::real_t get_xmax() { return XMAX; } \ + static const char* name() { return #FUNC; } \ + T operator()(T x) { \ + const typename T::real_t yoffset = YOFFSET; \ + return FUNC(x, x + T(yoffset)); \ + } \ + } + +#define DECLARE_FUNCTOR3(FUNC, XMIN, XMAX, YOFFSET, ZOFFSET) \ + template<typename T> \ + struct functor_##FUNC { \ + static typename T::real_t get_xmin() { return XMIN; } \ + static typename T::real_t get_xmax() { return XMAX; } \ + static const char* name() { return #FUNC; } \ + T operator()(T x) { \ + const typename T::real_t yoffset = YOFFSET; \ + const typename T::real_t zoffset = ZOFFSET; \ + return FUNC(x, x + T(yoffset), x + T(zoffset)); \ + } \ + } + + + DECLARE_FUNCTOR(nop, 0.0, 1.0); +DECLARE_FUNCTOR(fneg, 0.0, 1.0); +DECLARE_FUNCTOR2(fadd, 0.0, 1.0, 2.0); +DECLARE_FUNCTOR2(fsub, 0.0, 1.0, 2.0); +DECLARE_FUNCTOR2(fmul, 0.0, 1.0, 2.0); +DECLARE_FUNCTOR2(fdiv, 0.0, 1.0, 2.0); + DECLARE_FUNCTOR(acos, -0.5, +0.5); -DECLARE_FUNCTOR(acosh, 0.0, 1.0); +DECLARE_FUNCTOR(acosh, 1.0, 2.0); DECLARE_FUNCTOR(asin, -0.5, +0.5); DECLARE_FUNCTOR(asinh, -1.0, +1.0); DECLARE_FUNCTOR(atan, -1.0, +1.0); -// DECLARE_FUNCTOR(atan2, 0.0); +DECLARE_FUNCTOR2(atan2, 0.0, 1.0, 2.0); DECLARE_FUNCTOR(atanh, -0.5, +0.5); DECLARE_FUNCTOR(cbrt, -1.0, 1.0); DECLARE_FUNCTOR(ceil, -1.0, +1.0); -// DECLARE_FUNCTOR(copysign, 0.0); +DECLARE_FUNCTOR2(copysign, -1.0, +1.0, 2.0); DECLARE_FUNCTOR(cos, 0.0, 1.0); DECLARE_FUNCTOR(cosh, 0.0, 1.0); DECLARE_FUNCTOR(exp, 0.0, 1.0); @@ -122,32 +218,33 @@ DECLARE_FUNCTOR(exp2, 0.0, 1.0); DECLARE_FUNCTOR(expm1, 0.0, 1.0); DECLARE_FUNCTOR(fabs, -1.0, 1.0); DECLARE_FUNCTOR(floor, -1.0, +1.0); -// DECLARE_FUNCTOR(fdim, 0.0); -// DECLARE_FUNCTOR(fma, 0.0); -// DECLARE_FUNCTOR(fmax, 0.0); -// DECLARE_FUNCTOR(fmin, 0.0); -// DECLARE_FUNCTOR(fmod, 0.0); -// DECLARE_FUNCTOR(frexp, 0.0); -// DECLARE_FUNCTOR(hypot, 0.0); -// DECLARE_FUNCTOR(ilogb, 0.0); -// DECLARE_FUNCTOR(isfinite, 0.0); -// DECLARE_FUNCTOR(isinf, 0.0); -// DECLARE_FUNCTOR(isnan, 0.0); -// DECLARE_FUNCTOR(isnormal, 0.0); -// DECLARE_FUNCTOR(ldexp, 0.0); -// DECLARE_FUNCTOR(ldexp, 0.0); +DECLARE_FUNCTOR2(fdim, 0.0, 1.0, 2.0); +DECLARE_FUNCTOR3(fma, 0.0, 1.0, 2.0, 3.0); +DECLARE_FUNCTOR2(fmax, 0.0, 1.0, 2.0); +DECLARE_FUNCTOR2(fmin, 0.0, 1.0, 2.0); +DECLARE_FUNCTOR2(fmod, 0.0, 1.0, 2.0); +DECLARE_FUNCTOR(frexp0, 1.0, 100.0); +DECLARE_IFUNCTOR(frexp1, 1.0, 100.0); +DECLARE_FUNCTOR2(hypot, 0.0, 1.0, 2.0); +DECLARE_IFUNCTOR(ilogb, 1.0, 100.0); +DECLARE_BFUNCTOR(isfinite, 0.0, 1.0); +DECLARE_BFUNCTOR(isinf, 0.0, 1.0); +DECLARE_BFUNCTOR(isnan, 0.0, 1.0); +DECLARE_BFUNCTOR(isnormal, 0.0, 1.0); +DECLARE_FUNCTOR2(ldexps, 1.0, 20.0, -10.0); +DECLARE_FUNCTOR2(ldexpv, 1.0, 20.0, -10.0); DECLARE_FUNCTOR(log, 1.0, 2.0); DECLARE_FUNCTOR(log10, 1.0, 2.0); DECLARE_FUNCTOR(log1p, 0.0, 1.0); DECLARE_FUNCTOR(log2, 1.0, 2.0); -// DECLARE_FUNCTOR(nextafter, 0.0); -// DECLARE_FUNCTOR(pow, 0.0); +DECLARE_FUNCTOR2(nextafter, -1.0, +1.0, 0.0); +DECLARE_FUNCTOR2(pow, 0.0, 1.0, 2.0); DECLARE_FUNCTOR(rcp, 1.0, 2.0); -// DECLARE_FUNCTOR(remainder, 0.0); +DECLARE_FUNCTOR2(remainder, 0.0, 1.0, 2.0); DECLARE_FUNCTOR(rint, -1.0, +1.0); DECLARE_FUNCTOR(round, -1.0, +1.0); -DECLARE_FUNCTOR(rsqrt, 0.0, 1.0); -// DECLARE_FUNCTOR(signbit, 0.0); +DECLARE_FUNCTOR(rsqrt, 1.0, 2.0); +DECLARE_BFUNCTOR(signbit, -1.0, +1.0); DECLARE_FUNCTOR(sin, 0.0, 1.0); DECLARE_FUNCTOR(sinh, -1.0, +1.0); DECLARE_FUNCTOR(sqrt, 0.0, 1.0); @@ -201,45 +298,45 @@ template<template<typename> class func_t> void bench_func() { cout << "\n" - << "Benchmarking " << func_t<float_vec>().name() << ":\n"; + << "Benchmarking " << func_t<float32_vec>().name() << ":\n"; -// bench_type_func<realpseudovec<float,1>, func_t>(); -// // bench_type_func<realbuiltinvec<float,1>, func_t>(); -// bench_type_func<realtestvec<float,1>, func_t>(); -// #ifdef VECMATHLIB_HAVE_VEC_FLOAT_1 -// bench_type_func<realvec<float,1>, func_t>(); -// #endif -// #ifdef VECMATHLIB_HAVE_VEC_FLOAT_2 -// bench_type_func<realpseudovec<float,2>, func_t>(); -// // bench_type_func<realbuiltinvec<float,2>, func_t>(); -// // bench_type_func<realtestvec<float,2>, func_t>(); -// bench_type_func<realvec<float,2>, func_t>(); -// #endif -// #ifdef VECMATHLIB_HAVE_VEC_FLOAT_4 -// bench_type_func<realpseudovec<float,4>, func_t>(); -// // bench_type_func<realbuiltinvec<float,4>, func_t>(); -// // bench_type_func<realtestvec<float,4>, func_t>(); -// bench_type_func<realvec<float,4>, func_t>(); -// #endif -// #ifdef VECMATHLIB_HAVE_VEC_FLOAT_8 -// bench_type_func<realpseudovec<float,8>, func_t>(); -// // bench_type_func<realbuiltinvec<float,8>, func_t>(); -// // bench_type_func<realtestvec<float,8>, func_t>(); -// bench_type_func<realvec<float,8>, func_t>(); -// #endif + bench_type_func<realpseudovec<float,1>, func_t>(); + // bench_type_func<realbuiltinvec<float,1>, func_t>(); + bench_type_func<realtestvec<float,1>, func_t>(); +#ifdef VECMATHLIB_HAVE_VEC_FLOAT_1 + bench_type_func<realvec<float,1>, func_t>(); +#endif +#ifdef VECMATHLIB_HAVE_VEC_FLOAT_2 + bench_type_func<realpseudovec<float,2>, func_t>(); + // bench_type_func<realbuiltinvec<float,2>, func_t>(); + // bench_type_func<realtestvec<float,2>, func_t>(); + bench_type_func<realvec<float,2>, func_t>(); +#endif +#ifdef VECMATHLIB_HAVE_VEC_FLOAT_4 + bench_type_func<realpseudovec<float,4>, func_t>(); + // bench_type_func<realbuiltinvec<float,4>, func_t>(); + // bench_type_func<realtestvec<float,4>, func_t>(); + bench_type_func<realvec<float,4>, func_t>(); +#endif +#ifdef VECMATHLIB_HAVE_VEC_FLOAT_8 + bench_type_func<realpseudovec<float,8>, func_t>(); + // bench_type_func<realbuiltinvec<float,8>, func_t>(); + // bench_type_func<realtestvec<float,8>, func_t>(); + bench_type_func<realvec<float,8>, func_t>(); +#endif -// bench_type_func<realpseudovec<double,1>, func_t>(); -// // bench_type_func<realbuiltinvec<double,1>, func_t>(); -// bench_type_func<realtestvec<double,1>, func_t>(); -// #ifdef VECMATHLIB_HAVE_VEC_DOUBLE_1 -// bench_type_func<realvec<double,1>, func_t>(); -// #endif -// #ifdef VECMATHLIB_HAVE_VEC_DOUBLE_2 -// bench_type_func<realpseudovec<double,2>, func_t>(); -// // bench_type_func<realbuiltinvec<double,2>, func_t>(); -// // bench_type_func<realtestvec<double,2>, func_t>(); -// bench_type_func<realvec<double,2>, func_t>(); -// #endif + bench_type_func<realpseudovec<double,1>, func_t>(); + // bench_type_func<realbuiltinvec<double,1>, func_t>(); + bench_type_func<realtestvec<double,1>, func_t>(); +#ifdef VECMATHLIB_HAVE_VEC_DOUBLE_1 + bench_type_func<realvec<double,1>, func_t>(); +#endif +#ifdef VECMATHLIB_HAVE_VEC_DOUBLE_2 + bench_type_func<realpseudovec<double,2>, func_t>(); + // bench_type_func<realbuiltinvec<double,2>, func_t>(); + // bench_type_func<realtestvec<double,2>, func_t>(); + bench_type_func<realvec<double,2>, func_t>(); +#endif #ifdef VECMATHLIB_HAVE_VEC_DOUBLE_4 bench_type_func<realpseudovec<double,4>, func_t>(); // bench_type_func<realbuiltinvec<double,4>, func_t>(); @@ -252,16 +349,22 @@ void bench() { bench_func<functor_nop>(); + bench_func<functor_fneg>(); + bench_func<functor_fadd>(); + bench_func<functor_fsub>(); + bench_func<functor_fmul>(); + bench_func<functor_fdiv>(); + bench_func<functor_acos>(); bench_func<functor_acosh>(); bench_func<functor_asin>(); bench_func<functor_asinh>(); bench_func<functor_atan>(); - // bench_func<functor_atan2>(); + bench_func<functor_atan2>(); bench_func<functor_atanh>(); bench_func<functor_cbrt>(); bench_func<functor_ceil>(); - // bench_func<functor_copysign>(); + bench_func<functor_copysign>(); bench_func<functor_cos>(); bench_func<functor_cosh>(); bench_func<functor_exp>(); @@ -270,32 +373,33 @@ void bench() bench_func<functor_expm1>(); bench_func<functor_fabs>(); bench_func<functor_floor>(); - // bench_func<functor_fdim>(); - // bench_func<functor_fma>(); - // bench_func<functor_fmax>(); - // bench_func<functor_fmin>(); - // bench_func<functor_fmod>(); - // bench_func<functor_frexp>(); - // bench_func<functor_hypot>(); - // bench_func<functor_ilogb>(); - // bench_func<functor_isfinite>(); - // bench_func<functor_isinf>(); - // bench_func<functor_isnan>(); - // bench_func<functor_isnormal>(); - // bench_func<functor_ldexp>(); - // bench_func<functor_ldexp>(); + bench_func<functor_fdim>(); + bench_func<functor_fma>(); + bench_func<functor_fmax>(); + bench_func<functor_fmin>(); + bench_func<functor_fmod>(); + bench_func<functor_frexp0>(); + bench_func<functor_frexp1>(); + bench_func<functor_hypot>(); + bench_func<functor_ilogb>(); + bench_func<functor_isfinite>(); + bench_func<functor_isinf>(); + bench_func<functor_isnan>(); + bench_func<functor_isnormal>(); + bench_func<functor_ldexps>(); + bench_func<functor_ldexpv>(); bench_func<functor_log>(); bench_func<functor_log10>(); bench_func<functor_log1p>(); bench_func<functor_log2>(); - // bench_func<functor_nextafter>(); - // bench_func<functor_pow>(); + bench_func<functor_nextafter>(); + bench_func<functor_pow>(); bench_func<functor_rcp>(); - // bench_func<functor_remainder>(); + bench_func<functor_remainder>(); bench_func<functor_rint>(); bench_func<functor_round>(); bench_func<functor_rsqrt>(); - // bench_func<functor_signbit>(); + bench_func<functor_signbit>(); bench_func<functor_sin>(); bench_func<functor_sinh>(); bench_func<functor_sqrt>(); @@ -308,17 +412,7 @@ void bench() int main(int argc, char** argv) { - using namespace vecmathlib; - cout << "Benchmarking math functions:\n"; - bench(); - - // Checking global accumulator to prevent optimisation - if (! std::isfinite(global_result)) { - cout << "\n" - << "WARNING: Global accumulator is not finite\n"; - } - return 0; } |