From efadf5a694663b8d2a9bbd52f14f8cb0ee8a5dcc Mon Sep 17 00:00:00 2001
From: Nicola Vigano <nicola.vigano@esrf.fr>
Date: Tue, 17 Jul 2012 10:22:04 +0000
Subject: [PATCH] Cell operations: added sqrt and another variant of
 exponential

Signed-off-by: Nicola Vigano <nicola.vigano@esrf.fr>

git-svn-id: https://svn.code.sf.net/p/dct/code/trunk@663 4c865b51-4357-4376-afb4-474e03ccb993
---
 .../internal_cell_exponent_assign.cpp         | 31 +++++++++++++++++++
 ...nt.cpp => internal_cell_exponent_copy.cpp} |  0
 .../internal_cell_sqrt_assign.cpp             | 31 +++++++++++++++++++
 .../internal_cell_sqrt_copy.cpp               | 29 +++++++++++++++++
 zUtil_Cxx/include/internal_cell_defs.h        | 22 +++++++++++++
 5 files changed, 113 insertions(+)
 create mode 100755 zUtil_Cxx/cell_operations/internal_cell_exponent_assign.cpp
 rename zUtil_Cxx/cell_operations/{internal_cell_exponent.cpp => internal_cell_exponent_copy.cpp} (100%)
 create mode 100755 zUtil_Cxx/cell_operations/internal_cell_sqrt_assign.cpp
 create mode 100755 zUtil_Cxx/cell_operations/internal_cell_sqrt_copy.cpp

