Added scalar functions cbrt as well as masked Rcp
authorMagnus Lundborg <magnus.lundborg@scilifelab.se>
Thu, 19 Nov 2020 16:49:57 +0000 (17:49 +0100)
committerPaul Bauer <paul.bauer.q@gmail.com>
Fri, 4 Dec 2020 08:47:15 +0000 (08:47 +0000)
These functions as useful for nonbonded FE SIMD kernels.

src/gromacs/simd/scalar/scalar.h
src/gromacs/simd/scalar/scalar_math.h

index 25f0471a43ec6e71dc5c74f5fbf8a9dd1b7844a7..6beb22595dcbf960f37130d23c49b644a928f493 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2016,2017,2018,2019, by the GROMACS development team, led by
+ * Copyright (c) 2016,2017,2018,2019,2020, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -212,6 +212,21 @@ static inline float maskzFma(float a, float b, float c, float m)
     return m != 0.0F ? (a * b + c) : 0.0F;
 }
 
+/*! \brief Float 1.0/x, masked version.
+ *
+ * \param x Argument, x>0 for entries where mask is true.
+ * \param m Mask
+ * \return 1/x. The result for masked-out entries will be 0.0.
+ *
+ * \note This function might be superficially meaningless, but it helps us to
+ *       write templated SIMD/non-SIMD code. For clarity it should not be used
+ *       outside such code.
+ */
+static inline float gmx_simdcall maskzRcp(float x, float m)
+{
+    return m != 0.0F ? 1.0F / x : 0.0F;
+}
+
 /*! \brief Float Floating-point abs().
  *
  * \param a any floating point values
@@ -603,6 +618,21 @@ static inline double maskzFma(double a, double b, double c, double m)
     return m != 0.0 ? (a * b + c) : 0.0;
 }
 
+/*! \brief Double 1.0/x, masked version.
+ *
+ * \param x Argument, x>0 for entries where mask is true.
+ * \param m Mask
+ * \return Approximation of 1/x. The result for masked-out entries will be 0.0.
+ *
+ * \note This function might be superficially meaningless, but it helps us to
+ *       write templated SIMD/non-SIMD code. For clarity it should not be used
+ *       outside such code.
+ */
+static inline double gmx_simdcall maskzRcp(double x, double m)
+{
+    return m != 0.0 ? 1.0 / x : 0.0;
+}
+
 /*! \brief double doubleing-point abs().
  *
  * \param a any doubleing point values
index 246e45b7f2e1c1983a575d001d9ed79aa90f1ecc..a5239859843c8f0b256084865520395479e88b99 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2016,2017,2019, by the GROMACS development team, led by
+ * Copyright (c) 2016,2017,2019,2020, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -169,6 +169,21 @@ static inline float sqrt(float x)
     return std::sqrt(x);
 }
 
+/*! \brief Float cbrt(x). This is the cubic root.
+ *
+ * \param x Argument, should be >= 0.
+ * \result The cubic root of x. Undefined if argument is invalid.
+ *
+ * \note This function might be superficially meaningless, but it helps us to
+ *       write templated SIMD/non-SIMD code. For clarity it should not be used
+ *       outside such code.
+ */
+template<MathOptimization opt = MathOptimization::Safe>
+static inline float cbrt(float x)
+{
+    return std::cbrt(x);
+}
+
 /*! \brief Float log(x). This is the natural logarithm.
  *
  * \param x Argument, should be >0.
@@ -557,6 +572,21 @@ static inline double sqrt(double x)
     return std::sqrt(x);
 }
 
+/*! \brief Double cbrt(x). This is the cubic root.
+ *
+ * \param x Argument, should be >= 0.
+ * \result The cubic root of x. Undefined if argument is invalid.
+ *
+ * \note This function might be superficially meaningless, but it helps us to
+ *       write templated SIMD/non-SIMD code. For clarity it should not be used
+ *       outside such code.
+ */
+template<MathOptimization opt = MathOptimization::Safe>
+static inline double cbrt(double x)
+{
+    return std::cbrt(x);
+}
+
 /*! \brief Double log(x). This is the natural logarithm.
  *
  * \param x Argument, should be >0.