Skip to content

Commit

Permalink
Merge remote-tracking branch 'frasercrmck/cherry-pick-libclc' into HEAD
Browse files Browse the repository at this point in the history
Closes: #16249
  • Loading branch information
sarnex committed Dec 4, 2024
2 parents d0d8a56 + 37f93d9 commit 7923d30
Show file tree
Hide file tree
Showing 28 changed files with 112 additions and 136 deletions.
14 changes: 14 additions & 0 deletions libclc/clc/include/clc/integer/clc_abs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef __CLC_INTEGER_CLC_ABS_H__
#define __CLC_INTEGER_CLC_ABS_H__

#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
// clspv and spir-v targets provide their own OpenCL-compatible abs
#define __clc_abs abs
#else

#define __CLC_BODY <clc/integer/clc_abs.inc>
#include <clc/integer/gentype.inc>

#endif

#endif // __CLC_INTEGER_CLC_ABS_H__
1 change: 1 addition & 0 deletions libclc/clc/include/clc/integer/clc_abs.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_CLC_OVERLOAD _CLC_DECL __CLC_U_GENTYPE __clc_abs(__CLC_GENTYPE x);
14 changes: 14 additions & 0 deletions libclc/clc/include/clc/integer/clc_abs_diff.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef __CLC_INTEGER_CLC_ABS_DIFF_H__
#define __CLC_INTEGER_CLC_ABS_DIFF_H__

#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
// clspv and spir-v targets provide their own OpenCL-compatible abs_diff
#define __clc_abs_diff abs_diff
#else

#define __CLC_BODY <clc/integer/clc_abs_diff.inc>
#include <clc/integer/gentype.inc>

#endif

#endif // __CLC_INTEGER_CLC_ABS_DIFF_H__
2 changes: 2 additions & 0 deletions libclc/clc/include/clc/integer/clc_abs_diff.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_CLC_OVERLOAD _CLC_DECL __CLC_U_GENTYPE __clc_abs_diff(__CLC_GENTYPE x,
__CLC_GENTYPE y);
20 changes: 20 additions & 0 deletions libclc/clc/lib/generic/SOURCES
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
geometric/clc_dot.cl
integer/clc_abs.cl
integer/clc_abs_diff.cl
relational/clc_all.cl
relational/clc_any.cl
relational/clc_bitselect.cl
relational/clc_isequal.cl
relational/clc_isfinite.cl
relational/clc_isgreater.cl
relational/clc_isgreaterequal.cl
relational/clc_isinf.cl
relational/clc_isless.cl
relational/clc_islessequal.cl
relational/clc_islessgreater.cl
relational/clc_isnan.cl
relational/clc_isnormal.cl
relational/clc_isnotequal.cl
relational/clc_isordered.cl
relational/clc_isunordered.cl
relational/clc_select.cl
relational/clc_signbit.cl
shared/clc_clamp.cl
shared/clc_max.cl
shared/clc_min.cl
4 changes: 4 additions & 0 deletions libclc/clc/lib/generic/integer/clc_abs.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include <clc/internal/clc.h>

#define __CLC_BODY <clc_abs.inc>
#include <clc/integer/gentype.inc>
4 changes: 4 additions & 0 deletions libclc/clc/lib/generic/integer/clc_abs.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
_CLC_OVERLOAD _CLC_DEF __CLC_U_GENTYPE __clc_abs(__CLC_GENTYPE x) {
return __builtin_astype((__CLC_GENTYPE)(x > (__CLC_GENTYPE)(0) ? x : -x),
__CLC_U_GENTYPE);
}
4 changes: 4 additions & 0 deletions libclc/clc/lib/generic/integer/clc_abs_diff.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include <clc/internal/clc.h>

