Skip to content

Commit 7be30fd

Browse files
committed
[libclc] Move abs/abs_diff to CLC library
1 parent 37ce189 commit 7be30fd

File tree

15 files changed

+59
-6
lines changed

15 files changed

+59
-6
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <clc/clc.h>
2+
#include <clc/integer/clc_abs.h>
23

34
#define __CLC_BODY <abs.inc>
45
#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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <clc/clc.h>
2+
#include <clc/integer/clc_abs_diff.h>
23

34
#define __CLC_BODY <abs_diff.inc>
45
#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/lib/math/clc_fma.cl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include <clc/clc.h>
2424
#include <clc/clcmacro.h>
25+
#include <clc/integer/clc_abs.h>
2526

2627
#include "config.h"
2728
#include "math.h"
@@ -84,7 +85,7 @@ _CLC_DEF _CLC_OVERLOAD float __clc_sw_fma(float a, float b, float c) {
8485

8586
st_c.mantissa <<= C_ADJUST;
8687
ulong cutoff_bits = 0;
87-
ulong cutoff_mask = (1ul << abs(exp_diff)) - 1ul;
88+
ulong cutoff_mask = (1ul << __clc_abs(exp_diff)) - 1ul;
8889
if (exp_diff > 0) {
8990
cutoff_bits =
9091
exp_diff >= 64 ? st_c.mantissa : (st_c.mantissa & cutoff_mask);

libclc/generic/lib/math/clc_hypot.cl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include <clc/clc.h>
2424
#include <clc/clcmacro.h>
25+
#include <clc/integer/clc_abs.h>
2526
#include <clc/shared/clc_clamp.h>
2627
#include <math/clc_hypot.h>
2728

@@ -82,7 +83,7 @@ _CLC_DEF _CLC_OVERLOAD double __clc_hypot(double x, double y) {
8283

8384
// If the difference in exponents between x and y is large
8485
double s = x + y;
85-
c = abs(xexp - yexp) > MANTLENGTH_DP64 + 1;
86+
c = __clc_abs(xexp - yexp) > MANTLENGTH_DP64 + 1;
8687
r = c ? s : r;
8788

8889
// Check for NaN

0 commit comments

Comments
 (0)