Author: jvesely
Date: Tue Feb  6 10:44:45 2018
New Revision: 324374

URL: http://llvm.org/viewvc/llvm-project?rev=324374&view=rev
Log:
Add vstore_half_rtn implementation

Passes CTS on carrizo

Reviewer: Jeroen Ketema <j.ket...@xs4all.nl>
Signed-off-by: Jan Vesely <jan.ves...@rutgers.edu>

Modified:
    libclc/trunk/generic/include/clc/shared/vstore.h
    libclc/trunk/generic/lib/shared/vstore.cl

Modified: libclc/trunk/generic/include/clc/shared/vstore.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/shared/vstore.h?rev=324374&r1=324373&r2=324374&view=diff
==============================================================================
--- libclc/trunk/generic/include/clc/shared/vstore.h (original)
+++ libclc/trunk/generic/include/clc/shared/vstore.h Tue Feb  6 10:44:45 2018
@@ -38,11 +38,13 @@ _CLC_VECTOR_VSTORE_PRIM1(float)
 
 _CLC_VECTOR_VSTORE_HALF_PRIM1(float,)
 _CLC_VECTOR_VSTORE_HALF_PRIM1(float, _rtz)
+_CLC_VECTOR_VSTORE_HALF_PRIM1(float, _rtn)
 
 #ifdef cl_khr_fp64
   _CLC_VECTOR_VSTORE_PRIM1(double)
   _CLC_VECTOR_VSTORE_HALF_PRIM1(double,)
   _CLC_VECTOR_VSTORE_HALF_PRIM1(double, _rtz)
+  _CLC_VECTOR_VSTORE_HALF_PRIM1(double, _rtn)
 #endif
 
 #ifdef cl_khr_fp16

Modified: libclc/trunk/generic/lib/shared/vstore.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/shared/vstore.cl?rev=324374&r1=324373&r2=324374&view=diff
==============================================================================
--- libclc/trunk/generic/lib/shared/vstore.cl (original)
+++ libclc/trunk/generic/lib/shared/vstore.cl Tue Feb  6 10:44:45 2018
@@ -124,6 +124,26 @@ _CLC_DEF _CLC_OVERLOAD float __clc_rtz(f
                return x;
        return as_float(as_uint(x) & mask);
 }
+_CLC_DEF _CLC_OVERLOAD float __clc_rti(float x)
+{
+       const float inf = copysign(INFINITY, x);
+       /* Set lower 13 bits */
+       int mask = (1 << 13) - 1;
+       const int exp = (as_uint(x) >> 23 & 0xff) - 127;
+       /* Denormals cannot be flushed, and they use different bit for rounding 
*/
+       if (exp < -14)
+               mask = (1 << (13 + min(-(exp + 14), 10))) - 1;
+       /* Handle nan corner case */
+       if (isnan(x))
+               return x;
+       const float next = nextafter(as_float(as_uint(x) | mask), inf);
+       return ((as_uint(x) & mask) == 0) ? x : next;
+}
+_CLC_DEF _CLC_OVERLOAD float __clc_rtn(float x)
+{
+       return ((as_uint(x) & 0x80000000) == 0) ? __clc_rtz(x) : __clc_rti(x);
+}
+
 #ifdef cl_khr_fp64
 _CLC_DEF _CLC_OVERLOAD double __clc_noop(double x)
 {
@@ -145,11 +165,31 @@ _CLC_DEF _CLC_OVERLOAD double __clc_rtz(
                return x;
        return as_double(as_ulong(x) & mask);
 }
+_CLC_DEF _CLC_OVERLOAD double __clc_rti(double x)
+{
+       const double inf = copysign((double)INFINITY, x);
+       /* Set lower 42 bits */
+       long mask = (1UL << 42UL) - 1UL;
+       const int exp = (as_ulong(x) >> 52 & 0x7ff) - 1023;
+       /* Denormals cannot be flushed, and they use different bit for rounding 
*/
+       if (exp < -14)
+               mask = (1UL << (42UL + min(-(exp + 14), 10))) - 1;
+       /* Handle nan corner case */
+       if (isnan(x))
+               return x;
+       const double next = nextafter(as_double(as_ulong(x) | mask), inf);
+       return ((as_ulong(x) & mask) == 0) ? x : next;
+}
+_CLC_DEF _CLC_OVERLOAD double __clc_rtn(double x)
+{
+       return ((as_ulong(x) & 0x8000000000000000UL) == 0) ? __clc_rtz(x) : 
__clc_rti(x);
+}
 #endif
 
 #define __XFUNC(SUFFIX, VEC_SIZE, OFFSET, TYPE, STYPE, AS) \
        __FUNC(SUFFIX, VEC_SIZE, OFFSET, TYPE, STYPE, AS, __clc_noop) \
-       __FUNC(SUFFIX ## _rtz, VEC_SIZE, OFFSET, TYPE, STYPE, AS, __clc_rtz)
+       __FUNC(SUFFIX ## _rtz, VEC_SIZE, OFFSET, TYPE, STYPE, AS, __clc_rtz) \
+       __FUNC(SUFFIX ## _rtn, VEC_SIZE, OFFSET, TYPE, STYPE, AS, __clc_rtn)
 
 #define FUNC(SUFFIX, VEC_SIZE, OFFSET, TYPE, STYPE, AS) \
        __XFUNC(SUFFIX, VEC_SIZE, OFFSET, TYPE, STYPE, AS)


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to