29 #ifndef OPENCL_CL_HALF_H
30 #define OPENCL_CL_HALF_H
54 #define CL_HALF_EXP_MASK 0x7C00
55 #define CL_HALF_MAX_FINITE_MAG 0x7BFF
93 return (sign << 15) | 1;
98 return (sign << 15) | 1;
120 uint16_t sign = f32.i >> 31;
141 uint16_t h_mant = (uint16_t)(f_mant >> lsb_pos);
153 if (!f_exp && !f_mant)
161 return cl_half_handle_overflow(rounding_mode, sign);
167 return cl_half_handle_underflow(rounding_mode, sign);
182 uint16_t h_mant = (uint16_t)(f_mant >> lsb_pos);
185 uint32_t halfway = 1 << (lsb_pos - 1);
186 uint32_t
mask = (halfway << 1) - 1;
187 switch (rounding_mode)
190 if ((f_mant & mask) > halfway)
195 else if ((f_mant & mask) == halfway)
206 if ((f_mant & mask) && !
sign)
213 if ((f_mant & mask) &&
sign)
228 return (sign << 15) | (h_exp << 10) | h_mant;
246 uint16_t sign = f64.i >> 63;
250 uint64_t d_mant = f64.i & (((uint64_t)1 << (
CL_DBL_MANT_DIG - 1)) - 1);
267 uint16_t h_mant = (uint16_t)(d_mant >> lsb_pos);
279 if (!d_exp && !d_mant)
287 return cl_half_handle_overflow(rounding_mode, sign);
293 return cl_half_handle_underflow(rounding_mode, sign);
308 uint16_t h_mant = (uint16_t)(d_mant >> lsb_pos);
311 uint64_t halfway = (uint64_t)1 << (lsb_pos - 1);
312 uint64_t mask = (halfway << 1) - 1;
313 switch (rounding_mode)
316 if ((d_mant & mask) > halfway)
321 else if ((d_mant & mask) == halfway)
332 if ((d_mant & mask) && !
sign)
339 if ((d_mant & mask) &&
sign)
354 return (sign << 15) | (h_exp << 10) | h_mant;
371 uint16_t sign = h >> 15;
374 uint16_t h_exp = (h >> (CL_HALF_MANT_DIG - 1)) & 0x1F;
375 uint16_t h_mant = h & 0x3FF;
381 uint32_t f_exp = exp + CL_FLT_MAX_EXP - 1;
391 f32.i = (sign << 31) | 0x7F800000 | f_mant;
397 f32.i = (sign << 31) | 0x7F800000;
416 while ((h_mant & 0x400) == 0)
426 f32.i = (sign << 31) | (f_exp << 23) | (h_mant << 13);
431 #undef CL_HALF_EXP_MASK
432 #undef CL_HALF_MAX_FINITE_MAG
OIIO_FORCEINLINE T exp(const T &v)
IMATH_HOSTDEVICE constexpr int sign(T a) IMATH_NOEXCEPT
GLfloat GLfloat GLfloat GLfloat h
#define CL_HALF_MAX_FINITE_MAG