[Mesa-dev] [PATCH] libclc: Implement clz() builtin

Tom Stellard tom at stellard.net
Tue Apr 16 09:24:37 PDT 2013


On Mon, Apr 15, 2013 at 07:20:31PM -0500, Aaron Watry wrote:

Reviewed-by: Tom Stellard <thomas.stellard at amd.com>
> Squashed commit of the following:
> 
> commit a0df0a0e86c55c1bdc0b9c0f5a739e5adef4b056
> Author: Aaron Watry <awatry at gmail.com>
> Date:   Mon Apr 15 18:42:04 2013 -0500
> 
>     libclc: Rename clz.ll to clz_if.ll to ensure it gets built.
> 
>     configure.py treats files that have the same name with the .cl and .ll
>     extensions as overriding eachother.
> 
>     E.g. If you have clz.cl and clz.ll both specified to be built in the same
>     SOURCES file, only the first file listed will actually be built.
> 
>     Since the contents of clz.ll were an interface that is implemented in
>     clz_impl.ll, rename clz.ll to clz_if.ll to make sure that the interface is
>     built.
> 
> commit 931b62bed05c58f737de625bd415af09571a6a5a
> Author: Aaron Watry <awatry at gmail.com>
> Date:   Sat Apr 13 12:32:54 2013 -0500
> 
>     libclc: llvm assembly implementation of clz
> 
>     Untested... currently crashes in the same manner as add_sat.
> 
> commit 6ef0b7b0b6d2e5584086b4b9a9243743b2e0538f
> Author: Aaron Watry <awatry at gmail.com>
> Date:   Sat Mar 23 12:35:27 2013 -0500
> 
>     libclc: Add stub clz builtin
> 
>     For scalar int/uint, attempt to use the clz llvm builtin.. for all others
>     return 0 until an actual implementation is finished.
> ---
>  generic/include/clc/clc.h           |    1 +
>  generic/include/clc/integer/clz.h   |    2 ++
>  generic/include/clc/integer/clz.inc |    1 +
>  generic/lib/SOURCES                 |    3 ++
>  generic/lib/integer/clz.cl          |   52 +++++++++++++++++++++++++++++++++
>  generic/lib/integer/clz_if.ll       |   55 +++++++++++++++++++++++++++++++++++
>  generic/lib/integer/clz_impl.ll     |   44 ++++++++++++++++++++++++++++
>  7 files changed, 158 insertions(+)
>  create mode 100644 generic/include/clc/integer/clz.h
>  create mode 100644 generic/include/clc/integer/clz.inc
>  create mode 100644 generic/lib/integer/clz.cl
>  create mode 100644 generic/lib/integer/clz_if.ll
>  create mode 100644 generic/lib/integer/clz_impl.ll
> 
> diff --git a/generic/include/clc/clc.h b/generic/include/clc/clc.h
> index 72f518a..0d7f105 100644
> --- a/generic/include/clc/clc.h
> +++ b/generic/include/clc/clc.h
> @@ -63,6 +63,7 @@
>  #include <clc/integer/abs.h>
>  #include <clc/integer/abs_diff.h>
>  #include <clc/integer/add_sat.h>
> +#include <clc/integer/clz.h>
>  #include <clc/integer/rotate.h>
>  #include <clc/integer/sub_sat.h>
>  
> diff --git a/generic/include/clc/integer/clz.h b/generic/include/clc/integer/clz.h
> new file mode 100644
> index 0000000..5708eb4
> --- /dev/null
> +++ b/generic/include/clc/integer/clz.h
> @@ -0,0 +1,2 @@
> +#define BODY <clc/integer/clz.inc>
> +#include <clc/integer/gentype.inc>
> diff --git a/generic/include/clc/integer/clz.inc b/generic/include/clc/integer/clz.inc
> new file mode 100644
> index 0000000..ac73a31
> --- /dev/null
> +++ b/generic/include/clc/integer/clz.inc
> @@ -0,0 +1 @@
> +_CLC_OVERLOAD _CLC_DECL GENTYPE clz(GENTYPE x);
> diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES
> index 495b3e7..b04d3b8 100644
> --- a/generic/lib/SOURCES
> +++ b/generic/lib/SOURCES
> @@ -8,6 +8,9 @@ integer/abs_diff.cl
>  integer/add_sat.cl
>  integer/add_sat.ll
>  integer/add_sat_impl.ll
> +integer/clz.cl
> +integer/clz_if.ll
> +integer/clz_impl.ll
>  integer/rotate.cl
>  integer/sub_sat.cl
>  integer/sub_sat.ll
> diff --git a/generic/lib/integer/clz.cl b/generic/lib/integer/clz.cl
> new file mode 100644
> index 0000000..83ef2dd
> --- /dev/null
> +++ b/generic/lib/integer/clz.cl
> @@ -0,0 +1,52 @@
> +#include <clc/clc.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);
> +}
> +
> +_CLC_OVERLOAD _CLC_DEF uchar clz(uchar x) {
> +  return __clc_clz_u8(x);
> +}
> +
> +_CLC_OVERLOAD _CLC_DEF short clz(short x) {
> +  return __clc_clz_s16(x);
> +}
> +
> +_CLC_OVERLOAD _CLC_DEF ushort clz(ushort x) {
> +  return __clc_clz_u16(x);
> +}
> +
> +_CLC_OVERLOAD _CLC_DEF int clz(int x) {
> +  return __clc_clz_s32(x);
> +}
> +
> +_CLC_OVERLOAD _CLC_DEF uint clz(uint x) {
> +  return __clc_clz_u32(x);
> +}
> +
> +_CLC_OVERLOAD _CLC_DEF long clz(long x) {
> +  return __clc_clz_s64(x);
> +}
> +
> +_CLC_OVERLOAD _CLC_DEF ulong clz(ulong x) {
> +  return __clc_clz_u64(x);
> +}
> +
> +_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, char, clz, char)
> +_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, uchar, clz, uchar)
> +_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, short, clz, short)
> +_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, ushort, clz, ushort)
> +_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, int, clz, int)
> +_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, uint, clz, uint)
> +_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, long, clz, long)
> +_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, ulong, clz, ulong)
> diff --git a/generic/lib/integer/clz_if.ll b/generic/lib/integer/clz_if.ll
> new file mode 100644
> index 0000000..23dfc74
> --- /dev/null
> +++ b/generic/lib/integer/clz_if.ll
> @@ -0,0 +1,55 @@
> +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
> new file mode 100644
> index 0000000..b5c3d98
> --- /dev/null
> +++ b/generic/lib/integer/clz_impl.ll
> @@ -0,0 +1,44 @@
> +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
> +}
> -- 
> 1.7.10.4
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list