[Libclc-dev] [PATCH 2/2] amdgcn/fmax: Explicitly check for NaNs

Jan Vesely via Libclc-dev libclc-dev at lists.llvm.org
Wed Nov 15 09:21:07 PST 2017


v_max instruction fails to handle certain NaN values

Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
---
Fixes most of fmax CTS on carrizo. It still fails on denormals, but IMO
that's CTS bug.
EG/NI does not seem to suffer the same problem.

 amdgcn/lib/SOURCES      |  1 +
 amdgcn/lib/math/fmax.cl | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)
 create mode 100644 amdgcn/lib/math/fmax.cl

diff --git a/amdgcn/lib/SOURCES b/amdgcn/lib/SOURCES
index 5149f85..36f3397 100644
--- a/amdgcn/lib/SOURCES
+++ b/amdgcn/lib/SOURCES
@@ -1,4 +1,5 @@
 cl_khr_int64_extended_atomics/minmax_helpers.ll
+math/fmax.cl
 math/fmin.cl
 math/ldexp.cl
 mem_fence/fence.cl
diff --git a/amdgcn/lib/math/fmax.cl b/amdgcn/lib/math/fmax.cl
new file mode 100644
index 0000000..204bbd6
--- /dev/null
+++ b/amdgcn/lib/math/fmax.cl
@@ -0,0 +1,32 @@
+#include <clc/clc.h>
+
+#include "../../../generic/lib/clcmacro.h"
+
+_CLC_DEF _CLC_OVERLOAD float fmax(float x, float y)
+{
+   if (isnan(x))
+      return y;
+   if (isnan(y))
+      return x;
+   return (x < y) ? y : x;
+}
+_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, fmax, float, float)
+
+#ifdef cl_khr_fp64
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+_CLC_DEF _CLC_OVERLOAD double fmax(double x, double y)
+{
+   if (isnan(x))
+      return y;
+   if (isnan(y))
+      return x;
+   return (x < y) ? y : x;
+}
+_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, fmax, double, double)
+
+#endif
+
+#define __CLC_BODY <../../../generic/lib/math/fmax.inc>
+#include <clc/math/gentype.inc>
-- 
2.13.6



More information about the Libclc-dev mailing list