[Libclc-dev] [PATCH 1/3] math: Add helper function to flush denormals if not supported.

Jan Vesely via Libclc-dev libclc-dev at lists.llvm.org
Tue May 1 15:01:25 PDT 2018


Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
---
 generic/lib/math/math.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/generic/lib/math/math.h b/generic/lib/math/math.h
index 91d116e..c931d19 100644
--- a/generic/lib/math/math.h
+++ b/generic/lib/math/math.h
@@ -20,6 +20,13 @@
  * THE SOFTWARE.
  */
 
+#ifndef __CLC_MATH_H_
+#define __CLC_MATH_H_
+
+#include "clc/clcfunc.h"
+#include "clc/as_type.h"
+#include "config.h"
+
 #define SNAN 0x001
 #define QNAN 0x002
 #define NINF 0x004
@@ -66,6 +73,17 @@
 #define MANTLENGTH_SP32   24
 #define BASEDIGITS_SP32   7
 
+_CLC_OVERLOAD _CLC_INLINE float __clc_flush_denormal_if_not_supported(float x)
+{
+	int ix = as_int(x);
+	if (!__clc_fp32_subnormals_supported() &&
+		((ix & EXPBITS_SP32) == 0) && ((ix & MANTBITS_SP32) != 0)) {
+		ix &= SIGNBIT_SP32;
+		x = as_float(ix);
+	}
+	return x;
+}
+
 #ifdef cl_khr_fp64
 
 #define SIGNBIT_DP64      0x8000000000000000L
@@ -93,3 +111,4 @@
 #endif // cl_khr_fp64
 
 #define ALIGNED(x)	__attribute__((aligned(x)))
+#endif // __CLC_MATH_H_
-- 
2.14.3



More information about the Libclc-dev mailing list