Sort all includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / simd / tests / simd4_floatingpoint.cpp
index 41aa5aa85f324fe7492d6526104b0b02d4b7655b..68a448e3db70155b124f39bd4a5295d6a2a1857a 100644 (file)
  * To help us fund GROMACS development, we humbly ask that you cite
  * the research papers on the package. Check out http://www.gromacs.org.
  */
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "gmxpre.h"
 
 #include <math.h>
+
 #include "gromacs/math/utilities.h"
 
 #include "simd4.h"
@@ -121,25 +120,47 @@ TEST_F(Simd4FloatingpointTest, gmxSimd4FnegR)
 }
 
 #ifdef GMX_SIMD4_HAVE_LOGICAL
+/* 1.3333282470703125 has mantissa 0101010101010101 (followed by zeros)
+ * 1.79998779296875   has mantissa 1100110011001100 (followed by zeros)
+ * 1.26666259765625   has mantissa 0100010001000100 (followed by zeros)
+ * 1.8666534423828125 has mantissa 1101110111011101 (followed by zeros)
+ *
+ * Since all of them have the same exponent (2^0), the exponent will
+ * not change with AND or OR operations.
+ */
 TEST_F(Simd4FloatingpointTest, gmxSimd4AndR)
 {
-    GMX_EXPECT_SIMD4_REAL_EQ(rSimd4_Bits3, gmx_simd4_and_r(rSimd4_Bits1, rSimd4_Bits2)); // Bits1 & Bits2 = Bits3
+    GMX_EXPECT_SIMD4_REAL_EQ(setSimd4RealFrom1R(1.26666259765625),
+                             gmx_simd4_and_r(gmx_simd4_set1_r(1.3333282470703125),
+                                             gmx_simd4_set1_r(1.79998779296875)));
 }
 
-TEST_F(Simd4FloatingpointTest, gmxSimd4AndnotR)
+TEST_F(Simd4FloatingpointTest, gmxSimd4OrR)
 {
-    GMX_EXPECT_SIMD4_REAL_EQ(rSimd4_Bits4, gmx_simd4_andnot_r(rSimd4_Bits1, rSimd4_Bits2)); // (~Bits1) & Bits2 = Bits3
+    GMX_EXPECT_SIMD4_REAL_EQ(setSimd4RealFrom1R(1.8666534423828125),
+                             gmx_simd4_or_r(gmx_simd4_set1_r(1.3333282470703125),
+                                            gmx_simd4_set1_r(1.79998779296875)));
 }
 
-TEST_F(Simd4FloatingpointTest, gmxSimd4OrR)
+TEST_F(Simd4FloatingpointTest, gmxSimd4XorR)
 {
-    GMX_EXPECT_SIMD4_REAL_EQ(rSimd4_Bits5, gmx_simd4_or_r(rSimd4_Bits1, rSimd4_Bits2)); // Bits1 | Bits2 = Bits3
+    /* Test xor by taking xor with a number and its negative. This should result
+     * in only the sign bit being set. We then use this bit change the sign of
+     * different numbers.
+     */
+    gmx_simd4_real_t signbit = gmx_simd4_xor_r(gmx_simd4_set1_r(1.5), gmx_simd4_set1_r(-1.5));
+    GMX_EXPECT_SIMD4_REAL_EQ(setSimd4RealFrom3R(-1, 2, -3), gmx_simd4_xor_r(signbit, setSimd4RealFrom3R(1, -2, 3)));
 }
 
-TEST_F(Simd4FloatingpointTest, gmxSimd4XorR)
+TEST_F(Simd4FloatingpointTest, gmxSimd4AndnotR)
 {
-    GMX_EXPECT_SIMD4_REAL_EQ(rSimd4_Bits6, gmx_simd4_xor_r(rSimd4_Bits1, rSimd4_Bits2)); // Bits1 ^ Bits2 = Bits3
+    /* Use xor (which we already tested, so fix that first if both tests fail)
+     * to extract the sign bit, and then use andnot to take absolute values.
+     */
+    gmx_simd4_real_t signbit = gmx_simd4_xor_r(gmx_simd4_set1_r(1.5), gmx_simd4_set1_r(-1.5));
+    GMX_EXPECT_SIMD4_REAL_EQ(setSimd4RealFrom3R(1, 2, 3), gmx_simd4_andnot_r(signbit, setSimd4RealFrom3R(-1, 2, -3)));
 }
+
 #endif
 
 TEST_F(Simd4FloatingpointTest, gmxSimd4MaxR)