Skip to content

Commit 11497c9

Browse files
wenju-hevarun-r-mallya
authored andcommitted
[libclc] Implement integer __clc_abs using __builtin_elementwise_abs (#164957)
Previous implementation was cmp, select and @llvm.smax sequence in LLVM IR. __CLC_GEN_U/__CLC_GEN_S is upstreamed from intel/llvm repo.
1 parent c13b49b commit 11497c9

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

libclc/clc/include/clc/integer/gentype.inc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
// to keep this file manageable.
2424
#define __CLC_GENSIZE 8
2525
#define __CLC_SCALAR_GENTYPE char
26+
#define __CLC_GEN_S
2627

2728
#define __CLC_GENTYPE char
2829
#define __CLC_U_GENTYPE uchar
@@ -93,6 +94,8 @@
9394

9495
#undef __CLC_SCALAR_GENTYPE
9596
#define __CLC_SCALAR_GENTYPE uchar
97+
#undef __CLC_GEN_S
98+
#define __CLC_GEN_U
9699

97100
#define __CLC_GENTYPE uchar
98101
#define __CLC_U_GENTYPE uchar
@@ -165,6 +168,8 @@
165168
#define __CLC_GENSIZE 16
166169
#undef __CLC_SCALAR_GENTYPE
167170
#define __CLC_SCALAR_GENTYPE short
171+
#undef __CLC_GEN_U
172+
#define __CLC_GEN_S
168173

169174
#define __CLC_GENTYPE short
170175
#define __CLC_U_GENTYPE ushort
@@ -235,6 +240,8 @@
235240

236241
#undef __CLC_SCALAR_GENTYPE
237242
#define __CLC_SCALAR_GENTYPE ushort
243+
#undef __CLC_GEN_S
244+
#define __CLC_GEN_U
238245

239246
#define __CLC_GENTYPE ushort
240247
#define __CLC_U_GENTYPE ushort
@@ -307,6 +314,8 @@
307314
#define __CLC_GENSIZE 32
308315
#undef __CLC_SCALAR_GENTYPE
309316
#define __CLC_SCALAR_GENTYPE int
317+
#undef __CLC_GEN_U
318+
#define __CLC_GEN_S
310319

311320
#define __CLC_GENTYPE int
312321
#define __CLC_U_GENTYPE uint
@@ -377,6 +386,8 @@
377386

378387
#undef __CLC_SCALAR_GENTYPE
379388
#define __CLC_SCALAR_GENTYPE uint
389+
#undef __CLC_GEN_S
390+
#define __CLC_GEN_U
380391

381392
#define __CLC_GENTYPE uint
382393
#define __CLC_U_GENTYPE uint
@@ -449,6 +460,8 @@
449460
#define __CLC_GENSIZE 64
450461
#undef __CLC_SCALAR_GENTYPE
451462
#define __CLC_SCALAR_GENTYPE long
463+
#undef __CLC_GEN_U
464+
#define __CLC_GEN_S
452465

453466
#define __CLC_GENTYPE long
454467
#define __CLC_U_GENTYPE ulong
@@ -519,6 +532,8 @@
519532

520533
#undef __CLC_SCALAR_GENTYPE
521534
#define __CLC_SCALAR_GENTYPE ulong
535+
#undef __CLC_GEN_S
536+
#define __CLC_GEN_U
522537

523538
#define __CLC_GENTYPE ulong
524539
#define __CLC_U_GENTYPE ulong
@@ -588,6 +603,8 @@
588603
#undef __CLC_S_GENTYPE
589604
#undef __CLC_VECSIZE_OR_1
590605

606+
#undef __CLC_GEN_U
607+
591608
#undef __CLC_GENSIZE
592609
#undef __CLC_SCALAR_GENTYPE
593610
#undef __CLC_BODY

libclc/clc/lib/generic/integer/clc_abs.inc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#ifdef __CLC_GEN_S
10+
911
_CLC_OVERLOAD _CLC_DEF __CLC_U_GENTYPE __clc_abs(__CLC_GENTYPE x) {
10-
return __builtin_astype((__CLC_GENTYPE)(x > (__CLC_GENTYPE)(0) ? x : -x),
11-
__CLC_U_GENTYPE);
12+
return __builtin_astype(__builtin_elementwise_abs(x), __CLC_U_GENTYPE);
1213
}
14+
15+
#else
16+
17+
_CLC_OVERLOAD _CLC_DEF __CLC_U_GENTYPE __clc_abs(__CLC_GENTYPE x) { return x; }
18+
19+
#endif

0 commit comments

Comments
 (0)