1 #include <iostream>
2 #define BOOST_TEST_MAIN
3 #include <boost/test/included/unit_test.hpp>
4 #include <boost/test/floating_point_comparison.hpp>
5 
6 #include <cmath>
7 
8 #include "test_helper.hpp"
9 
10 #include "../benchmarks/cache_aligned_array.hpp"
11 #include "../simd_binary_arithmetic.hpp"
12 
13 using namespace nova;
14 using namespace std;
15 
16 static const unsigned int size = 64;
17 
18 #define COMPARE_TEST(function)                                          \
19     template <typename float_type>                                      \
20     void function##_compare_vv(void)                                    \
21     {                                                                   \
22         aligned_array<float_type, size> out, out_simd, out_mp,          \
23             in0, in1;                                                   \
24         randomize_buffer<float_type>(in0.c_array(), size);              \
25         randomize_buffer<float_type>(in1.c_array(), size);              \
26                                                                         \
27         function##_vec<float_type>(out.c_array(), in0.c_array(),        \
28                                    in1.c_array(), size);                \
29         function##_vec_simd<float_type>(out_simd.c_array(),             \
30                                         in0.c_array(),                  \
31                                         in1.c_array(), size);           \
32         function##_vec_simd<size>(out_mp.c_array(), in0.c_array(),      \
33                                         in1.c_array());                 \
34                                                                         \
35         compare_buffers(out.c_array(), out_simd.c_array(), size);       \
36         compare_buffers(out.c_array(), out_mp.c_array(), size);         \
37     }                                                                   \
38                                                                         \
39     template <typename float_type>                                      \
40     void function##_compare_vs(void)                                    \
41     {                                                                   \
42         aligned_array<float_type, size> out, out_simd, out_mp, in0;     \
43         randomize_buffer<float_type>(in0.c_array(), size);              \
44         float_type in1 = randomize_float<float_type>();                 \
45                                                                         \
46         function##_vec<float_type>(out.c_array(), in0.c_array(),        \
47                                    in1, size);                          \
48         function##_vec_simd<float_type>(out_simd.c_array(),             \
49                                         in0.c_array(),                  \
50                                         in1, size);                     \
51         function##_vec_simd<size>(out_mp.c_array(), in0.c_array(),      \
52                                   in1);                                 \
53                                                                         \
54         compare_buffers(out.c_array(), out_simd.c_array(), size);       \
55         compare_buffers(out.c_array(), out_mp.c_array(), size);         \
56     }                                                                   \
57                                                                         \
58     template <typename float_type>                                      \
59     void function##_compare_sv(void)                                    \
60     {                                                                   \
61         aligned_array<float_type, size> out, out_simd, out_mp, in0;     \
62         randomize_buffer<float_type>(in0.c_array(), size);              \
63         float_type in1 = randomize_float<float_type>();                 \
64                                                                         \
65         function##_vec<float_type>(out.c_array(), in1,                  \
66                                    in0.c_array(), size);                \
67         function##_vec_simd<float_type>(out_simd.c_array(), in1,        \
68                                         in0.c_array(), size);           \
69         function##_vec_simd<size>(out_mp.c_array(), in1, in0.c_array()); \
70                                                                         \
71         compare_buffers(out.c_array(), out_simd.c_array(), size);       \
72         compare_buffers(out.c_array(), out_mp.c_array(), size);         \
73     }                                                                   \
74                                                                         \
75     template <typename float_type>                                      \
76     void function##_compare_vr(void)                                    \
77     {                                                                   \
78         aligned_array<float_type, size> out, out_simd, out_mp, in0;     \
79         randomize_buffer<float_type>(in0.c_array(), size);              \
80         float_type in1 = randomize_float<float_type>();                 \
81         float_type in1_slope = randomize_float_slope<float_type>();     \
82                                                                         \
83         function##_vec<float_type>(out.c_array(), in0.c_array(),        \
84                                    slope_argument(in1, in1_slope), size); \
85         function##_vec_simd<float_type>(out_simd.c_array(),             \
86                                         in0.c_array(),                  \
87                                         slope_argument(in1, in1_slope), size); \
88         function##_vec_simd<size>(out_mp.c_array(), in0.c_array(),      \
89                                   slope_argument(in1, in1_slope));      \
90                                                                         \
91         compare_buffers(out.c_array(), out_simd.c_array(), size, 5e-4); \
92         compare_buffers(out.c_array(), out_mp.c_array(), size, 5e-4);   \
93     }                                                                   \
94                                                                         \
95     template <typename float_type>                                      \
96     void function##_compare_rv(void)                                    \
97     {                                                                   \
98         aligned_array<float_type, size> out, out_simd, out_mp, in0;     \
99         randomize_buffer<float_type>(in0.c_array(), size);              \
100         float_type in1 = randomize_float<float_type>();                 \
101         float_type in1_slope = randomize_float_slope<float_type>();     \
102                                                                         \
103         function##_vec<float_type>(out.c_array(), slope_argument(in1, in1_slope), \
104                                    in0.c_array(), size);                \
105         function##_vec_simd<float_type>(out_simd.c_array(),             \
106                                         slope_argument(in1, in1_slope), \
107                                         in0.c_array(), size);           \
108         function##_vec_simd<size>(out_mp.c_array(), slope_argument(in1, in1_slope), \
109                                   in0.c_array());                       \
110                                                                         \
111         compare_buffers(out.c_array(), out_simd.c_array(), size, 5e-4); \
112         compare_buffers(out.c_array(), out_mp.c_array(), size, 5e-4);   \
113     }                                                                   \
114                                                                         \
115     BOOST_AUTO_TEST_CASE( function##_comparer_vv )                      \
116     {                                                                   \
117         function##_compare_vv<float>();                                 \
118         function##_compare_vv<double>();                                \
119     }                                                                   \
120                                                                         \
121     BOOST_AUTO_TEST_CASE( function##_comparer_vs )                      \
122     {                                                                   \
123         function##_compare_vs<float>();                                 \
124         function##_compare_vs<double>();                                \
125     }                                                                   \
126                                                                         \
127     BOOST_AUTO_TEST_CASE( function##_comparer_vr )                      \
128     {                                                                   \
129         function##_compare_vr<float>();                                 \
130         function##_compare_vr<double>();                                \
131     }                                                                   \
132                                                                         \
133     BOOST_AUTO_TEST_CASE( function##_comparer_sv )                      \
134     {                                                                   \
135         function##_compare_sv<float>();                                 \
136         function##_compare_sv<double>();                                \
137     }                                                                   \
138                                                                         \
139     BOOST_AUTO_TEST_CASE( function##_comparer_rv )                      \
140     {                                                                   \
141         function##_compare_rv<float>();                                 \
142         function##_compare_rv<double>();                                \
143     }
144 
145 
146 COMPARE_TEST(plus)
147 COMPARE_TEST(minus)
148 COMPARE_TEST(times)
149 COMPARE_TEST(over)
150 COMPARE_TEST(min)
151 COMPARE_TEST(max)
152 COMPARE_TEST(less)
153 COMPARE_TEST(less_equal)
154 COMPARE_TEST(greater)
155 COMPARE_TEST(greater_equal)
156 COMPARE_TEST(equal)
157 COMPARE_TEST(notequal)
158 COMPARE_TEST(clip2)
159