[Libclc-dev] [PATCH 1/3] integer/clz: Use clang builtin instead of llvm asm
Jan Vesely via Libclc-dev
libclc-dev at lists.llvm.org
Sun Oct 1 14:13:34 PDT 2017
The generated llvm IR mostly identical. char/uchar case is a bit worse.
Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
---
CTS integer_clz still passes
generic/lib/SOURCES | 2 --
generic/lib/integer/clz.cl | 26 ++++++-------------
generic/lib/integer/clz_if.ll | 55 -----------------------------------------
generic/lib/integer/clz_impl.ll | 44 ---------------------------------
4 files changed, 8 insertions(+), 119 deletions(-)
delete mode 100644 generic/lib/integer/clz_if.ll
delete mode 100644 generic/lib/integer/clz_impl.ll
diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES
index f919bc7..aa7f4aa 100644
--- a/generic/lib/SOURCES
+++ b/generic/lib/SOURCES
@@ -67,8 +67,6 @@ integer/add_sat.cl
integer/add_sat_if.ll
integer/add_sat_impl.ll
integer/clz.cl
-integer/clz_if.ll
-integer/clz_impl.ll
integer/hadd.cl
integer/mad24.cl
integer/mad_sat.cl
diff --git a/generic/lib/integer/clz.cl b/generic/lib/integer/clz.cl
index 17e3fe0..e2080b5 100644
--- a/generic/lib/integer/clz.cl
+++ b/generic/lib/integer/clz.cl
@@ -1,46 +1,36 @@
#include <clc/clc.h>
#include "../clcmacro.h"
-// From clz.ll
-_CLC_DECL char __clc_clz_s8(char);
-_CLC_DECL uchar __clc_clz_u8(uchar);
-_CLC_DECL short __clc_clz_s16(short);
-_CLC_DECL ushort __clc_clz_u16(ushort);
-_CLC_DECL int __clc_clz_s32(int);
-_CLC_DECL uint __clc_clz_u32(uint);
-_CLC_DECL long __clc_clz_s64(long);
-_CLC_DECL ulong __clc_clz_u64(ulong);
-
_CLC_OVERLOAD _CLC_DEF char clz(char x) {
- return __clc_clz_s8(x);
+ return clz((ushort)(uchar)x) - 8;
}
_CLC_OVERLOAD _CLC_DEF uchar clz(uchar x) {
- return __clc_clz_u8(x);
+ return clz((ushort)x) - 8;
}
_CLC_OVERLOAD _CLC_DEF short clz(short x) {
- return __clc_clz_s16(x);
+ return x ? __builtin_clzs(x) : 16;
}
_CLC_OVERLOAD _CLC_DEF ushort clz(ushort x) {
- return __clc_clz_u16(x);
+ return x ? __builtin_clzs(x) : 16;
}
_CLC_OVERLOAD _CLC_DEF int clz(int x) {
- return __clc_clz_s32(x);
+ return x ? __builtin_clz(x) : 32;
}
_CLC_OVERLOAD _CLC_DEF uint clz(uint x) {
- return __clc_clz_u32(x);
+ return x ? __builtin_clz(x) : 32;
}
_CLC_OVERLOAD _CLC_DEF long clz(long x) {
- return __clc_clz_s64(x);
+ return x ? __builtin_clzl(x) : 64;
}
_CLC_OVERLOAD _CLC_DEF ulong clz(ulong x) {
- return __clc_clz_u64(x);
+ return x ? __builtin_clzl(x) : 64;
}
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, char, clz, char)
diff --git a/generic/lib/integer/clz_if.ll b/generic/lib/integer/clz_if.ll
deleted file mode 100644
index 23dfc74..0000000
--- a/generic/lib/integer/clz_if.ll
+++ /dev/null
@@ -1,55 +0,0 @@
-declare i8 @__clc_clz_impl_s8(i8 %x)
-
-define i8 @__clc_clz_s8(i8 %x) nounwind readnone alwaysinline {
- %call = call i8 @__clc_clz_impl_s8(i8 %x)
- ret i8 %call
-}
-
-declare i8 @__clc_clz_impl_u8(i8 %x)
-
-define i8 @__clc_clz_u8(i8 %x) nounwind readnone alwaysinline {
- %call = call i8 @__clc_clz_impl_u8(i8 %x)
- ret i8 %call
-}
-
-declare i16 @__clc_clz_impl_s16(i16 %x)
-
-define i16 @__clc_clz_s16(i16 %x) nounwind readnone alwaysinline {
- %call = call i16 @__clc_clz_impl_s16(i16 %x)
- ret i16 %call
-}
-
-declare i16 @__clc_clz_impl_u16(i16 %x)
-
-define i16 @__clc_clz_u16(i16 %x) nounwind readnone alwaysinline {
- %call = call i16 @__clc_clz_impl_u16(i16 %x)
- ret i16 %call
-}
-
-declare i32 @__clc_clz_impl_s32(i32 %x)
-
-define i32 @__clc_clz_s32(i32 %x) nounwind readnone alwaysinline {
- %call = call i32 @__clc_clz_impl_s32(i32 %x)
- ret i32 %call
-}
-
-declare i32 @__clc_clz_impl_u32(i32 %x)
-
-define i32 @__clc_clz_u32(i32 %x) nounwind readnone alwaysinline {
- %call = call i32 @__clc_clz_impl_u32(i32 %x)
- ret i32 %call
-}
-
-declare i64 @__clc_clz_impl_s64(i64 %x)
-
-define i64 @__clc_clz_s64(i64 %x) nounwind readnone alwaysinline {
- %call = call i64 @__clc_clz_impl_s64(i64 %x)
- ret i64 %call
-}
-
-declare i64 @__clc_clz_impl_u64(i64 %x)
-
-define i64 @__clc_clz_u64(i64 %x) nounwind readnone alwaysinline {
- %call = call i64 @__clc_clz_impl_u64(i64 %x)
- ret i64 %call
-}
diff --git a/generic/lib/integer/clz_impl.ll b/generic/lib/integer/clz_impl.ll
deleted file mode 100644
index b5c3d98..0000000
--- a/generic/lib/integer/clz_impl.ll
+++ /dev/null
@@ -1,44 +0,0 @@
-declare i8 @llvm.ctlz.i8(i8, i1)
-declare i16 @llvm.ctlz.i16(i16, i1)
-declare i32 @llvm.ctlz.i32(i32, i1)
-declare i64 @llvm.ctlz.i64(i64, i1)
-
-define i8 @__clc_clz_impl_s8(i8 %x) nounwind readnone alwaysinline {
- %call = call i8 @llvm.ctlz.i8(i8 %x, i1 0)
- ret i8 %call
-}
-
-define i8 @__clc_clz_impl_u8(i8 %x) nounwind readnone alwaysinline {
- %call = call i8 @llvm.ctlz.i8(i8 %x, i1 0)
- ret i8 %call
-}
-
-define i16 @__clc_clz_impl_s16(i16 %x) nounwind readnone alwaysinline {
- %call = call i16 @llvm.ctlz.i16(i16 %x, i1 0)
- ret i16 %call
-}
-
-define i16 @__clc_clz_impl_u16(i16 %x) nounwind readnone alwaysinline {
- %call = call i16 @llvm.ctlz.i16(i16 %x, i1 0)
- ret i16 %call
-}
-
-define i32 @__clc_clz_impl_s32(i32 %x) nounwind readnone alwaysinline {
- %call = call i32 @llvm.ctlz.i32(i32 %x, i1 0)
- ret i32 %call
-}
-
-define i32 @__clc_clz_impl_u32(i32 %x) nounwind readnone alwaysinline {
- %call = call i32 @llvm.ctlz.i32(i32 %x, i1 0)
- ret i32 %call
-}
-
-define i64 @__clc_clz_impl_s64(i64 %x) nounwind readnone alwaysinline {
- %call = call i64 @llvm.ctlz.i64(i64 %x, i1 0)
- ret i64 %call
-}
-
-define i64 @__clc_clz_impl_u64(i64 %x) nounwind readnone alwaysinline {
- %call = call i64 @llvm.ctlz.i64(i64 %x, i1 0)
- ret i64 %call
-}
--
2.13.6
More information about the Libclc-dev
mailing list