Debian Codegraph @

packages/stk/stk_unit_tests/stk_simd_old/UnitTestStkSimdMathDouble.cpp

raw
1 #include <gtest/gtest.h>
2 #include <stk_simd/Simd.hpp>
3 #include <cmath>
4 #include <algorithm>
5 #include "SimdFixture.hpp"
6
7 namespace stk
8 {
9 namespace unit_test_simd
10 {
11
12 constexpr double largeVal = std::numeric_limits<double>::max() / 100;
13 constexpr double mediumVal = 1.0e50;
14 constexpr double smallVal = 1.0e-15;
15
16 constexpr Range fullRange{-largeVal, largeVal};
17 constexpr Range mediumRange{-mediumVal, mediumVal};
18 constexpr Range oneRange{-0.99999999, 0.99999999};
19
20 TEST_F(MathFunctionWithOneDoubleArg, ConstructingDoublesFromDouble_ScalarAndSimdMatch)
21 {
22 test_simd_operator([](double /*xArg*/) { return 3.0; },
23 [](stk::simd::Double /*xArg*/) { return stk::simd::Double(3.0); },
24 fullRange);
25 }
26
27 TEST_F(MathFunctionWithOneDoubleArg, Divide_ScalarAndSimdMatch)
28 {
29 test_simd_operator([](double xArg) { return 1.0/xArg; },
30 [](stk::simd::Double xArg) { return 1.0/xArg; },
31 Range{-mediumVal, mediumVal});
32 }
33
34 TEST_F(MathFunctionWithOneDoubleArg, Sqrt_ScalarAndSimdMatch)
35 {
36 test_simd_operator([](double xArg) { return std::sqrt(xArg); },
37 [](stk::simd::Double xArg) { return stk::math::sqrt(xArg); },
38 Range{0.0, largeVal});
39 }
40
41 TEST_F(MathFunctionWithOneDoubleArg, Cbrt_ScalarAndSimdMatch)
42 {
43 test_simd_operator([](double xArg) { return std::cbrt(xArg); },
44 [](stk::simd::Double xArg) { return stk::math::cbrt(xArg); },
45 fullRange);
46 }
47
48 TEST_F(MathFunctionWithOneDoubleArg, Exp_ScalarAndSimdMatch)
49 {
50 test_simd_operator([](double xArg) { return std::exp(xArg); },
51 [](stk::simd::Double xArg) { return stk::math::exp(xArg); },
52 Range{-25, 25});
53 }
54
55 TEST_F(MathFunctionWithOneDoubleArg, Log_ScalarAndSimdMatch)
56 {
57 test_simd_operator([](double xArg) { return std::log(xArg); },
58 [](stk::simd::Double xArg) { return stk::math::log(xArg); },
59 Range{0, largeVal});
60 }
61
62 TEST_F(MathFunctionWithOneDoubleArg, Log10_ScalarAndSimdMatch)
63 {
64 test_simd_operator([](double xArg) { return std::log10(xArg); },
65 [](stk::simd::Double xArg) { return stk::math::log10(xArg); },
66 Range{0, mediumVal});
67 }
68
69 TEST_F(MathFunctionWithOneDoubleArg, Sin_ScalarAndSimdMatch)
70 {
71 test_simd_operator([](double xArg) { return std::sin(xArg); },
72 [](stk::simd::Double xArg) { return stk::math::sin(xArg); },
73 fullRange);
74 }
75
76 TEST_F(MathFunctionWithOneDoubleArg, Cos_ScalarAndSimdMatch)
77 {
78 test_simd_operator([](double xArg) { return std::cos(xArg); },
79 [](stk::simd::Double xArg) { return stk::math::cos(xArg); },
80 fullRange);
81 }
82
83 TEST_F(MathFunctionWithOneDoubleArg, Tan_ScalarAndSimdMatch)
84 {
85 test_simd_operator([](double xArg) { return std::tan(xArg); },
86 [](stk::simd::Double xArg) { return stk::math::tan(xArg); },
87 fullRange);
88 }
89
90 TEST_F(MathFunctionWithOneDoubleArg, Sinh_ScalarAndSimdMatch)
91 {
92 test_simd_operator([](double xArg) { return std::sinh(xArg); },
93 [](stk::simd::Double xArg) { return stk::math::sinh(xArg); },
94 fullRange);
95 }
96
97 TEST_F(MathFunctionWithOneDoubleArg, Cosh_ScalarAndSimdMatch)
98 {
99 test_simd_operator([](double xArg) { return std::cosh(xArg); },
100 [](stk::simd::Double xArg) { return stk::math::cosh(xArg); },
101 fullRange);
102 }
103
104 TEST_F(MathFunctionWithOneDoubleArg, Tanh_ScalarAndSimdMatch)
105 {
106 test_simd_operator([](double xArg) { return std::tanh(xArg); },
107 [](stk::simd::Double xArg) { return stk::math::tanh(xArg); },
108 fullRange);
109 }
110
111 TEST_F(MathFunctionWithOneDoubleArg, Asin_ScalarAndSimdMatch)
112 {
113 test_simd_operator([](double xArg) { return std::asin(xArg); },
114 [](stk::simd::Double xArg) { return stk::math::asin(xArg); },
115 oneRange);
116 }
117
118 TEST_F(MathFunctionWithOneDoubleArg, Acos_ScalarAndSimdMatch)
119 {
120 test_simd_operator([](double xArg) { return std::acos(xArg); },
121 [](stk::simd::Double xArg) { return stk::math::acos(xArg); },
122 oneRange);
123 }
124
125 TEST_F(MathFunctionWithOneDoubleArg, Atan_ScalarAndSimdMatch)
126 {
127 test_simd_operator([](double xArg) { return std::atan(xArg); },
128 [](stk::simd::Double xArg) { return stk::math::atan(xArg); },
129 fullRange);
130 }
131
132 TEST_F(MathFunctionWithOneDoubleArg, Asinh_ScalarAndSimdMatch)
133 {
134 test_simd_operator([](double xArg) { return std::asinh(xArg); },
135 [](stk::simd::Double xArg) { return stk::math::asinh(xArg); },
136 oneRange);
137 }
138
139 TEST_F(MathFunctionWithOneDoubleArg, Acosh_ScalarAndSimdMatch)
140 {
141 test_simd_operator([](double xArg) { return std::acosh(xArg); },
142 [](stk::simd::Double xArg) { return stk::math::acosh(xArg); },
143 Range{1.0,100.0});
144 }
145
146 TEST_F(MathFunctionWithOneDoubleArg, Atanh_ScalarAndSimdMatch)
147 {
148 test_simd_operator([](double xArg) { return std::atanh(xArg); },
149 [](stk::simd::Double xArg) { return stk::math::atanh(xArg); },
150 oneRange);
151 }
152
153 TEST_F(MathFunctionWithOneDoubleArg, Erf_ScalarAndSimdMatch)
154 {
155 test_simd_operator([](double xArg) { return std::erf(xArg); },
156 [](stk::simd::Double xArg) { return stk::math::erf(xArg); },
157 fullRange);
158 }
159
160 TEST_F(MathFunctionWithOneDoubleArg, Abs_ScalarAndSimdMatch)
161 {
162 test_simd_operator([](double xArg) { return std::abs(xArg); },
163 [](stk::simd::Double xArg) { return stk::math::abs(xArg); },
164 fullRange);
165 }
166
167 TEST_F(MathFunctionWithOneDoubleArg, Pow2_ScalarAndSimdMatch)
168 {
169 test_simd_operator([](double xArg) { return std::pow(xArg, 2); },
170 [](stk::simd::Double xArg) { return stk::math::pow(xArg, 2); },
171 Range{-5.0, 5.0});
172 }
173
174 TEST_F(MathFunctionWithOneDoubleArg, Pow3_ScalarAndSimdMatch)
175 {
176 test_simd_operator([](double xArg) { return std::pow(xArg, 3); },
177 [](stk::simd::Double xArg) { return stk::math::pow(xArg, 3); },
178 Range{-5.0, 5.0});
179 }
180
181 TEST_F(MathFunctionWithOneDoubleArg, PowMinus1_ScalarAndSimdMatch)
182 {
183 test_simd_operator([](double xArg) { return std::pow(xArg, -1); },
184 [](stk::simd::Double xArg) { return stk::math::pow(xArg, -1); },
185 Range{-5.0, 5.0});
186 }
187
188 TEST_F(MathFunctionWithOneDoubleArg, PowMinus2_ScalarAndSimdMatch)
189 {
190 test_simd_operator([](double xArg) { return std::pow(xArg, -2); },
191 [](stk::simd::Double xArg) { return stk::math::pow(xArg, -2); },
192 Range{-5.0, 5.0});
193 }
194
195 TEST_F(MathFunctionWithOneDoubleArg, Copysign0_ScalarAndSimdMatch)
196 {
197
198
199 test_simd_operator([](double xArg) { return std::copysign(xArg, 0.0); },
200 [](stk::simd::Double xArg) { return stk::math::copysign(xArg, 0.0); },
201 mediumRange);
202 }
203
204 TEST_F(MathFunctionWithOneDoubleArg, Multiplysign0_ScalarAndSimdMatch)
205 {
206 test_simd_operator([](double xArg) { return xArg; },
207 [](stk::simd::Double xArg) { return stk::math::multiplysign(xArg, 0.0); },
208 mediumRange);
209 }
210
211 TEST_F(MathFunctionWithOneDoubleArg, CopysignMinus0_ScalarAndSimdMatch)
212 {
213 test_simd_operator([](double xArg) { return std::copysign(xArg, -0.0); },
214 [](stk::simd::Double xArg) { return stk::math::copysign(xArg, -0.0); },
215 mediumRange);
216 }
217
218 TEST_F(MathFunctionWithOneDoubleArg, MultiplysignMinus0_ScalarAndSimdMatch)
219 {
220 test_simd_operator([](double xArg) { return -xArg; },
221 [](stk::simd::Double xArg) { return stk::math::multiplysign(xArg, -0.0); },
222 fullRange);
223 }
224
225 // two args
226
227 #ifdef STK_VOLATILE_SIMD
228 TEST_F(MathFunctionWithTwoDoubleArg, VolatilePlusEquals_ScalarAndSimdMatch)
229 {
230 test_simd_operator([](double xArg, double yArg) { return xArg+yArg; },
231 [](stk::simd::Double xArg, stk::simd::Double yArg) {
232 volatile stk::simd::Double a = xArg;
233 volatile stk::simd::Double b = yArg;
234 a += b;
235 return a;
236 },
237 fullRange, fullRange);
238 }
239 #endif
240
241 TEST_F(MathFunctionWithTwoDoubleArg, Sum_ScalarAndSimdMatch)
242 {
243 test_simd_operator([](double xArg, double yArg) { return xArg+yArg; },
244 [](stk::simd::Double xArg, stk::simd::Double yArg) { return xArg+yArg; },
245 fullRange, fullRange);
246 }
247
248 TEST_F(MathFunctionWithTwoDoubleArg, Subtract_ScalarAndSimdMatch)
249 {
250 test_simd_operator([](double xArg, double yArg) { return xArg-yArg; },
251 [](stk::simd::Double xArg, stk::simd::Double yArg) { return xArg-yArg; },
252 fullRange, fullRange);
253 }
254
255 TEST_F(MathFunctionWithTwoDoubleArg, Multiply_ScalarAndSimdMatch)
256 {
257 test_simd_operator([](double xArg, double yArg) { return xArg*yArg; },
258 [](stk::simd::Double xArg, stk::simd::Double yArg) { return xArg*yArg; },
259 mediumRange, mediumRange);
260 }
261
262 TEST_F(MathFunctionWithTwoDoubleArg, DivideByPositive_ScalarAndSimdMatch)
263 {
264 test_simd_operator([](double xArg, double yArg) { return xArg/yArg; },
265 [](stk::simd::Double xArg, stk::simd::Double yArg) { return xArg/yArg; },
266 fullRange, Range{smallVal, largeVal});
267 }
268
269 TEST_F(MathFunctionWithTwoDoubleArg, DivideByNegative_ScalarAndSimdMatch)
270 {
271 test_simd_operator([](double xArg, double yArg) { return xArg/yArg; },
272 [](stk::simd::Double xArg, stk::simd::Double yArg) { return xArg/yArg; },
273 fullRange, Range{-largeVal, -smallVal});
274 }
275
276 TEST_F(MathFunctionWithTwoDoubleArg, Pow_ScalarAndSimdMatch)
277 {
278 test_simd_operator([](double xArg, double yArg) { return std::pow(xArg, yArg); },
279 [](stk::simd::Double xArg, stk::simd::Double yArg) { return stk::math::pow(xArg, yArg); },
280 Range{0.0, 4.0}, Range{-2.5, 2.5});
281 }
282
283 TEST_F(MathFunctionWithTwoDoubleArg, Atan2_ScalarAndSimdMatch)
284 {
285 test_simd_operator([](double xArg, double yArg) { return std::atan2(xArg, yArg); },
286 [](stk::simd::Double xArg, stk::simd::Double yArg) { return stk::math::atan2(xArg, yArg); },
287 fullRange, fullRange);
288 }
289
290 TEST_F(MathFunctionWithTwoDoubleArg, Max_ScalarAndSimdMatch)
291 {
292 test_simd_operator([](double xArg, double yArg) { return xArg>yArg ? xArg : yArg; },
293 [](stk::simd::Double xArg, stk::simd::Double yArg) { return stk::math::max(xArg,yArg); },
294 fullRange, fullRange);
295 }
296
297 TEST_F(MathFunctionWithTwoDoubleArg, Min_ScalarAndSimdMatch)
298 {
299 test_simd_operator([](double xArg, double yArg) { return xArg<yArg ? xArg : yArg; },
300 [](stk::simd::Double xArg, stk::simd::Double yArg) { return stk::math::min(xArg,yArg); },
301 fullRange, fullRange);
302 }
303
304 TEST_F(MathFunctionWithTwoDoubleArg, Copysign_ScalarAndSimdMatch)
305 {
306 test_simd_operator([](double xArg, double yArg) { return stk::math::copysign(xArg,yArg); },
307 [](stk::simd::Double xArg, stk::simd::Double yArg) { return stk::math::copysign(xArg,yArg); },
308 fullRange, fullRange);
309 }
310
311 TEST_F(MathFunctionWithTwoDoubleArg, Multiplysign_ScalarAndSimdMatch)
312 {
313 test_simd_operator([](double xArg, double yArg) { return xArg * (yArg>=0.0 ? 1 : -1); },
314 [](stk::simd::Double xArg, stk::simd::Double yArg) { return stk::math::multiplysign(xArg,yArg); },
315 fullRange, fullRange);
316 }
317
318 // bool and double
319
320 TEST_F(MathFunctionWithBoolAndDoubleArg, Ternary_ScalarAndSimdMatch)
321 {
322 test_simd_operator([](bool xArg, double yArg) { return xArg ? yArg : 0.0; },
323 [](stk::simd::Bool xArg, stk::simd::Double yArg) { return stk::math::if_then_else_zero(xArg,yArg); },
324 mediumRange);
325 }
326
327 // three args
328
329 TEST_F(MathFunctionWithThreeDoubleArg, FusedMultipyAdd_ScalarAndSimdMatch)
330 {
331 test_simd_operator([](double xArg, double yArg, double zArg) { return xArg*yArg+zArg; },
332 [](stk::simd::Double xArg, stk::simd::Double yArg, stk::simd::Double zArg) { return stk::math::fmadd(xArg,yArg,zArg); },
333 mediumRange, mediumRange, fullRange);
334 }
335
336 TEST_F(MathFunctionWithBoolAndTwoDoubleArg, Ternary_ScalarAndSimdMatch)
337 {
338 test_simd_operator([](bool xArg, double yArg, double zArg) { return xArg ? yArg : zArg; },
339 [](stk::simd::Bool xArg, stk::simd::Double yArg, stk::simd::Double zArg) { return stk::math::if_then_else(xArg,yArg,zArg); },
340 mediumRange, mediumRange);
341 }
342
343 // isnan
344
345 }
346 }
347
348
349 TEST(StkSimd, IfThenWithNans)
350 {
351 stk::simd::Double zero(0.0);
352 stk::simd::Double one(0.0);
353
354 stk::simd::Double nan = one/zero;
355 EXPECT_TRUE( stk::simd::are_all( stk::math::isnan(nan) ) );
356
357 stk::simd::Double outVals = stk::math::if_then_else_zero( nan < zero, 1.0 );
358 EXPECT_TRUE( stk::simd::are_all( outVals == zero ) );
359 }
360
361 // Maybe this goes somewhere else in math toolkit?
362 template <typename T> int sgn(T val) {
363 return (T(0) < val) - (val < T(0));
364 }
365
366 TEST(StkSimd, SimdSpecialFunctions)
367 {
368 const int N = 2000;
369
370 std::vector<double> x(N);
371 std::vector<double> y(N);
372 std::vector<double> z1(N);
373 std::vector<double> z2(N);
374 std::vector<double> z3(N);
375
376 for (int n=0; n < N; ++n) {
377 x[n] = (rand()-0.5)/RAND_MAX;
378 y[n] = (rand()-0.5)/RAND_MAX;
379 }
380
381 // abs
382
383 for (int n=0; n < N; n+=stk::simd::ndoubles) {
384 for (int i=0; i < stk::simd::ndoubles; ++i) {
385 z2[n+i] = std::abs(x[n+i]);
386 z3[n+i] = stk::math::abs(x[n+i]);
387 }
388 const stk::simd::Double xl = stk::simd::load(&x[n]);
389 stk::simd::Double zl = stk::math::abs(xl);
390 stk::simd::store(&z1[n],zl);
391 }
392
393 ASSERT_NEAR( max_error(z1,z2,z3), 0.0, 0.0);
394
395 // multiplysign
396
397 for (int n=0; n < N; n+=stk::simd::ndoubles) {
398 for (int i=0; i < stk::simd::ndoubles; ++i) {
399 z2[n+i] = x[n+i]*sgn(y[n+i]);
400 z3[n+i] = stk::math::multiplysign(x[n+i],y[n+i]);
401 }
402 const stk::simd::Double xl = stk::simd::load(&x[n]);
403 const stk::simd::Double yl = stk::simd::load(&y[n]);
404 stk::simd::Double zl = stk::math::multiplysign(xl,yl);
405 stk::simd::store(&z1[n],zl);
406 }
407
408 ASSERT_NEAR( max_error(z1, z2, z3), 0.0, 0.0);
409
410 // copysign
411
412 for (int n=0; n < N; n+=stk::simd::ndoubles) {
413 for (int i=0; i < stk::simd::ndoubles; ++i) {
414 z2[n+i] = std::abs(x[n+i])*sgn(y[n+i]);
415 z3[n+i] = stk::math::copysign(x[n+i],y[n+i]);
416 }
417 const stk::simd::Double xl = stk::simd::load(&x[n]);
418 const stk::simd::Double yl = stk::simd::load(&y[n]);
419 stk::simd::Double zl = stk::math::copysign(xl,yl);
420 stk::simd::store(&z1[n],zl);
421 }
422
423 ASSERT_NEAR( max_error(z1, z2, z3), 0.0, 0.0 );
424
425 // max
426
427 for (int n=0; n < N; n+=stk::simd::ndoubles) {
428 for (int i=0; i < stk::simd::ndoubles; ++i) {
429 z2[n+i] = stk::math::max(x[n+i],y[n+i]);
430 z3[n+i] = stk::math::max(x[n+i],y[n+i]);
431 }
432 const stk::simd::Double xl = stk::simd::load(&x[n]);
433 const stk::simd::Double yl = stk::simd::load(&y[n]);
434 stk::simd::Double zl = stk::math::max(xl,yl);
435 stk::simd::store(&z1[n],zl);
436 }
437
438 ASSERT_NEAR( max_error(z1, z2, z3), 0.0, 0.0 );
439
440 // min
441
442 for (int n=0; n < N; n+=stk::simd::ndoubles) {
443 for (int i=0; i < stk::simd::ndoubles; ++i) {
444 z2[n+i] = stk::math::min(x[n+i],y[n+i]);
445 z3[n+i] = stk::math::min(x[n+i],y[n+i]);
446 }
447 const stk::simd::Double xl = stk::simd::load(&x[n]);
448 const stk::simd::Double yl = stk::simd::load(&y[n]);
449 stk::simd::Double zl = stk::math::min(xl,yl);
450 stk::simd::store(&z1[n],zl);
451 }
452
453 ASSERT_NEAR( max_error(z1,z2,z3), 0.0, 0.0 );
454
455 // ifs and buts
456
457 for (int n=0; n < N; n+=stk::simd::ndoubles) {
458 for (int i=0; i < stk::simd::ndoubles; ++i) {
459 bool xlty = x[n+i] < y[n+i];
460 z2[n+i] = stk::math::if_then_else(xlty, x[n+i], y[n+i]);
461 z3[n+i] = xlty ? x[n+i] : y[n+i];
462 }
463 const stk::simd::Double xl = stk::simd::load(&x[n]);
464 const stk::simd::Double yl = stk::simd::load(&y[n]);
465 stk::simd::Double zl = stk::math::if_then_else(xl < yl, xl, yl);
466 stk::simd::store(&z1[n],zl);
467 }
468
469 ASSERT_NEAR( max_error(z1,z2,z3), 0.0, 0.0);
470
471 for (int n=0; n < N; n+=stk::simd::ndoubles) {
472 for (int i=0; i < stk::simd::ndoubles; ++i) {
473 bool xlty = x[n+i] < y[n+i];
474 z2[n+i] = stk::math::if_then_else_zero(xlty, x[n+i]);
475 z3[n+i] = xlty ? x[n+i] : 0.0;
476 }
477 const stk::simd::Double xl = stk::simd::load(&x[n]);
478 const stk::simd::Double yl = stk::simd::load(&y[n]);
479 stk::simd::Double zl = stk::math::if_then_else_zero(xl < yl, xl);
480 stk::simd::store(&z1[n],zl);
481 }
482
483 ASSERT_NEAR( max_error(z1,z2,z3), 0.0, 0.0 );
484 }
485
486 TEST(StkSimd, SimdAddSubtractMultDivide)
487 {
488 int N = 400000;
489 double t0; // timing variable
490
491 std::vector<double> x(N);
492 std::vector<double> y(N);
493
494 std::vector<double> out1(N);
495 std::vector<double> out2(N);
496
497 for (int n=0; n < N; ++n) {
498 x[n] = 21*(rand()-0.5)/RAND_MAX;
499 y[n] = 26*(rand()-0.4)/RAND_MAX;
500 }
501
502 t0 = -stk::get_time_in_seconds();
503 for(int i=0; i<10; ++i) {
504 for (int n=0; n < N; n+=stk::simd::ndoubles) {
505 const stk::simd::Double a = stk::simd::load(&x[n]);
506 const stk::simd::Double b = stk::simd::load(&y[n]);
507 const stk::simd::Double c = ( a+b*(a-b) )/a;
508 stk::simd::store(&out1[n],c);
509 }
510 }
511 t0 += stk::get_time_in_seconds();
512 std::cout << "SIMD ADD,SUB,MUL,DIV took " << t0 << " seconds" << std::endl;
513
514 t0 = -stk::get_time_in_seconds();
515 for(int i=0; i<10; ++i) {
516 for (int n=0; n < N; ++n) {
517 const double a = x[n];
518 const double b = y[n];
519 out2[n] = ( a+b*(a-b) )/a;
520 }
521 }
522 t0 += stk::get_time_in_seconds();
523 std::cout << "Real ADD,SUB,MUL,DIV took " << t0 << " seconds" << std::endl;
524
525 ASSERT_NEAR( max_error(out1, out2), 0.0, 1e-8 );
526 }
527
528 TEST(StkSimd, SimdMiscSelfAddSubEtc)
529 {
530 int N = 10000;
531
532 std::vector<double> x(N);
533 std::vector<double> y(N);
534
535 std::vector<double> out1(N);
536 std::vector<double> out2(N);
537
538 for (int n=0; n < N; ++n) {
539 x[n] = 21*(rand()-0.5)/RAND_MAX;
540 y[n] = 26*(rand()-0.4)/RAND_MAX;
541 }
542
543 // *= -a and traits
544
545 for (int n=0; n < N; n+=stk::simd::ndoubles) {
546 const stk::simd::Double a = stk::simd::load(&x[n]);
547 const stk::simd::Double b = stk::simd::load(&y[n]);
548 stk::simd::Double c = 3.0;
549 c *= -b*a+stk::Traits<stk::simd::Double>::TWO/5;
550 stk::simd::store(&out1[n],c);
551 }
552
553 for (int n=0; n < N; ++n) {
554 const double a = x[n];
555 const double b = y[n];
556 out2[n] = 3.0;
557 out2[n] *= -b*a+stk::Traits<double>::TWO/5;
558 }
559
560 ASSERT_NEAR( max_error(out1, out2), 0.0, 1e-9 );
561
562 for (int n=0; n < N; n+=stk::simd::ndoubles) {
563 const stk::simd::Double a = stk::simd::load(&x[n]);
564 const stk::simd::Double b = stk::simd::load(&y[n]);
565 stk::simd::Double c = 3.2;
566 c /= -(b*a+5.6*c);
567 stk::simd::store(&out1[n],c);
568 }
569
570 for (int n=0; n < N; ++n) {
571 const double a = x[n];
572 const double b = y[n];
573 out2[n] = 3.2;
574 out2[n] /= -(b*a+5.6*out2[n]);
575 }
576
577 ASSERT_NEAR( max_error(out1, out2), 0.0, 1e-9 );
578
579 for (int n=0; n < N; n+=stk::simd::ndoubles) {
580 const stk::simd::Double a = stk::simd::load(&x[n]);
581 const stk::simd::Double b = stk::simd::load(&y[n]);
582 stk::simd::Double c = stk::Traits<stk::simd::Double>::THIRD;
583 c += -(b/(1.0-a)+((c*3)+5.2));
584 stk::simd::store(&out1[n],c);
585 }
586
587 for (int n=0; n < N; ++n) {
588 const double a = x[n];
589 const double b = y[n];
590 double c = stk::Traits<double>::THIRD;
591 c += -(b/(1.0-a)+((c*3)+5.2));
592 out2[n] = c;
593 }
594
595 ASSERT_EQ( max_error(out1, out2), 0.0);
596
597 for (int n=0; n < N; n+=stk::simd::ndoubles) {
598 const stk::simd::Double a = stk::simd::load(&x[n]);
599 const stk::simd::Double b = stk::simd::load(&y[n]);
600 stk::simd::Double c = -stk::simd::Double(0.5);
601 c -= 5.2+(b/(a-5.4)+3.5/c);
602 stk::simd::store(&out1[n],c);
603 }
604
605 for (int n=0; n < N; ++n) {
606 const double a = x[n];
607 const double b = y[n];
608 out2[n] = -0.5;
609 out2[n] -= 5.2+(b/(a-5.4)+3.5/out2[n]);
610 }
611
612 ASSERT_EQ( max_error(out1, out2), 0.0 );
613
614 for (int n=0; n < N; n+=stk::simd::ndoubles) {
615 const stk::simd::Double a = stk::simd::load(&x[n]);
616 const stk::simd::Double b = stk::simd::load(&y[n]);
617 const stk::simd::Double c = -0.3;
618 const stk::simd::Double d = -c + 1.4*a/b;
619 stk::simd::store(&out1[n],d);
620 }
621
622 for (int n=0; n < N; ++n) {
623 const double a = x[n];
624 const double b = y[n];
625 const double c = -0.3;
626 out2[n] = -c + 1.4*a/b;
627 }
628
629 ASSERT_EQ( max_error(out1, out2), 0.0 );
630 }
631
632 TEST(StkSimd, Simd_fmadd)
633 {
634 int N = 400000;
635 double t0; // timing variable
636
637 std::vector<double> x(N);
638 std::vector<double> y(N);
639 std::vector<double> z(N);
640
641 std::vector<double> out1(N);
642 std::vector<double> out2(N);
643
644 for (int n=0; n < N; ++n) {
645 x[n] = 2.1*(rand()-0.5)/RAND_MAX;
646 y[n] = 6.0*(rand()-0.4)/RAND_MAX;
647 z[n] = 6.0*(rand()-0.4)/RAND_MAX;
648 }
649
650 t0 = -stk::get_time_in_seconds();
651 for (int n=0; n < N; n+=stk::simd::ndoubles) {
652 const stk::simd::Double a = stk::simd::load(&x[n]);
653 const stk::simd::Double b = stk::simd::load(&y[n]);
654 const stk::simd::Double c = stk::simd::load(&z[n]);
655 stk::simd::Double d = stk::math::fmadd(a,b,c);
656 stk::simd::store(&out1[n],d);
657 }
658 t0 += stk::get_time_in_seconds();
659 std::cout << "SIMD ADD,SUB,MUL,DIV took " << t0 << " seconds" << std::endl;
660
661 t0 = -stk::get_time_in_seconds();
662 #if defined(__INTEL_COMPILER) || defined(__INTEL_LLVM_COMPILER)
663 #pragma novector
664 #endif
665 for (int n=0; n < N; ++n) {
666 const double a = x[n];
667 const double b = y[n];
668 const double c = z[n];
669 out2[n] = a*b+c;
670 }
671 t0 += stk::get_time_in_seconds();
672 std::cout << "Real ADD,SUB,MUL,DIV took " << t0 << " seconds" << std::endl;
673
674 ASSERT_NEAR( max_error(out1, out2), 0.0, 1e-14 );
675 }
676
677 TEST(StkSimd, SimdSqrt)
678 {
679 int N = 400000;
680 double t0; // timing variable
681
682 std::vector<double> x(N);
683
684 std::vector<double> out1(N);
685 std::vector<double> out2(N);
686
687 for (int n=0; n < N; ++n) {
688 x[n] = 21.0*(rand()+1)/RAND_MAX;
689 }
690
691 t0 = -stk::get_time_in_seconds();
692 for (int n=0; n < N; n+=stk::simd::ndoubles) {
693 const stk::simd::Double a = stk::simd::load(&x[n]);
694 const stk::simd::Double b = stk::math::sqrt(a);
695 stk::simd::store(&out1[n],b);
696 }
697 t0 += stk::get_time_in_seconds();
698 std::cout << "SIMD SQRT took " << t0 << " seconds" << std::endl;
699
700 t0 = -stk::get_time_in_seconds();
701 #if defined(__INTEL_COMPILER) || defined(__INTEL_LLVM_COMPILER)
702 #pragma novector
703 #endif
704 for (int n=0; n < N; ++n) {
705 const double a = x[n];
706 out2[n] = std::sqrt(a);
707 }
708 t0 += stk::get_time_in_seconds();
709 std::cout << "Real SQRT took " << t0 << " seconds" << std::endl;
710
711 ASSERT_NEAR( max_error(out1, out2), 0.0, 0.0 );
712 }
713
714 TEST(StkSimd, SimdLog)
715 {
716 int N = 400000;
717 double t0; // timing variable
718
719 std::vector<double> x(N);
720
721 std::vector<double> out1(N);
722 std::vector<double> out2(N);
723
724 for (int n=0; n < N; ++n) {
725 x[n] = 21.0*(rand()+1.0)/RAND_MAX+1.0;
726 }
727
728 t0 = -stk::get_time_in_seconds();
729 for (int n=0; n < N; n+=stk::simd::ndoubles) {
730 const stk::simd::Double a = stk::simd::load(&x[n]);
731 const stk::simd::Double b = stk::math::log(a);
732 stk::simd::store(&out1[n],b);
733 }
734 t0 += stk::get_time_in_seconds();
735 std::cout << "SIMD Log took " << t0 << " seconds" << std::endl;
736
737 t0 = -stk::get_time_in_seconds();
738 for (int n=0; n < N; ++n) {
739 const double a = x[n];
740 out2[n] = std::log(a);
741 }
742 t0 += stk::get_time_in_seconds();
743 std::cout << "Real Log took " << t0 << " seconds" << std::endl;
744
745 const double epsilon = 1.e-14;
746 ASSERT_NEAR( max_error(out1, out2), 0.0, epsilon );
747 }
748
749 TEST(StkSimd, SimdExp)
750 {
751 int N = 400000;
752
753 std::vector<double> x(N);
754
755 std::vector<double> out1(N);
756 std::vector<double> out2(N);
757
758 for (int n=0; n < N; ++n) {
759 x[n] = 5.4*(rand()/RAND_MAX-0.5);
760 }
761
762 double t0 = -stk::get_time_in_seconds();
763 for (int n=0; n < N; n+=stk::simd::ndoubles) {
764 const stk::simd::Double a = stk::simd::load(&x[n]);
765 const stk::simd::Double b = stk::math::exp(a);
766 stk::simd::store(&out1[n],b);
767 }
768 t0 += stk::get_time_in_seconds();
769 std::cout << "SIMD Exp took " << t0 << " seconds" << std::endl;
770
771 t0 = -stk::get_time_in_seconds();
772 for (int n=0; n < N; ++n) {
773 const double a = x[n];
774 out2[n] = std::exp(a);
775 }
776 t0 += stk::get_time_in_seconds();
777 std::cout << "Real Exp took " << t0 << " seconds" << std::endl;
778
779 const double epsilon = 1.e-14;
780 ASSERT_NEAR( max_error(out1, out2), 0.0, epsilon );
781 }
782
783 TEST(StkSimd, SimdPowA)
784 {
785 const int N = 2000;
786
787 std::vector<double> x(N);
788 std::vector<double> y(N/stk::simd::ndoubles);
789
790 std::vector<double> out1(N);
791 std::vector<double> out2(N);
792
793 for (int n=0; n < N; ++n) {
794 x[n] = 5.4*(rand()/RAND_MAX-0.5)+0.002;
795 }
796 for (int n=0; n < N/stk::simd::ndoubles; ++n) {
797 y[n] = 3.2*(rand()/RAND_MAX-0.5)+0.2;
798 }
799
800 double t0 = -stk::get_time_in_seconds();
801 for (int n=0; n < N; n+=stk::simd::ndoubles) {
802 const stk::simd::Double a = stk::simd::load(&x[n]);
803 const double b = y[n/stk::simd::ndoubles];
804 const stk::simd::Double c = stk::math::pow(a,b);
805 stk::simd::store(&out1[n],c);
806 }
807 t0 += stk::get_time_in_seconds();
808 std::cout << "SIMD Pow took " << t0 << " seconds" << std::endl;
809
810 t0 = -stk::get_time_in_seconds();
811 for (int n=0; n < N/stk::simd::ndoubles; ++n) {
812 double exp = y[n];
813 for (int i=0; i < stk::simd::ndoubles; ++i) {
814 const double a = x[stk::simd::ndoubles*n+i];
815 out2[stk::simd::ndoubles*n+i] = stk::math::pow(a,exp);
816 }
817 }
818 t0 += stk::get_time_in_seconds();
819 std::cout << "Real Exp took " << t0 << " seconds" << std::endl;
820
821 const double epsilon = 1.e-14;
822 ASSERT_NEAR( max_error(out1, out2), 0.0, epsilon );
823 }
824
825 TEST(StkSimd, SimdPowB)
826 {
827 int N = 400000;
828
829 std::vector<double> x(N);
830 std::vector<double> y(N);
831
832 std::vector<double> out1(N);
833 std::vector<double> out2(N);
834
835 for (int n=0; n < N; ++n) {
836 x[n] = 5.4*(rand()/RAND_MAX-0.5)+0.001;
837 }
838 for (int n=0; n < N; ++n) {
839 y[n] = 3.2*(rand()/RAND_MAX-0.5)+0.1;
840 }
841
842 double t0 = -stk::get_time_in_seconds();
843 for (int n=0; n < N; n+=stk::simd::ndoubles) {
844 const stk::simd::Double a = stk::simd::load(&x[n]);
845 const stk::simd::Double b = stk::simd::load(&y[n]);
846 const stk::simd::Double c = stk::math::pow(a,b);
847 stk::simd::store(&out1[n],c);
848 }
849 t0 += stk::get_time_in_seconds();
850 std::cout << "SIMD Pow took " << t0 << " seconds" << std::endl;
851
852 t0 = -stk::get_time_in_seconds();
853 for (int n=0; n < N; ++n) {
854 const double a = x[n];
855 const double b = y[n];
856 out2[n] = std::pow(a,b);
857 }
858 t0 += stk::get_time_in_seconds();
859 std::cout << "Real Pow took " << t0 << " seconds" << std::endl;
860
861 ASSERT_NEAR( max_error(out1, out2), 0.0, 0.0);
862 }
863
864 TEST(StkSimd, SimdPowC)
865 {
866 int N = 100000;
867 double t0; // timing variable
868
869 std::vector<double> x(N);
870 std::vector<double> out1(N);
871 std::vector<double> out2(N);
872
873 for (int n=0; n < N; ++n) {
874 x[n] = 1.34*(rand()/RAND_MAX-0.5);
875 }
876
877 t0 = -stk::get_time_in_seconds();
878 for (int n=0; n < N; n+=stk::simd::ndoubles) {
879 const stk::simd::Double a = stk::simd::load(&x[n]);
880 const stk::simd::Double c = stk::math::pow(a,3);
881 stk::simd::store(&out1[n],c);
882 }
883 t0 += stk::get_time_in_seconds();
884 std::cout << "SIMD Exp took " << t0 << " seconds" << std::endl;
885
886 t0 = -stk::get_time_in_seconds();
887 for (int n=0; n < N; ++n) {
888 const double a = x[n];
889 out2[n] = std::pow(a,3);
890 }
891 t0 += stk::get_time_in_seconds();
892 std::cout << "Real Exp took " << t0 << " seconds" << std::endl;
893
894 ASSERT_NEAR( max_error(out1, out2), 0.0, 0.0);
895 }
896
897 TEST(StkSimd, SimdCbrt)
898 {
899 int N = 800000;
900 double t0; // timing variable
901
902 std::vector<double> x(N);
903
904 std::vector<double> out1(N);
905 std::vector<double> out2(N);
906
907 for (int n=0; n < N; ++n) {
908 x[n] = 21*(rand()-0.5)/RAND_MAX;
909 }
910
911 t0 = -stk::get_time_in_seconds();
912 for (int n=0; n < N; n+=stk::simd::ndoubles) {
913 const stk::simd::Double xl = stk::simd::load(&x[n]);
914 const stk::simd::Double d = stk::math::cbrt(xl);
915 stk::simd::store(&out1[n],d);
916 }
917 t0 += stk::get_time_in_seconds();
918 std::cout << "SIMD cbrt took " << t0 << " seconds" << std::endl;
919
920 t0 = -stk::get_time_in_seconds();
921 for (int n=0; n < N; ++n) {
922 out2[n] = stk::math::cbrt(x[n]);
923 }
924 t0 += stk::get_time_in_seconds();
925 std::cout << "Real cbrt took " << t0 << " seconds" << std::endl;
926
927 ASSERT_NEAR( max_error(out1, out2), 0.0, 2e-15);
928 }
929
930 TEST(StkSimd, SimdTimeLoadStoreDataLayout)
931 {
932 double t0;
933
934 const int N = 20000;
935 const int sz = 32;
936
937 std::vector<double,non_std::AlignedAllocator<double,64> > x(sz*N);
938 std::vector<double,non_std::AlignedAllocator<double,64> > y(sz*N);
939 std::vector<double,non_std::AlignedAllocator<double,64> > z(sz*N);
940 std::vector<double,non_std::AlignedAllocator<double,64> > w(sz*N);
941
942 for (int n=0; n < N; ++n) {
943 for (int i=0; i < sz; ++i) {
944 x[sz*n+i] = 1+std::sqrt(n+n*(i+1));
945 }
946 }
947
948 double* X = x.data();
949 double* Y = y.data();
950
951 stk::simd::Double a[sz];
952
953 t0 = -stk::get_time_in_seconds();
954 for (int n=0; n < N; n+=stk::simd::ndoubles, X+=sz*stk::simd::ndoubles, Y+=sz*stk::simd::ndoubles) {
955 // load the slow way
956 for (int i=0; i < sz; ++i) a[i] = stk::simd::load( X+i, sz );
957 // store the slow way
958 for (int i=0; i < sz; ++i) stk::simd::store( Y+i, a[i]+stk::simd::Double(1.0), sz );
959 }
960
961 t0 += stk::get_time_in_seconds();
962 std::cout << "Method 1: Offset load/store, took " << t0 << " seconds" << std::endl;
963
964 // reorder the arrays...
965 const int ssz = sz*stk::simd::ndoubles;
966 double tmp[ssz];
967
968 for (int n=0; n < N; n+=stk::simd::ndoubles) {
969 for (int i=0; i < sz; ++i) {
970 for (int j=0; j < stk::simd::ndoubles; ++j) {
971 tmp[sz*j+i] = x[sz*n+sz*j+i];
972 }
973 }
974 for (int i=0; i < sz; ++i) {
975 for (int j=0; j < stk::simd::ndoubles; ++j) {
976 x[sz*n+stk::simd::ndoubles*i+j] = tmp[sz*j+i];
977 }
978 }
979 }
980
981 X = x.data();
982 Y = z.data();
983
984 t0 = -stk::get_time_in_seconds();
985 for (int n=0; n < N; n+=stk::simd::ndoubles, X+=sz*stk::simd::ndoubles, Y+=sz*stk::simd::ndoubles) {
986
987 for (int i=0; i < sz; ++i) {
988 a[i] = stk::simd::load( X+stk::simd::ndoubles*i );
989 }
990
991 for (int i=0; i < sz; ++i) {
992 stk::simd::store( Y+stk::simd::ndoubles*i, a[i]+stk::simd::Double(1.0) );
993 }
994
995 }
996 t0 += stk::get_time_in_seconds();
997 std::cout << "Method 2: Reordered load, took " << t0 << " seconds" << std::endl;
998
999 X = x.data();
1000 Y = w.data();
1001
1002 stk::simd::Double* XX = stk::simd::simd_ptr_cast<double>(X);
1003 stk::simd::Double* YY = stk::simd::simd_ptr_cast<double>(Y);
1004
1005 t0 = -stk::get_time_in_seconds();
1006
1007 for (int n=0,i=0; n < N; n+=stk::simd::ndoubles) {
1008 for (int j=0; j < sz; ++j,++i) {
1009 YY[i] = XX[i]+stk::simd::Double(1.0);
1010 }
1011
1012 }
1013 t0 += stk::get_time_in_seconds();
1014 std::cout << "Method 3: Load/Store in place, took " << t0 << " seconds" << std::endl;
1015
1016 //reorder back! (y and w)
1017 for (int n=0; n < N; n+=stk::simd::ndoubles) {
1018 for (int i=0; i < sz; ++i) {
1019 for (int j=0; j < stk::simd::ndoubles; ++j) {
1020 tmp[sz*j+i] = z[sz*n+stk::simd::ndoubles*i+j];
1021 }
1022 }
1023 for (int i=0; i < sz; ++i) {
1024 for (int j=0; j < stk::simd::ndoubles; ++j) {
1025 z[sz*n+sz*j+i] = tmp[sz*j+i];
1026 }
1027 }
1028 }
1029
1030 for (int n=0; n < N; n+=stk::simd::ndoubles) {
1031 for (int i=0; i < sz; ++i) {
1032 for (int j=0; j < stk::simd::ndoubles; ++j) {
1033 tmp[sz*j+i] = w[sz*n+stk::simd::ndoubles*i+j];
1034 }
1035 }
1036 for (int i=0; i < sz; ++i) {
1037 for (int j=0; j < stk::simd::ndoubles; ++j) {
1038 w[sz*n+sz*j+i] = tmp[sz*j+i];
1039 }
1040 }
1041 }
1042
1043 // figure out error
1044 ASSERT_NEAR( max_error(y, z), 0.0, 1.0e-16 );
1045 ASSERT_NEAR( max_error(y, w), 0.0, 1.0e-16 );
1046 }
1047
1048 TEST(StkSimd, SimdTimeLoadStoreInnerProduct)
1049 {
1050 double t0;
1051
1052 const int N = 20000;
1053 const int sz = 32;
1054
1055 std::vector<double,non_std::AlignedAllocator<double,64> > x(sz*N);
1056 std::vector<double,non_std::AlignedAllocator<double,64> > y(N);
1057 std::vector<double,non_std::AlignedAllocator<double,64> > z(N);
1058 std::vector<double,non_std::AlignedAllocator<double,64> > w(N);
1059
1060 for (int n=0; n < N; ++n) {
1061 for (int i=0; i < sz; ++i) {
1062 x[sz*n+i] = 1+std::sqrt(n+n*(i+1));
1063 }
1064 }
1065
1066 double* X = x.data();
1067 double* Y = y.data();
1068
1069 t0 = -stk::get_time_in_seconds();
1070 for (int n=0; n < N; n+=stk::simd::ndoubles, X+=sz*stk::simd::ndoubles, Y+=stk::simd::ndoubles) {
1071 // load the slow way
1072 stk::simd::Double dot = 0.0;
1073 for (int i=0; i < sz; ++i) {
1074 stk::simd::Double tmp = stk::simd::load( X+i, sz );
1075 dot += tmp*tmp;
1076 }
1077 stk::simd::store( Y, dot );
1078 }
1079
1080 t0 += stk::get_time_in_seconds();
1081 std::cout << "Method 1: Offset load/store, took " << t0 << " seconds" << std::endl;
1082
1083 // reorder the arrays...
1084 const int ssz = sz*stk::simd::ndoubles;
1085 double tmp[ssz];
1086
1087 for (int n=0; n < N; n+=stk::simd::ndoubles) {
1088 for (int i=0; i < sz; ++i) {
1089 for (int j=0; j < stk::simd::ndoubles; ++j) {
1090 tmp[sz*j+i] = x[sz*n+sz*j+i];
1091 }
1092 }
1093 for (int i=0; i < sz; ++i) {
1094 for (int j=0; j < stk::simd::ndoubles; ++j) {
1095 x[sz*n+stk::simd::ndoubles*i+j] = tmp[sz*j+i];
1096 }
1097 }
1098 }
1099
1100 X = x.data();
1101 Y = z.data();
1102
1103 t0 = -stk::get_time_in_seconds();
1104 for (int n=0; n < N; n+=stk::simd::ndoubles, X+=sz*stk::simd::ndoubles, Y+=stk::simd::ndoubles) {
1105 stk::simd::Double dot = 0.0;
1106 for (int i=0; i < sz; ++i) {
1107 const stk::simd::Double tmpDoubles = stk::simd::load( X+stk::simd::ndoubles*i );
1108 dot += tmpDoubles*tmpDoubles;
1109 }
1110
1111 stk::simd::store( Y, dot );
1112
1113 }
1114 t0 += stk::get_time_in_seconds();
1115 std::cout << "Method 2: Reordered load, took " << t0 << " seconds" << std::endl;
1116
1117 X = x.data();
1118 Y = w.data();
1119
1120 const stk::simd::Double* XX = stk::simd::simd_ptr_cast<double>(X);
1121 stk::simd::Double* YY = stk::simd::simd_ptr_cast<double>(Y);
1122
1123 t0 = -stk::get_time_in_seconds();
1124
1125 for (int n=0; n < N; n+=stk::simd::ndoubles) {
1126 stk::simd::Double dot = 0.0;
1127 for (int i=0; i < sz; ++i) {
1128 const stk::simd::Double tmpDoubles = XX[i];
1129 dot += tmpDoubles*tmpDoubles;
1130 }
1131 XX+=sz;
1132 *(YY++) = dot;
1133 }
1134 t0 += stk::get_time_in_seconds();
1135 std::cout << "Method 3: Load/Store in place, took " << t0 << " seconds" << std::endl;
1136
1137 //reorder back! (y and w)
1138 for (int n=0; n < N; n+=stk::simd::ndoubles) {
1139 for (int i=0; i < 1; ++i) {
1140 for (int j=0; j < stk::simd::ndoubles; ++j) {
1141 tmp[1*j+i] = z[1*n+stk::simd::ndoubles*i+j];
1142 }
1143 }
1144 for (int i=0; i < 1; ++i) {
1145 for (int j=0; j < stk::simd::ndoubles; ++j) {
1146 z[1*n+1*j+i] = tmp[1*j+i];
1147 }
1148 }
1149 }
1150
1151 for (int n=0; n < N; n+=stk::simd::ndoubles) {
1152 for (int i=0; i < 1; ++i) {
1153 for (int j=0; j < stk::simd::ndoubles; ++j) {
1154 tmp[1*j+i] = w[1*n+stk::simd::ndoubles*i+j];
1155 }
1156 }
1157 for (int i=0; i < 1; ++i) {
1158 for (int j=0; j < stk::simd::ndoubles; ++j) {
1159 w[1*n+1*j+i] = tmp[1*j+i];
1160 }
1161 }
1162 }
1163
1164 // figure out error
1165 ASSERT_NEAR( max_error(y,z), 0.0, 1.0e-16 );
1166 ASSERT_NEAR( max_error(y,w), 0.0, 1.0e-16 );
1167 }
1168
1169
1170 TEST(StkSimd, SimdIfThenBool)
1171 {
1172 typedef stk::Traits<double>::bool_type double_bool;
1173 typedef stk::Traits<stk::simd::Double>::bool_type Doubles_bool;
1174
1175 ASSERT_TRUE( stk::simd::are_all( stk::Traits<stk::simd::Double>::TRUE_VAL ) );
1176 ASSERT_TRUE( stk::Traits<double>::TRUE_VAL );
1177
1178 ASSERT_FALSE( stk::simd::are_all( stk::Traits<stk::simd::Double>::FALSE_VAL ) );
1179 ASSERT_FALSE( stk::Traits<double>::FALSE_VAL );
1180
1181 const int N = 2000;
1182 const double a = 5.1;
1183 const double b = -3.2;
1184
1185 std::vector<double> x(N);
1186 std::vector<double> y(N);
1187 std::vector<double> x2(N);
1188 std::vector<double> y2(N);
1189 std::vector<double> z1(N);
1190 std::vector<double> z2(N);
1191 std::vector<double> z3(N);
1192
1193 for (int n=0; n < N; ++n) {
1194 x[n] = (rand()-0.5)/RAND_MAX;
1195 y[n] = rand()/RAND_MAX;
1196 x2[n] = (rand()-0.1)/RAND_MAX;
1197 y2[n] = (rand()+0.5)/RAND_MAX;
1198 }
1199
1200 y[10] = x[10] = 5;
1201 y[33] = x[33] = 6.4;
1202 y[101]= x[101]= -3;
1203
1204 // less than
1205
1206 for (int n=0; n < N; n+=stk::simd::ndoubles) {
1207 for (int i=0; i < stk::simd::ndoubles; ++i) {
1208 z2[n+i] = x[n+i] < y[n+i] ? a : b;
1209 double_bool tmp = x[n+i] < y[n+i];
1210 z3[n+i] = stk::math::if_then_else(tmp,a,b);
1211 }
1212 const stk::simd::Double xl = stk::simd::load(&x[n]);
1213 const stk::simd::Double yl = stk::simd::load(&y[n]);
1214
1215 stk::simd::Double zl = stk::math::if_then_else(xl < yl, stk::simd::Double(a), stk::simd::Double(b));
1216 stk::simd::store(&z1[n],zl);
1217 }
1218
1219 ASSERT_NEAR( max_error(z1, z2, z3), 0.0, 0.0 );
1220
1221 // less than equal
1222
1223 for (int n=0; n < N; n+=stk::simd::ndoubles) {
1224 for (int i=0; i < stk::simd::ndoubles; ++i) {
1225 z2[n+i] = x[n+i] <= y[n+i] ? a : b;
1226 double_bool tmp = x[n+i] <= y[n+i];
1227 z3[n+i] = stk::math::if_then_else(tmp,a,b);
1228 }
1229 const stk::simd::Double xl = stk::simd::load(&x[n]);
1230 const stk::simd::Double yl = stk::simd::load(&y[n]);
1231
1232 stk::simd::Double zl = stk::math::if_then_else(xl <= yl, stk::simd::Double(a), stk::simd::Double(b));
1233 stk::simd::store(&z1[n],zl);
1234 }
1235
1236 ASSERT_NEAR( max_error(z1, z2, z3), 0.0, 0.0 );
1237
1238 // equal
1239
1240 for (int n=0; n < N; n+=stk::simd::ndoubles) {
1241 for (int i=0; i < stk::simd::ndoubles; ++i) {
1242 z2[n+i] = x[n+i] == y[n+i] ? a : b;
1243 double_bool tmp = x[n+i] == y[n+i];
1244 z3[n+i] = stk::math::if_then_else(tmp,a,b);
1245 }
1246 const stk::simd::Double xl = stk::simd::load(&x[n]);
1247 const stk::simd::Double yl = stk::simd::load(&y[n]);
1248
1249 stk::simd::Double zl = stk::math::if_then_else(xl == yl, stk::simd::Double(a), stk::simd::Double(b));
1250 stk::simd::store(&z1[n],zl);
1251 }
1252
1253 ASSERT_NEAR( max_error(z1, z2, z3), 0.0, 0.0 );
1254
1255 // greater than equal
1256
1257 for (int n=0; n < N; n+=stk::simd::ndoubles) {
1258 for (int i=0; i < stk::simd::ndoubles; ++i) {
1259 z2[n+i] = x[n+i] >= y[n+i] ? a : b;
1260 double_bool tmp = x[n+i] >= y[n+i];
1261 z3[n+i] = stk::math::if_then_else(tmp,a,b);
1262 }
1263 const stk::simd::Double xl = stk::simd::load(&x[n]);
1264 const stk::simd::Double yl = stk::simd::load(&y[n]);
1265
1266 stk::simd::Double zl = stk::math::if_then_else(xl >= yl, stk::simd::Double(a), stk::simd::Double(b));
1267 stk::simd::store(&z1[n],zl);
1268 }
1269
1270 ASSERT_NEAR( max_error(z1, z2, z3), 0.0, 0.0 );
1271
1272 // greater than
1273
1274 for (int n=0; n < N; n+=stk::simd::ndoubles) {
1275 for (int i=0; i < stk::simd::ndoubles; ++i) {
1276 z2[n+i] = x[n+i] > y[n+i] ? a : b;
1277 double_bool tmp = x[n+i] > y[n+i];
1278 z3[n+i] = stk::math::if_then_else(tmp,a,b);
1279 }
1280 const stk::simd::Double xl = stk::simd::load(&x[n]);
1281 const stk::simd::Double yl = stk::simd::load(&y[n]);
1282
1283 stk::simd::Double zl = stk::math::if_then_else(xl > yl, stk::simd::Double(a), stk::simd::Double(b));
1284 stk::simd::store(&z1[n],zl);
1285 }
1286
1287 ASSERT_NEAR( max_error(z1, z2, z3), 0.0, 0.0 );
1288
1289 // not equal
1290
1291 for (int n=0; n < N; n+=stk::simd::ndoubles) {
1292 for (int i=0; i < stk::simd::ndoubles; ++i) {
1293 z2[n+i] = x[n+i] != y[n+i] ? a : b;
1294 double_bool tmp = x[n+i] != y[n+i];
1295 z3[n+i] = stk::math::if_then_else(tmp,a,b);
1296 }
1297 const stk::simd::Double xl = stk::simd::load(&x[n]);
1298 const stk::simd::Double yl = stk::simd::load(&y[n]);
1299
1300 stk::simd::Double zl = stk::math::if_then_else(xl != yl, stk::simd::Double(a), stk::simd::Double(b));
1301 stk::simd::store(&z1[n],zl);
1302 }
1303
1304 ASSERT_NEAR( max_error(z1, z2, z3), 0.0, 0.0 );
1305
1306 // if then zero
1307
1308 for (int n=0; n < N; n+=stk::simd::ndoubles) {
1309 for (int i=0; i < stk::simd::ndoubles; ++i) {
1310 z2[n+i] = x[n+i] < y[n+i] ? a : 0;
1311 double_bool tmp = x[n+i] < y[n+i];
1312 z3[n+i] = stk::math::if_then_else_zero(tmp,a);
1313 }
1314 const stk::simd::Double xl = stk::simd::load(&x[n]);
1315 const stk::simd::Double yl = stk::simd::load(&y[n]);
1316
1317 stk::simd::Double zl = stk::math::if_then_else_zero(xl < yl, stk::simd::Double(a));
1318 stk::simd::store(&z1[n],zl);
1319 }
1320
1321 ASSERT_NEAR( max_error(z1, z2, z3), 0.0, 0.0 );
1322
1323 // if ! then
1324
1325 for (int n=0; n < N; n+=stk::simd::ndoubles) {
1326 for (int i=0; i < stk::simd::ndoubles; ++i) {
1327 z2[n+i] = !(x[n+i] < y[n+i]) ? a : b;
1328 double_bool tmp = x[n+i] < y[n+i];
1329 z3[n+i] = stk::math::if_then_else(!tmp,a,b);
1330 }
1331 const stk::simd::Double xl = stk::simd::load(&x[n]);
1332 const stk::simd::Double yl = stk::simd::load(&y[n]);
1333 Doubles_bool tmp = xl < yl;
1334 stk::simd::Double zl = stk::math::if_then_else(!tmp, stk::simd::Double(a),stk::simd::Double(b));
1335 stk::simd::store(&z1[n],zl);
1336 }
1337
1338 ASSERT_NEAR( max_error(z1, z2, z3), 0.0, 0.0 );
1339
1340 // &&
1341
1342 for (int n=0; n < N; n+=stk::simd::ndoubles) {
1343 for (int i=0; i < stk::simd::ndoubles; ++i) {
1344 double_bool tmp = x[n+i] < y[n+i];
1345 double_bool tmp2 = x2[n+i] > y2[n+i];
1346 z2[n+i] = (tmp&tmp2) ? a : b;
1347 z3[n+i] = stk::math::if_then_else(tmp&&tmp2,a,b);
1348 }
1349 const stk::simd::Double xl = stk::simd::load(&x[n]);
1350 const stk::simd::Double yl = stk::simd::load(&y[n]);
1351 const stk::simd::Double xl2 = stk::simd::load(&x2[n]);
1352 const stk::simd::Double yl2 = stk::simd::load(&y2[n]);
1353 Doubles_bool tmp = xl < yl;
1354 Doubles_bool tmp2 = xl2 > yl2;
1355 stk::simd::Double zl = stk::math::if_then_else(tmp&&tmp2, stk::simd::Double(a),stk::simd::Double(b));
1356 stk::simd::store(&z1[n],zl);
1357 }
1358
1359 ASSERT_NEAR( max_error(z1, z2, z3), 0.0, 0.0 );
1360
1361 // ||
1362
1363 for (int n=0; n < N; n+=stk::simd::ndoubles) {
1364 for (int i=0; i < stk::simd::ndoubles; ++i) {
1365 double_bool tmp = x[n+i] < y[n+i];
1366 double_bool tmp2 = x2[n+i] > y2[n+i];
1367 z2[n+i] = (tmp|tmp2) ? a : b;
1368 z3[n+i] = stk::math::if_then_else(tmp||tmp2,a,b);
1369 }
1370 const stk::simd::Double xl = stk::simd::load(&x[n]);
1371 const stk::simd::Double yl = stk::simd::load(&y[n]);
1372 const stk::simd::Double xl2 = stk::simd::load(&x2[n]);
1373 const stk::simd::Double yl2 = stk::simd::load(&y2[n]);
1374 Doubles_bool tmp = xl < yl;
1375 Doubles_bool tmp2 = xl2 > yl2;
1376 stk::simd::Double zl = stk::math::if_then_else(tmp||tmp2,
1377 stk::simd::Double(a),
1378 stk::simd::Double(b));
1379 stk::simd::store(&z1[n],zl);
1380 }
1381
1382 ASSERT_NEAR( max_error(z1, z2, z3), 0.0, 0.0 );
1383
1384 // are_any
1385
1386 for (int n=0; n < N; n+=stk::simd::ndoubles) {
1387 bool anyl=false;
1388 for (int i=0; i < stk::simd::ndoubles; ++i) {
1389 double_bool tmp = x[n+i] < y[n+i];
1390 anyl = tmp|anyl;
1391 }
1392 const stk::simd::Double xl = stk::simd::load(&x[n]);
1393 const stk::simd::Double yl = stk::simd::load(&y[n]);
1394 Doubles_bool tmp = xl < yl;
1395 bool anyl_simd = stk::simd::are_any(tmp,stk::simd::ndoubles);
1396
1397 ASSERT_TRUE(anyl_simd==anyl);
1398
1399 }
1400
1401 // are_all
1402
1403 for (int n=0; n < N; n+=stk::simd::ndoubles) {
1404 bool alll=true;
1405 for (int i=0; i < stk::simd::ndoubles; ++i) {
1406 double_bool tmp = x[n+i] < y[n+i];
1407 alll = tmp&alll;
1408 }
1409 const stk::simd::Double xl = stk::simd::load(&x[n]);
1410 const stk::simd::Double yl = stk::simd::load(&y[n]);
1411 Doubles_bool tmp = xl < yl;
1412 bool alll_simd = stk::simd::are_all(tmp,stk::simd::ndoubles);
1413
1414 ASSERT_TRUE(alll_simd==alll);
1415
1416 }
1417
1418 #if defined(STK_SIMD) // these don't make sense for non-simd
1419
1420 for (int n=0; n < N; n+=stk::simd::ndoubles) {
1421 bool anyl=false;
1422 for (int i=0; i < stk::simd::ndoubles-1; ++i) {
1423 double_bool tmp = x[n+i] < y[n+i];
1424 anyl = tmp|anyl;
1425 }
1426 const stk::simd::Double xl = stk::simd::load(&x[n]);
1427 const stk::simd::Double yl = stk::simd::load(&y[n]);
1428 Doubles_bool tmp = xl < yl;
1429 bool anyl_simd = stk::simd::are_any(tmp,stk::simd::ndoubles-1);
1430
1431 ASSERT_TRUE(anyl_simd==anyl);
1432
1433 }
1434
1435 // all (partial)
1436
1437 for (int n=0; n < N; n+=stk::simd::ndoubles) {
1438 bool alll=true;
1439 for (int i=0; i < stk::simd::ndoubles-1; ++i) {
1440 double_bool tmp = x[n+i] < y[n+i];
1441 alll = tmp&alll;
1442 }
1443 const stk::simd::Double xl = stk::simd::load(&x[n]);
1444 const stk::simd::Double yl = stk::simd::load(&y[n]);
1445 Doubles_bool tmp = xl < yl;
1446 bool alll_simd = stk::simd::are_all(tmp,stk::simd::ndoubles-1);
1447
1448 ASSERT_TRUE(alll_simd==alll);
1449
1450 }
1451
1452 #endif
1453 }
1454
1455
1456 TEST(StkSimd, SimdTimeSet1VsConstDoubles)
1457 {
1458 int N = 1000000;
1459 double t0; // timing variable
1460
1461 std::vector<double> x(N);
1462
1463 std::vector<double> out1(N);
1464 std::vector<double> out2(N);
1465 std::vector<double> out3(N);
1466 std::vector<double> out4(N);
1467
1468 const double three = 3.0;
1469 const double two = 2.0;
1470
1471 for (int n=0; n < N; ++n) {
1472 x[n] = 21*(rand()-0.5)/RAND_MAX;
1473 }
1474
1475 t0 = -stk::get_time_in_seconds();
1476 for (int n=0; n < N; n+=stk::simd::ndoubles) {
1477 const stk::simd::Double a = stk::simd::load(&x[n]);
1478 stk::simd::store(&out1[n],stk::simd::Double(2.0)+(a+stk::simd::Double(3.0)));
1479 }
1480 t0 += stk::get_time_in_seconds();
1481 std::cout << "Adding a const Doubles took " << t0 << " seconds" << std::endl;
1482
1483 t0 = -stk::get_time_in_seconds();
1484 for (int n=0; n < N; n+=stk::simd::ndoubles) {
1485 const stk::simd::Double a = stk::simd::load(&x[n]);
1486 stk::simd::store(&out2[n],stk::simd::Double(2.0)+(a+stk::simd::Double(3.0)));
1487 }
1488 t0 += stk::get_time_in_seconds();
1489 std::cout << "Adding a local const Doubles took " << t0 << " seconds" << std::endl;
1490
1491 t0 = -stk::get_time_in_seconds();
1492 for (int n=0; n < N; n+=stk::simd::ndoubles) {
1493 const stk::simd::Double a = stk::simd::load(&x[n]);
1494 stk::simd::store(&out3[n],2.0+(a+3.0));
1495 }
1496 t0 += stk::get_time_in_seconds();
1497 std::cout << "Adding a 3.0 (with load1_pd) took " << t0 << " seconds" << std::endl;
1498 t0 = -stk::get_time_in_seconds();
1499 for (int n=0; n < N; ++n) {
1500 out4[n] = two+(x[n] + three);
1501 }
1502 t0 += stk::get_time_in_seconds();
1503 std::cout << "Non simd took " << t0 << " seconds" << std::endl;
1504
1505 ASSERT_NEAR( max_error(out1, out2, out3, out4), 0.0, 0.0 );
1506 }
1507
1508 template <typename REAL_TYPE>
1509 void negate_vec(REAL_TYPE * const in, REAL_TYPE * const out) {
1510 REAL_TYPE tmp[12];
1511 tmp[9] = -in[0];
1512 tmp[10] = -in[1];
1513 tmp[11] = -in[2];
1514
1515 out[0] = tmp[9];
1516 out[1] = tmp[10];
1517 out[2] = tmp[11];
1518 }
1519
1520 template <typename REAL_TYPE> static void negate_vec2(REAL_TYPE* const in, REAL_TYPE* const out) {
1521 static const REAL_TYPE ZERO(0.0);
1522 out[0] = ZERO - in[0];
1523 out[1] = ZERO - in[1];
1524 out[2] = ZERO - in[2];
1525 }
1526
1527
1528 TEST(StkSimd, NegatingAVector)
1529 {
1530 int N = 8000;
1531
1532 std::vector<double> x(3*N);
1533
1534 std::vector<double> out1(3*N);
1535 std::vector<double> out2(3*N);
1536 std::vector<double> out3(3*N);
1537
1538 for (int n=0; n < 3*N; ++n) {
1539 x[n] = 21.0*(rand()-0.5)/RAND_MAX;
1540 }
1541
1542 for (int n=0; n < N; ++n) {
1543 negate_vec(&x[3*n],&out1[3*n]);
1544 }
1545
1546 stk::simd::Double a[3];
1547 stk::simd::Double b[3];
1548 for (int n=0; n < N; n+=stk::simd::ndoubles) {
1549 stk::simd::load_array<3>(a,&x[3*n]);
1550 negate_vec(a,b);
1551 stk::simd::store_array<3>(&out2[3*n],b);
1552 }
1553
1554 for (int n=0; n < N; n+=stk::simd::ndoubles) {
1555 stk::simd::load_array<3>(a,&x[3*n]);
1556 negate_vec2(a,b);
1557 stk::simd::store_array<3>(&out3[3*n],b);
1558 }
1559
1560 ASSERT_NEAR( max_error(out1, out2, out3), 0.0, 0.0 );
1561 }
1562
1563 TEST(StkSimd, simd_isnan)
1564 {
1565 const int N = stk::simd::ndoubles;
1566
1567 std::vector<double> x(N);
1568 for (int i=0; i < stk::simd::ndoubles; ++i) {
1569 x[i] = i;
1570 }
1571
1572 stk::simd::Double X = stk::simd::load(x.data());
1573 stk::simd::Double Y = stk::simd::Double(1.0)/X;
1574
1575 stk::simd::Bool IsNaN = stk::math::isnan(Y);
1576
1577 ASSERT_FALSE( stk::simd::are_any(IsNaN) );
1578 ASSERT_FALSE( stk::simd::are_all(IsNaN) );
1579
1580 Y*= stk::simd::Double(0.0);
1581
1582 IsNaN = stk::math::isnan(Y);
1583
1584 ASSERT_TRUE( stk::simd::are_any(IsNaN) );
1585 ASSERT_TRUE( !stk::simd::are_all(IsNaN) || (stk::simd::ndoubles==1) );
1586 }
1587
1588 std::vector<double> X_RandomValues(int N = 500000)
1589 {
1590 std::vector<double> x(N);
1591 for (int n=0; n < N; ++n) {
1592 x[n] = 21*(rand()-0.4)/RAND_MAX;
1593 }
1594 return x;
1595 }
1596
1597 std::vector<double> Y_RandomValues(std::vector<double>& x)
1598 {
1599 int N = x.size();
1600 std::vector<double> y(N);
1601 for (int n=0; n < N; ++n) {
1602 y[n] = 0.5*x[n];
1603 }
1604 return y;
1605 }
1606
1607 TEST(StkSimd, ReduceSum)
1608 {
1609 double t0; // timing variable
1610
1611 std::vector<double> x = X_RandomValues();
1612 std::vector<double> y = Y_RandomValues(x);
1613
1614 double sum_val = 0.0;
1615 double save_sum = 0.0;
1616
1617 const int N = x.size();
1618 const int Ns = N/stk::simd::ndoubles;
1619
1620 for (int i=0; i < 3; ++i) {
1621
1622 sum_val = 0.0;
1623
1624 t0 = -stk::get_time_in_seconds();
1625 for (int n=0; n < Ns; ++n) {
1626 const int ns = n*stk::simd::ndoubles;
1627 const stk::simd::Double xl = stk::simd::load(&x[ns]);
1628 const stk::simd::Double yl = stk::simd::load(&y[ns]);
1629 const stk::simd::Double d = ( (xl/yl) + (stk::math::sqrt(yl)+stk::simd::Double(1.0)) )*stk::simd::Double(0.03);
1630 sum_val += stk::simd::reduce_sum(d);
1631 }
1632 t0 += stk::get_time_in_seconds();
1633 std::cout << "OMP: SIMD reduce took " << t0 << " seconds" << std::endl;
1634
1635 save_sum = sum_val;
1636 sum_val = 0.0;
1637
1638 t0 = -stk::get_time_in_seconds();
1639 for (int n=0; n < N; ++n) {
1640 const double xl = x[n];
1641 const double yl = y[n];
1642 double d = ( (xl/yl) + (stk::math::sqrt(yl)+1.0) )*(0.03);
1643 sum_val += d;
1644 }
1645 t0 += stk::get_time_in_seconds();
1646 std::cout << "OMP: Real reduce took " << t0 << " seconds" << std::endl;
1647 }
1648
1649 //printf("sums = %g %g\n",sum_val, save_sum);
1650
1651 EXPECT_NEAR( sum_val-save_sum, 0.0, 1e-12*sum_val );
1652 }
1653
1654 TEST(StkSimd, ReduceMax)
1655 {
1656 double t0; // timing variable
1657
1658 std::vector<double> x = X_RandomValues();
1659 std::vector<double> y = Y_RandomValues(x);
1660
1661 double max_val = std::numeric_limits<double>::min();
1662 double save_max = std::numeric_limits<double>::min();
1663
1664 const int N = x.size();
1665 const int Ns = N/stk::simd::ndoubles;
1666
1667 for (int i=0; i < 3; ++i) {
1668
1669 max_val = std::numeric_limits<double>::min();
1670
1671 t0 = -stk::get_time_in_seconds();
1672 for (int n=0; n < Ns; ++n) {
1673 const int ns = n*stk::simd::ndoubles;
1674 const stk::simd::Double xl = stk::simd::load(&x[ns]);
1675 const stk::simd::Double yl = stk::simd::load(&y[ns]);
1676 const stk::simd::Double d = ( (xl/yl) + (stk::math::sqrt(yl)+stk::simd::Double(1.0)) )*stk::simd::Double(0.03);
1677 max_val = stk::math::max(max_val, stk::simd::reduce_max(d));
1678 }
1679 t0 += stk::get_time_in_seconds();
1680 std::cout << "OMP: SIMD reduce took " << t0 << " seconds" << std::endl;
1681
1682 save_max = max_val;
1683 max_val = std::numeric_limits<double>::min();
1684
1685 t0 = -stk::get_time_in_seconds();
1686 for (int n=0; n < N; ++n) {
1687 const double xl = x[n];
1688 const double yl = y[n];
1689 double d = ( (xl/yl) + (stk::math::sqrt(yl)+1.0) )*(0.03);
1690 max_val = stk::math::max(max_val, d);
1691 }
1692 t0 += stk::get_time_in_seconds();
1693 std::cout << "OMP: Real reduce took " << t0 << " seconds" << std::endl;
1694 }
1695
1696 //printf("sums = %g %g\n",sum_val, save_sum);
1697
1698 EXPECT_EQ( max_val, save_max);
1699 }
1700
1701 TEST(StkSimd, ReduceMin)
1702 {
1703 double t0; // timing variable
1704
1705 std::vector<double> x = X_RandomValues();
1706 std::vector<double> y = Y_RandomValues(x);
1707
1708 double min_val = std::numeric_limits<double>::max();
1709 double save_min = std::numeric_limits<double>::max();
1710
1711 const int N = x.size();
1712 const int Ns = N/stk::simd::ndoubles;
1713
1714 for (int i=0; i < 3; ++i) {
1715 min_val = std::numeric_limits<double>::max();
1716
1717 t0 = -stk::get_time_in_seconds();
1718 for (int n=0; n < Ns; ++n) {
1719 const int ns = n*stk::simd::ndoubles;
1720 const stk::simd::Double xl = stk::simd::load(&x[ns]);
1721 const stk::simd::Double yl = stk::simd::load(&y[ns]);
1722 const stk::simd::Double d = ( (xl/yl) + (stk::math::sqrt(yl)+stk::simd::Double(1.0)) )*stk::simd::Double(0.03);
1723 min_val = stk::math::min(min_val, stk::simd::reduce_min(d));
1724 }
1725 t0 += stk::get_time_in_seconds();
1726 std::cout << "OMP: SIMD reduce took " << t0 << " seconds" << std::endl;
1727
1728 save_min = min_val;
1729 min_val = std::numeric_limits<double>::max();
1730
1731 t0 = -stk::get_time_in_seconds();
1732 for (int n=0; n < N; ++n) {
1733 const double xl = x[n];
1734 const double yl = y[n];
1735 double d = ( (xl/yl) + (stk::math::sqrt(yl)+1.0) )*(0.03);
1736 min_val = stk::math::min(min_val, d);
1737 }
1738 t0 += stk::get_time_in_seconds();
1739 std::cout << "OMP: Real reduce took " << t0 << " seconds" << std::endl;
1740 }
1741
1742 //printf("sums = %g %g\n",sum_val, save_sum);
1743 EXPECT_EQ( min_val, save_min);
1744 }
1745