From 9d10fedb2ad3c049bfbb29202aeb36b890999d14 Mon Sep 17 00:00:00 2001 From: Homer Hsing Date: Wed, 4 Sep 2013 10:33:39 +0800 Subject: [PATCH] fix 64-bit "clz" if parameter is "long4" or "ulong4" Signed-off-by: Homer Hsing Reviewed-by: Zhigang Gong --- backend/src/ocl_stdlib.tmpl.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/src/ocl_stdlib.tmpl.h b/backend/src/ocl_stdlib.tmpl.h index 8e8c042..939d5be 100644 --- a/backend/src/ocl_stdlib.tmpl.h +++ b/backend/src/ocl_stdlib.tmpl.h @@ -318,12 +318,12 @@ INLINE_OVERLOADABLE uint clz(uint x) { } INLINE_OVERLOADABLE long clz(long x) { - if (x < 0) - return 0; - if (x == 0) - return 64; union { int i[2]; long x; } u; u.x = x; + if (u.i[1] & 0x80000000u) + return 0; + if (u.i[1] == 0 && u.i[0] == 0) + return 64; uint v = clz(u.i[1]); if(v == 32) v += clz(u.i[0]); -- 2.7.4