diff --git a/zUtil_Cxx/cell_operations/internal_cell_exponent_assign.cpp b/zUtil_Cxx/cell_operations/internal_cell_exponent_assign.cpp
new file mode 100755
index 00000000..8bf7261d
--- /dev/null
+++ b/zUtil_Cxx/cell_operations/internal_cell_exponent_assign.cpp
@@ -0,0 +1,31 @@
+/*
+ * internal_cell_exponent.cpp
+ *
+ *  Created on: Jul 10, 2012
+ *
+ * Nicola Vigano', 2012, ID11 @ ESRF vigano@esrf.eu
+ */
+
+#include "internal_cell_defs.h"
+
+void mexFunction( int nlhs, mxArray * plhs[], int nrhs, const mxArray * prhs[] )
+{
+  if (nrhs != 2) {
+    mexErrMsgIdAndTxt("C_FUN:cell_exponent_wrong_argument",
+        "Not enough arguments! you need to provide a cell array and a double");
+  }
+  if (!mxIsCell(prhs[0])) {
+    mexErrMsgIdAndTxt("C_FUN:cell_exponent_wrong_argument",
+        "The first argument should be a Cell array");
+  }
+  if (!mxIsDouble(prhs[1])) {
+    mexErrMsgIdAndTxt("C_FUN:cell_exponent_wrong_argument",
+        "The second argument should be a double containing the exponent");
+  }
+  const double exponent = *mxGetPr(prhs[1]);
+
+  plhs[0] = (mxArray *) prhs[0];
+
+  inner_pow<const double, const double> func(exponent);
+  cell_iteration<false>(plhs[0], prhs[0], func);
+}
diff --git a/zUtil_Cxx/cell_operations/internal_cell_exponent.cpp b/zUtil_Cxx/cell_operations/internal_cell_exponent_copy.cpp
similarity index 100%
rename from zUtil_Cxx/cell_operations/internal_cell_exponent.cpp
rename to zUtil_Cxx/cell_operations/internal_cell_exponent_copy.cpp
diff --git a/zUtil_Cxx/cell_operations/internal_cell_sqrt_assign.cpp b/zUtil_Cxx/cell_operations/internal_cell_sqrt_assign.cpp
new file mode 100755
index 00000000..9ecc2ab7
--- /dev/null
+++ b/zUtil_Cxx/cell_operations/internal_cell_sqrt_assign.cpp
@@ -0,0 +1,31 @@
+/*
+ * internal_cell_exponent.cpp
+ *
+ *  Created on: Jul 10, 2012
+ *
+ * Nicola Vigano', 2012, ID11 @ ESRF vigano@esrf.eu
+ */
+
+#include "internal_cell_defs.h"
+
+void mexFunction( int nlhs, mxArray * plhs[], int nrhs, const mxArray * prhs[] )
+{
+  if (nrhs != 1) {
+    mexErrMsgIdAndTxt("C_FUN:cell_exponent_wrong_argument",
+        "Not enough arguments! you need to provide a cell array and a double");
+  }
+  if (!mxIsCell(prhs[0])) {
+    mexErrMsgIdAndTxt("C_FUN:cell_exponent_wrong_argument",
+        "The first argument should be a Cell array");
+  }
+
+  plhs[0] = (mxArray *) prhs[0];
+
+  inner_sqrt<const double, const double> funcNonVect;
+#if defined(__SSE2__) || defined(__SSE2_MATH__)
+  inner_sqrt<const v2df, const v2df> func;
+  cell_iteration_sse<false>(plhs[0], prhs[0], func, funcNonVect);
+#else
+  cell_iteration<false>(plhs[0], prhs[0], funcNonVect);
+#endif
+}
diff --git a/zUtil_Cxx/cell_operations/internal_cell_sqrt_copy.cpp b/zUtil_Cxx/cell_operations/internal_cell_sqrt_copy.cpp
new file mode 100755
index 00000000..8638f23d
--- /dev/null
+++ b/zUtil_Cxx/cell_operations/internal_cell_sqrt_copy.cpp
@@ -0,0 +1,29 @@
+/*
+ * internal_cell_exponent.cpp
+ *
+ *  Created on: Jul 10, 2012
+ *
+ * Nicola Vigano', 2012, ID11 @ ESRF vigano@esrf.eu
+ */
+
+#include "internal_cell_defs.h"
+
+void mexFunction( int nlhs, mxArray * plhs[], int nrhs, const mxArray * prhs[] )
+{
+  if (nrhs != 1) {
+    mexErrMsgIdAndTxt("C_FUN:cell_exponent_wrong_argument",
+        "Not enough arguments! you need to provide a cell array and a double");
+  }
+  if (!mxIsCell(prhs[0])) {
+    mexErrMsgIdAndTxt("C_FUN:cell_exponent_wrong_argument",
+        "The first argument should be a Cell array");
+  }
+
+  inner_sqrt<const double, const double> funcNonVect;
+#if defined(__SSE2__) || defined(__SSE2_MATH__)
+  inner_sqrt<const v2df, const v2df> func;
+  cell_iteration_sse<true>(plhs[0], prhs[0], func, funcNonVect);
+#else
+  cell_iteration<true>(plhs[0], prhs[0], funcNonVect);
+#endif
+}
diff --git a/zUtil_Cxx/include/internal_cell_defs.h b/zUtil_Cxx/include/internal_cell_defs.h
index e52d42ad..47bb6d10 100755
--- a/zUtil_Cxx/include/internal_cell_defs.h
+++ b/zUtil_Cxx/include/internal_cell_defs.h
@@ -41,6 +41,28 @@ public:
   }
 };
 
+template<typename Type1, typename Type2>
+class inner_sqrt {
+public:
+  const Type2
+  operator()(Type1 & inData1, Type2 & inData2) const throw()
+  {
+    return sqrt(inData2); // __builtin_ia32_sqrtpd
+  }
+};
+
+#if defined(__SSE2__) || defined(__SSE2_MATH__)
+template<>
+class inner_sqrt<const v2df, const v2df> {
+public:
+  const v2df
+  operator()(const v2df & inData1, const v2df & inData2) const throw()
+  {
+    return __builtin_ia32_sqrtpd(inData2);
+  }
+};
+#endif
+
 template<typename Type1, typename Type2>
 class inner_sum {
 public:
-- 
GitLab