#define __CLC_BODY <clc_abs_diff.inc>
#include <clc/integer/gentype.inc>
6 changes: 6 additions & 0 deletions libclc/clc/lib/generic/integer/clc_abs_diff.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
_CLC_OVERLOAD _CLC_DEF __CLC_U_GENTYPE __clc_abs_diff(__CLC_GENTYPE x,
__CLC_GENTYPE y) {
__CLC_U_GENTYPE ux = __builtin_astype(x, __CLC_U_GENTYPE);
__CLC_U_GENTYPE uy = __builtin_astype(y, __CLC_U_GENTYPE);
return x > y ? ux - uy : uy - ux;
}
3 changes: 1 addition & 2 deletions libclc/generic/lib/integer/abs.cl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <clc/clc.h>
#include <core/clc_core.h>
#include <spirv/spirv.h>
#include <clc/integer/clc_abs.h>

#define __CLC_BODY <abs.inc>
#include <clc/integer/gentype.inc>
2 changes: 1 addition & 1 deletion libclc/generic/lib/integer/abs.inc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
_CLC_OVERLOAD _CLC_DEF __CLC_U_GENTYPE abs(__CLC_GENTYPE x) {
return __builtin_astype((__CLC_GENTYPE)(x > (__CLC_GENTYPE)(0) ? x : -x), __CLC_U_GENTYPE);
return __clc_abs(x);
}
3 changes: 1 addition & 2 deletions libclc/generic/lib/integer/abs_diff.cl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <clc/clc.h>
#include <core/clc_core.h>
#include <spirv/spirv.h>
#include <clc/integer/clc_abs_diff.h>

#define __CLC_BODY <abs_diff.inc>
#include <clc/integer/gentype.inc>
4 changes: 1 addition & 3 deletions libclc/generic/lib/integer/abs_diff.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
_CLC_OVERLOAD _CLC_DEF __CLC_U_GENTYPE abs_diff(__CLC_GENTYPE x, __CLC_GENTYPE y) {
__CLC_U_GENTYPE ux = __builtin_astype(x, __CLC_U_GENTYPE);
__CLC_U_GENTYPE uy = __builtin_astype(y, __CLC_U_GENTYPE);
return x > y ? ux - uy : uy - ux;
return __clc_abs_diff(x, y);
}
4 changes: 3 additions & 1 deletion libclc/generic/lib/math/clc_ldexp.cl
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
* THE SOFTWARE.
*/

#include "../clcmacro.h"
#include "config.h"
#include "math.h"
#include <clc/clc.h>
#include <clc/clcmacro.h>
#include <clc/relational/clc_isinf.h>
#include <clc/relational/clc_isnan.h>
#include <clc/shared/clc_clamp.h>

