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>

0 commit comments

Comments
 (0)