1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
#include <iostream>
#define BOOST_TEST_MAIN
#include <boost/test/included/unit_test.hpp>
#include <boost/test/floating_point_comparison.hpp>
#include <cmath>
#include "../simd_memory.hpp"
#include "../benchmarks/cache_aligned_array.hpp"
#include "test_helper.hpp"
using namespace nova;
using namespace std;
static const unsigned int size = 64;
template <typename float_type>
void zero_tests(void)
{
aligned_array<float_type, size> out, out_simd, out_mp;
randomize_buffer<float_type>(out.c_array(), size);
randomize_buffer<float_type>(out_simd.c_array(), size);
randomize_buffer<float_type>(out_mp.c_array(), size);
zerovec<float_type>(out.c_array(), size);
zerovec_simd<float_type>(out_simd.c_array(), size);
zerovec_simd<size>(out_mp.c_array());
compare_buffers(out.c_array(), out_simd.c_array(), size);
compare_buffers(out.c_array(), out_mp.c_array(), size);
}
BOOST_AUTO_TEST_CASE( zero_test )
{
zero_tests<float>();
zero_tests<double>();
}
template <typename float_type>
void set_tests(void)
{
aligned_array<float_type, size> out, out_simd, out_mp;
randomize_buffer<float_type>(out.c_array(), size);
randomize_buffer<float_type>(out_simd.c_array(), size);
randomize_buffer<float_type>(out_mp.c_array(), size);
float_type f = randomize_float<float_type>();
setvec<float_type>(out.c_array(), f, size);
setvec_simd<float_type>(out_simd.c_array(), f, size);
setvec_simd<size>(out_mp.c_array(), f);
compare_buffers(out.c_array(), out_simd.c_array(), size);
compare_buffers(out.c_array(), out_mp.c_array(), size);
}
BOOST_AUTO_TEST_CASE( set_test )
{
set_tests<float>();
set_tests<double>();
}
template <typename float_type>
void add_tests(void)
{
aligned_array<float_type, size> out, out_simd, out_mp, in;
randomize_buffer<float_type>(in.c_array(), size);
randomize_buffer<float_type>(out.c_array(), size);
out_simd = out;
out_mp = out;
addvec<float_type>(out.c_array(), in.c_array(), size);
addvec_simd<float_type>(out_simd.c_array(), in.c_array(), size);
addvec_simd<size>(out_mp.c_array(), in.c_array());
compare_buffers(out.c_array(), out_simd.c_array(), size);
compare_buffers(out.c_array(), out_mp.c_array(), size);
}
BOOST_AUTO_TEST_CASE( add_test )
{
add_tests<float>();
add_tests<double>();
}
template <typename float_type>
void slope_tests(void)
{
aligned_array<float_type, size> out, out_simd;
float_type base = randomize_float<float_type>();
float_type slope = randomize_float<float_type>() * 0.01;
set_slope_vec<float_type>(out.c_array(), base, slope, size);
set_slope_vec_simd<float_type>(out_simd.c_array(), base, slope, size);
compare_buffers(out.c_array(), out_simd.c_array(), size);
}
BOOST_AUTO_TEST_CASE( slope_test )
{
slope_tests<float>();
slope_tests<double>();
}
template <typename float_type>
void exp_tests(void)
{
aligned_array<float_type, size> out, out_simd;
float_type base = std::abs(randomize_float<float_type>());
float_type slope = std::abs(randomize_float<float_type>() * 0.01) + 1;
set_exp_vec<float_type>(out.c_array(), base, slope, size);
set_exp_vec_simd<float_type>(out_simd.c_array(), base, slope, size);
compare_buffers(out.c_array(), out_simd.c_array(), size, 1e-5);
}
BOOST_AUTO_TEST_CASE( exp_test )
{
exp_tests<float>();
exp_tests<double>();
}
|