_CLC_DEF _CLC_OVERLOAD float __clc_ldexp(float x, int n) {
Expand Down
32 changes: 4 additions & 28 deletions libclc/generic/lib/relational/isinf.cl
Original file line number Diff line number Diff line change
@@ -1,31 +1,7 @@
#include <clc/clc.h>
#include <spirv/spirv.h>
#include "relational.h"
#include <clc/relational/clc_isinf.h>

_CLC_DEFINE_RELATIONAL_UNARY(int, isinf, __spirv_IsInf, float)
#define FUNCTION isinf
#define __CLC_BODY "unary_def.inc"

#ifdef cl_khr_fp64

#pragma OPENCL EXTENSION cl_khr_fp64 : enable

// The scalar version of isinf(double) returns an int, but the vector versions
// return long.
_CLC_DEF _CLC_OVERLOAD int isinf(double x) {
return __spirv_IsInf(x);
}

_CLC_DEFINE_RELATIONAL_UNARY_VEC_ALL(long, isinf, double)
#endif

#ifdef cl_khr_fp16

#pragma OPENCL EXTENSION cl_khr_fp16 : enable

// The scalar version of isinf(half) returns an int, but the vector versions
// return short.
_CLC_DEF _CLC_OVERLOAD int isinf(half x) {
return __spirv_IsInf(x);
}

_CLC_DEFINE_RELATIONAL_UNARY_VEC_ALL(short, isinf, half)
#endif
#include <clc/relational/floatn.inc>
34 changes: 4 additions & 30 deletions libclc/generic/lib/relational/isnan.cl
Original file line number Diff line number Diff line change
@@ -1,33 +1,7 @@
#include <clc/clc.h>
#include <spirv/spirv.h>
#include "relational.h"
#include <clc/relational/clc_isnan.h>

_CLC_DEFINE_RELATIONAL_UNARY(int, isnan, __spirv_IsNan, float)
#define FUNCTION isnan
#define __CLC_BODY "unary_def.inc"

#ifdef cl_khr_fp64

#pragma OPENCL EXTENSION cl_khr_fp64 : enable

// The scalar version of isnan(double) returns an int, but the vector versions
// return long.
_CLC_DEF _CLC_OVERLOAD int isnan(double x) {
return __spirv_IsNan(x);
}

_CLC_DEFINE_RELATIONAL_UNARY_VEC_ALL(long, isnan, double)

#endif

#ifdef cl_khr_fp16

#pragma OPENCL EXTENSION cl_khr_fp16 : enable

// The scalar version of isnan(half) returns an int, but the vector versions
// return short.
_CLC_DEF _CLC_OVERLOAD int isnan(half x) {
return __spirv_IsNan(x);
}

_CLC_DEFINE_RELATIONAL_UNARY_VEC_ALL(short, isnan, half)

#endif
#include <clc/relational/floatn.inc>
2 changes: 0 additions & 2 deletions libclc/generic/libspirv/SOURCES
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ common/radians.cl
common/sign.cl
common/smoothstep.cl
common/step.cl
core/integer/clc_abs.cl
core/integer/clc_abs_diff.cl
core/integer/clc_add_sat.cl
core/integer/clc_hadd.cl
core/integer/clc_mad24.cl
Expand Down
12 changes: 0 additions & 12 deletions libclc/generic/libspirv/core/integer/clc_abs.cl

This file was deleted.

12 changes: 0 additions & 12 deletions libclc/generic/libspirv/core/integer/clc_abs.inc

This file was deleted.

12 changes: 0 additions & 12 deletions libclc/generic/libspirv/core/integer/clc_abs_diff.cl

This file was deleted.

14 changes: 0 additions & 14 deletions libclc/generic/libspirv/core/integer/clc_abs_diff.inc

This file was deleted.

3 changes: 2 additions & 1 deletion libclc/generic/libspirv/integer/abs.cl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
//
//===----------------------------------------------------------------------===//

#include <core/clc_core.h>
#include <clc/internal/clc.h>
#include <clc/integer/clc_abs.h>
#include <spirv/spirv.h>

#define __CLC_BODY <abs.inc>
Expand Down
3 changes: 2 additions & 1 deletion libclc/generic/libspirv/integer/abs_diff.cl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
//
//===----------------------------------------------------------------------===//

#include <core/clc_core.h>
#include <clc/internal/clc.h>
#include <clc/integer/clc_abs_diff.h>
#include <spirv/spirv.h>

#define __CLC_BODY <abs_diff.inc>
Expand Down
4 changes: 2 additions & 2 deletions libclc/generic/libspirv/math/clc_exp10.cl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ _CLC_DEF _CLC_OVERLOAD float __clc_exp10(float x)
const float R_LOG10_2_BY_64_TL = 0x1.04d426p-18f; // log2/(64 * log10) tail : 0.00000388665057
const float R_LN10 = 0x1.26bb1cp+1f;

int return_nan = __spirv_IsNan(x);
int return_nan = __clc_isnan(x);
int return_inf = x > X_MAX;
int return_zero = x < X_MIN;

Expand Down Expand Up @@ -143,7 +143,7 @@ _CLC_DEF _CLC_OVERLOAD double __clc_exp10(double x)
z2 = __spirv_ocl_ldexp(z2, m);
z2 = small_value ? z3: z2;

z2 = __spirv_IsNan(x) ? x : z2;
z2 = __clc_isnan(x) ? x : z2;

z2 = x > X_MAX ? as_double(PINFBITPATT_DP64) : z2;
z2 = x < X_MIN ? 0.0 : z2;
Expand Down
10 changes: 7 additions & 3 deletions libclc/generic/libspirv/math/clc_fma.cl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
*/

#include <clc/clcmacro.h>
#include <clc/integer/clc_abs.h>
#include <clc/relational/clc_isinf.h>
#include <clc/relational/clc_isnan.h>
#include <clc/shared/clc_max.h>
#include <config.h>
#include <core/clc_core.h>
#include <math/math.h>
Expand All @@ -34,12 +38,12 @@ struct fp {

_CLC_DEF _CLC_OVERLOAD float __clc_sw_fma(float a, float b, float c) {
/* special cases */
if (__spirv_IsNan(a) || __spirv_IsNan(b) || __spirv_IsNan(c) ||
__spirv_IsInf(a) || __spirv_IsInf(b))
if (__clc_isnan(a) || __clc_isnan(b) || __clc_isnan(c) || __clc_isinf(a) ||
__clc_isinf(b))
return __spirv_ocl_mad(a, b, c);

/* If only c is inf, and both a,b are regular numbers, the result is c*/
if (__spirv_IsInf(c))
if (__clc_isinf(c))
return c;

a = __clc_flush_denormal_if_not_supported(a);
Expand Down
8 changes: 5 additions & 3 deletions libclc/generic/libspirv/math/clc_hypot.cl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
#include <spirv/spirv.h>

#include <clc/clc.h>
#include <clc/shared/clc_clamp.h>
#include <clc/clcmacro.h>
#include <clc/integer/clc_abs.h>
#include <clc/relational/clc_isnan.h>
#include <clc/shared/clc_clamp.h>
#include <config.h>
#include <math/clc_hypot.h>
#include <math/math.h>
Expand Down Expand Up @@ -69,12 +71,12 @@ _CLC_DEF _CLC_OVERLOAD double __clc_hypot(double x, double y) {

// If the difference in exponents between x and y is large
double s = x + y;
c = __spirv_ocl_s_abs(xexp - yexp) > MANTLENGTH_DP64 + 1;
c = __clc_abs(xexp - yexp) > MANTLENGTH_DP64 + 1;
r = c ? s : r;

// Check for NaN
// c = x != x | y != y;
c = __spirv_IsNan(x) | __spirv_IsNan(y);
c = __clc_isnan(x) | __clc_isnan(y);
r = c ? as_double(QNANBITPATT_DP64) : r;

// If either is Inf, we must return Inf
Expand Down
6 changes: 4 additions & 2 deletions libclc/generic/libspirv/math/clc_ldexp.cl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

#include "tables.h"
#include <clc/clcmacro.h>
#include <clc/relational/clc_isinf.h>
#include <clc/relational/clc_isnan.h>
#include <config.h>
#include <math/math.h>

Expand Down Expand Up @@ -92,7 +94,7 @@ _CLC_DEF _CLC_OVERLOAD float __clc_ldexp(float x, int n) {
val_ui = dexp == 0 ? dval_ui : val_ui;
val_f = as_float(val_ui);

val_f = __spirv_IsNan(x) || __spirv_IsInf(x) || val_x == 0 ? x : val_f;
val_f = __clc_isnan(x) || __clc_isinf(x) || val_x == 0 ? x : val_f;
return val_f;
}

Expand Down Expand Up @@ -125,7 +127,7 @@ _CLC_DEF _CLC_OVERLOAD double __clc_ldexp(double x, int n) {
mr = v == 0x7ff ? as_double(s | PINFBITPATT_DP64) : mr;
mr = v < -53 ? as_double(s) : mr;

mr = ((n == 0) | __spirv_IsInf(x) | (x == 0)) ? x : mr;
mr = ((n == 0) | __clc_isinf(x) | (x == 0)) ? x : mr;
return mr;
}

Expand Down
Loading

0 comments on commit 7923d30

Please sign in to comment.