Skip to content

Commit 4e20b3e

Browse files
committed
[libclc] Move abs/abs_diff to CLC library
1 parent d7b2605 commit 4e20b3e

File tree

22 files changed

+63
-64
lines changed

22 files changed

+63
-64
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef __CLC_INTEGER_CLC_ABS_H__
2+
#define __CLC_INTEGER_CLC_ABS_H__
3+
4+
#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
5+
// clspv and spir-v targets provide their own OpenCL-compatible abs
6+
#define __clc_abs abs
7+
#else
8+
9+
#define __CLC_BODY <clc/integer/clc_abs.inc>
10+
#include <clc/integer/gentype.inc>
11+
12+
#endif
13+
14+
#endif // __CLC_INTEGER_CLC_ABS_H__
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_CLC_OVERLOAD _CLC_DECL __CLC_U_GENTYPE __clc_abs(__CLC_GENTYPE x);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef __CLC_INTEGER_CLC_ABS_DIFF_H__
2+
#define __CLC_INTEGER_CLC_ABS_DIFF_H__
3+
4+
#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
5+
// clspv and spir-v targets provide their own OpenCL-compatible abs_diff
6+
#define __clc_abs_diff abs_diff
7+
#else
8+
9+
#define __CLC_BODY <clc/integer/clc_abs_diff.inc>
10+
#include <clc/integer/gentype.inc>
11+
12+
#endif
13+
14+
#endif // __CLC_INTEGER_CLC_ABS_DIFF_H__
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
_CLC_OVERLOAD _CLC_DECL __CLC_U_GENTYPE __clc_abs_diff(__CLC_GENTYPE x,
2+
__CLC_GENTYPE y);

libclc/clc/lib/generic/SOURCES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
geometric/clc_dot.cl
2+
integer/clc_abs.cl
3+
integer/clc_abs_diff.cl
24
shared/clc_clamp.cl
35
shared/clc_max.cl
46
shared/clc_min.cl
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include <clc/internal/clc.h>
2+
3+
#define __CLC_BODY <clc_abs.inc>
4+
#include <clc/integer/gentype.inc>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
_CLC_OVERLOAD _CLC_DEF __CLC_U_GENTYPE __clc_abs(__CLC_GENTYPE x) {
2+
return __builtin_astype((__CLC_GENTYPE)(x > (__CLC_GENTYPE)(0) ? x : -x),
3+
__CLC_U_GENTYPE);
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include <clc/internal/clc.h>
2+
3+
#define __CLC_BODY <clc_abs_diff.inc>
4+
#include <clc/integer/gentype.inc>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
_CLC_OVERLOAD _CLC_DEF __CLC_U_GENTYPE __clc_abs_diff(__CLC_GENTYPE x,
2+
__CLC_GENTYPE y) {
3+
__CLC_U_GENTYPE ux = __builtin_astype(x, __CLC_U_GENTYPE);
4+
__CLC_U_GENTYPE uy = __builtin_astype(y, __CLC_U_GENTYPE);
5+
return x > y ? ux - uy : uy - ux;
6+
}

libclc/generic/lib/integer/abs.cl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include <clc/clc.h>
2-
#include <core/clc_core.h>
3-
#include <spirv/spirv.h>
2+
#include <clc/integer/clc_abs.h>
43

54
#define __CLC_BODY <abs.inc>
65
#include <clc/integer/gentype.inc>

libclc/generic/lib/integer/abs.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
_CLC_OVERLOAD _CLC_DEF __CLC_U_GENTYPE abs(__CLC_GENTYPE x) {
2-
return __builtin_astype((__CLC_GENTYPE)(x > (__CLC_GENTYPE)(0) ? x : -x), __CLC_U_GENTYPE);
2+
return __clc_abs(x);
33
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include <clc/clc.h>
2-
#include <core/clc_core.h>
3-
#include <spirv/spirv.h>
2+
#include <clc/integer/clc_abs_diff.h>
43

54
#define __CLC_BODY <abs_diff.inc>
65
#include <clc/integer/gentype.inc>
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
_CLC_OVERLOAD _CLC_DEF __CLC_U_GENTYPE abs_diff(__CLC_GENTYPE x, __CLC_GENTYPE y) {
2-
__CLC_U_GENTYPE ux = __builtin_astype(x, __CLC_U_GENTYPE);
3-
__CLC_U_GENTYPE uy = __builtin_astype(y, __CLC_U_GENTYPE);
4-
return x > y ? ux - uy : uy - ux;
2+
return __clc_abs_diff(x, y);
53
}

libclc/generic/libspirv/SOURCES

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ common/radians.cl
2727
common/sign.cl
2828
common/smoothstep.cl
2929
common/step.cl
30-
core/integer/clc_abs.cl
31-
core/integer/clc_abs_diff.cl
3230
core/integer/clc_add_sat.cl
3331
core/integer/clc_hadd.cl
3432
core/integer/clc_mad24.cl

libclc/generic/libspirv/core/integer/clc_abs.cl

Lines changed: 0 additions & 12 deletions
This file was deleted.

libclc/generic/libspirv/core/integer/clc_abs.inc

Lines changed: 0 additions & 12 deletions
This file was deleted.

libclc/generic/libspirv/core/integer/clc_abs_diff.cl

Lines changed: 0 additions & 12 deletions
This file was deleted.

libclc/generic/libspirv/core/integer/clc_abs_diff.inc

Lines changed: 0 additions & 14 deletions
This file was deleted.

libclc/generic/libspirv/integer/abs.cl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include <core/clc_core.h>
9+
#include <clc/internal/clc.h>
10+
#include <clc/integer/clc_abs.h>
1011
#include <spirv/spirv.h>
1112

1213
#define __CLC_BODY <abs.inc>

libclc/generic/libspirv/integer/abs_diff.cl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include <core/clc_core.h>
9+
#include <clc/internal/clc.h>
10+
#include <clc/integer/clc_abs_diff.h>
1011
#include <spirv/spirv.h>
1112

1213
#define __CLC_BODY <abs_diff.inc>

libclc/generic/libspirv/math/clc_fma.cl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222

2323
#include <clc/clcmacro.h>
24+
#include <clc/integer/clc_abs.h>
2425
#include <config.h>
2526
#include <core/clc_core.h>
2627
#include <math/math.h>

libclc/generic/libspirv/math/clc_hypot.cl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
#include <spirv/spirv.h>
1010

1111
#include <clc/clc.h>
12-
#include <clc/shared/clc_clamp.h>
1312
#include <clc/clcmacro.h>
13+
#include <clc/integer/clc_abs.h>
14+
#include <clc/shared/clc_clamp.h>
1415
#include <config.h>
1516
#include <math/clc_hypot.h>
1617
#include <math/math.h>
@@ -69,7 +70,7 @@ _CLC_DEF _CLC_OVERLOAD double __clc_hypot(double x, double y) {
6970

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

7576
// Check for NaN

0 commit comments

Comments
 (0)