aboutsummaryrefslogtreecommitdiff
path: root/libclc
diff options
context:
space:
mode:
authorJan Vesely <jan.vesely@rutgers.edu>2018-05-03 05:44:22 +0000
committerJan Vesely <jan.vesely@rutgers.edu>2018-05-03 05:44:22 +0000
commit6146eda75dbf8e734b02d02a7c4a62804e04293f (patch)
treef926f72035dc16c32457c11eddf2ddd2403d2d5f /libclc
parent8ef2abdbc4018e898b097df3a9b0aad0fc1a185d (diff)
math: Add helper function to flush denormals if not supported.
Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu> Reviewer: Aaron Watry <awatry@gmail.com> llvm-svn: 331433
Diffstat (limited to 'libclc')
-rw-r--r--libclc/generic/lib/math/math.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/libclc/generic/lib/math/math.h b/libclc/generic/lib/math/math.h
index 91d116e95d6f..c931d19a380c 100644
--- a/libclc/generic/lib/math/math.h
+++ b/libclc/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_