Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions libclc/opencl/lib/clspv/shared/vstore_half.cl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//

#include <clc/clc_as_type.h>
#include <clc/float/definitions.h>
#include <clc/opencl/math/copysign.h>
#include <clc/opencl/math/fabs.h>
Expand Down Expand Up @@ -59,7 +60,7 @@ _CLC_DEF _CLC_OVERLOAD float __clc_rtz(float x) {
if (fabs(x) > 65504.0f && !isinf(x))
return copysign(65504.0f, x);

const int exp = (as_uint(x) >> 23 & 0xff) - 127;
const int exp = (__clc_as_uint(x) >> 23 & 0xff) - 127;
/* Manage range rounded to +- zero explicitely */
if (exp < -24)
return copysign(0.0f, x);
Expand All @@ -70,7 +71,7 @@ _CLC_DEF _CLC_OVERLOAD float __clc_rtz(float x) {
if (exp < -14)
mask <<= min(-(exp + 14), 10);

return as_float(as_uint(x) & mask);
return __clc_as_float(__clc_as_uint(x) & mask);
}

_CLC_DEF _CLC_OVERLOAD float __clc_rti(float x) {
Expand All @@ -79,18 +80,18 @@ _CLC_DEF _CLC_OVERLOAD float __clc_rti(float x) {
return x;

const float inf = copysign(INFINITY, x);
uint ux = as_uint(x);
uint ux = __clc_as_uint(x);

/* Manage +- infinity explicitely */
if (as_float(ux & 0x7fffffff) > 0x1.ffcp+15f) {
if (__clc_as_float(ux & 0x7fffffff) > 0x1.ffcp+15f) {
return inf;
}
/* Manage +- zero explicitely */
if ((ux & 0x7fffffff) == 0) {
return copysign(0.0f, x);
}

const int exp = (as_uint(x) >> 23 & 0xff) - 127;
const int exp = (__clc_as_uint(x) >> 23 & 0xff) - 127;
/* Manage range rounded to smallest half denormal explicitely */
if (exp < -24) {
return copysign(0x1.0p-24f, x);
Expand All @@ -103,19 +104,19 @@ _CLC_DEF _CLC_OVERLOAD float __clc_rti(float x) {
mask = (1 << (13 + min(-(exp + 14), 10))) - 1;
}

const float next = nextafter(as_float(ux | mask), inf);
return ((ux & mask) == 0) ? as_float(ux) : next;
const float next = nextafter(__clc_as_float(ux | mask), inf);
return ((ux & mask) == 0) ? __clc_as_float(ux) : next;
}
_CLC_DEF _CLC_OVERLOAD float __clc_rtn(float x) {
return ((as_uint(x) & 0x80000000) == 0) ? __clc_rtz(x) : __clc_rti(x);
return ((__clc_as_uint(x) & 0x80000000) == 0) ? __clc_rtz(x) : __clc_rti(x);
}
_CLC_DEF _CLC_OVERLOAD float __clc_rtp(float x) {
return ((as_uint(x) & 0x80000000) == 0) ? __clc_rti(x) : __clc_rtz(x);
return ((__clc_as_uint(x) & 0x80000000) == 0) ? __clc_rti(x) : __clc_rtz(x);
}
_CLC_DEF _CLC_OVERLOAD float __clc_rte(float x) {
/* Mantisa + implicit bit */
const uint mantissa = (as_uint(x) & 0x7fffff) | (1u << 23);
const int exp = (as_uint(x) >> 23 & 0xff) - 127;
const uint mantissa = (__clc_as_uint(x) & 0x7fffff) | (1u << 23);
const int exp = (__clc_as_uint(x) >> 23 & 0xff) - 127;
int shift = 13;
if (exp < -14) {
/* The default assumes lower 13 bits are rounded,
Expand Down
Loading