GBE: Support builtin vector functions for select() autogeneration.
authorZhigang Gong <zhigang.gong@linux.intel.com>
Tue, 3 Sep 2013 06:30:46 +0000 (14:30 +0800)
committerZhigang Gong <zhigang.gong@linux.intel.com>
Tue, 3 Sep 2013 08:16:50 +0000 (16:16 +0800)
Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
Reviewed-by: Homer Hsing <homer.xing@intel.com>
backend/src/builtin_vector_proto.def
backend/src/gen_builtin_vector.py
backend/src/ocl_stdlib.tmpl.h

index 2a3daf2..37206a6 100644 (file)
@@ -253,8 +253,8 @@ int any (igentype x)
 int all (igentype x)
 # XXX need to revisit select latter
 #gentype bitselect (gentype a, gentype b, gentype c)
-#gentype select (gentype a, gentype b, igentype c)
-#gentype select (gentype a, gentype b, ugentype c)
+gentype select (gentype a, gentype b, igentype c)
+gentype select (gentype a, gentype b, ugentype c)
 
 ##misc
 #gentypen shuffle (gentypem x, ugentypen mask)
index 35e3a2a..cf023e7 100755 (executable)
@@ -311,7 +311,10 @@ class builtinProto():
                 if (isPointer(ptype)):
                     formatStr += '({} {} *)param{} + {:2d}'.format(ptype[2], ptype[0], n, j)
                 else:
-                    formatStr += 'param{}.s{:x}'.format(n, j)
+                    if (self.functionName == 'select' and n == 2):
+                        formatStr += '({})(param{}.s{:x} & (1 << (sizeof({})*8 - 1)))'.format(ptype[0], n, j, ptype[0])
+                    else:
+                        formatStr += 'param{}.s{:x}'.format(n, j)
 
             formatStr += ')'
 
index 2a20ee6..f3d2a8e 100644 (file)
@@ -1427,30 +1427,6 @@ DEF(float, int)
 DEF(float, uint)
 #undef DEF
 
-// This will be optimized out by LLVM and will output LLVM select instructions
-#define DECL_SELECT4(TYPE4, TYPE, COND_TYPE4, MASK) \
-INLINE_OVERLOADABLE TYPE4 select(TYPE4 src0, TYPE4 src1, COND_TYPE4 cond) { \
-  TYPE4 dst; \
-  const TYPE x0 = src0.x; /* Fix performance issue with CLANG */ \
-  const TYPE x1 = src1.x; \
-  const TYPE y0 = src0.y; \
-  const TYPE y1 = src1.y; \
-  const TYPE z0 = src0.z; \
-  const TYPE z1 = src1.z; \
-  const TYPE w0 = src0.w; \
-  const TYPE w1 = src1.w; \
-  dst.x = (cond.x & MASK) ? x1 : x0; \
-  dst.y = (cond.y & MASK) ? y1 : y0; \
-  dst.z = (cond.z & MASK) ? z1 : z0; \
-  dst.w = (cond.w & MASK) ? w1 : w0; \
-  return dst; \
-}
-DECL_SELECT4(int4, int, int4, 0x80000000)
-DECL_SELECT4(int4, int, uint4, 0x80000000)
-DECL_SELECT4(float4, float, int4, 0x80000000)
-DECL_SELECT4(float4, float, uint4, 0x80000000)
-#undef DECL_SELECT4
-
 /////////////////////////////////////////////////////////////////////////////
 // Common Functions (see 6.11.4 of OCL 1.1 spec)
 /////////////////////////////////////////////////////////////////////////////