From a83875a08c2481cdd2150db657c5d8002a0e7c91 Mon Sep 17 00:00:00 2001 From: Homer Hsing Date: Mon, 2 Sep 2013 16:33:23 +0800 Subject: [PATCH] add 64-bit version of "clz" this patch passes following piglit test cases: piglit/framework/../bin/cl-program-tester generated_tests/cl/builtin/int/builtin-ulong-clz-1.0.generated.cl piglit/framework/../bin/cl-program-tester generated_tests/cl/builtin/int/builtin-long-clz-1.0.generated.cl Signed-off-by: Homer Hsing Reviewed-by: Zhigang Gong --- backend/src/ocl_stdlib.tmpl.h | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/backend/src/ocl_stdlib.tmpl.h b/backend/src/ocl_stdlib.tmpl.h index 247902c..3e903ed 100644 --- a/backend/src/ocl_stdlib.tmpl.h +++ b/backend/src/ocl_stdlib.tmpl.h @@ -313,11 +313,27 @@ INLINE_OVERLOADABLE uint clz(uint x) { } INLINE_OVERLOADABLE long clz(long x) { - return 0; + if (x < 0) + return 0; + if (x == 0) + return 64; + union { int i[2]; long x; } u; + u.x = x; + uint v = clz(u.i[1]); + if(v == 32) + v += clz(u.i[0]); + return v; } INLINE_OVERLOADABLE ulong clz(ulong x) { - return 0; + if (x == 0) + return 64; + union { uint i[2]; ulong x; } u; + u.x = x; + uint v = clz(u.i[1]); + if(v == 32) + v += clz(u.i[0]); + return v; } OVERLOADABLE int __gen_ocl_mul_hi(int x, int y); -- 2.7.4