[libclc] r186691 - Implement generic upsample()

Aaron Watry awatry at gmail.com
Fri Jul 19 09:44:37 PDT 2013


Author: awatry
Date: Fri Jul 19 11:44:37 2013
New Revision: 186691

URL: http://llvm.org/viewvc/llvm-project?rev=186691&view=rev
Log:
Implement generic upsample()

Reduces all vector upsamples down to its scalar components, so probably
not the most efficient thing in the world, but it does what the
spec says it needs to do.

Another possible implementation would be to convert/cast everything as
unsigned if necessary, upsample the input vectors, create the upsampled
value, and then cast back to signed if required.

Signed-off-by: Aaron Watry <awatry at gmail.com>
Reviewed-by: Tom Stellard <thomas.stellard at amd.com>

Added:
    libclc/trunk/generic/include/clc/integer/upsample.h
    libclc/trunk/generic/lib/integer/upsample.cl
Modified:
    libclc/trunk/generic/include/clc/clc.h
    libclc/trunk/generic/lib/SOURCES

Modified: libclc/trunk/generic/include/clc/clc.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/clc.h?rev=186691&r1=186690&r2=186691&view=diff
==============================================================================
--- libclc/trunk/generic/include/clc/clc.h (original)
+++ libclc/trunk/generic/include/clc/clc.h Fri Jul 19 11:44:37 2013
@@ -68,6 +68,7 @@
 #include <clc/integer/mul24.h>
 #include <clc/integer/rotate.h>
 #include <clc/integer/sub_sat.h>
+#include <clc/integer/upsample.h>
 
 /* 6.11.2 and 6.11.3 Shared Integer/Math Functions */
 #include <clc/shared/clamp.h>

Added: libclc/trunk/generic/include/clc/integer/upsample.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/integer/upsample.h?rev=186691&view=auto
==============================================================================
--- libclc/trunk/generic/include/clc/integer/upsample.h (added)
+++ libclc/trunk/generic/include/clc/integer/upsample.h Fri Jul 19 11:44:37 2013
@@ -0,0 +1,25 @@
+#define __CLC_UPSAMPLE_DECL(BGENTYPE, GENTYPE, UGENTYPE) \
+    _CLC_OVERLOAD _CLC_DECL BGENTYPE upsample(GENTYPE hi, UGENTYPE lo);
+
+#define __CLC_UPSAMPLE_VEC(BGENTYPE, GENTYPE, UGENTYPE) \
+    __CLC_UPSAMPLE_DECL(BGENTYPE, GENTYPE, UGENTYPE); \
+    __CLC_UPSAMPLE_DECL(BGENTYPE##2, GENTYPE##2, UGENTYPE##2); \
+    __CLC_UPSAMPLE_DECL(BGENTYPE##3, GENTYPE##3, UGENTYPE##3); \
+    __CLC_UPSAMPLE_DECL(BGENTYPE##4, GENTYPE##4, UGENTYPE##4); \
+    __CLC_UPSAMPLE_DECL(BGENTYPE##8, GENTYPE##8, UGENTYPE##8); \
+    __CLC_UPSAMPLE_DECL(BGENTYPE##16, GENTYPE##16, UGENTYPE##16); \
+
+#define __CLC_UPSAMPLE_TYPES() \
+    __CLC_UPSAMPLE_VEC(short, char, uchar) \
+    __CLC_UPSAMPLE_VEC(ushort, uchar, uchar) \
+    __CLC_UPSAMPLE_VEC(int, short, ushort) \
+    __CLC_UPSAMPLE_VEC(uint, ushort, ushort) \
+    __CLC_UPSAMPLE_VEC(long, int, uint) \
+    __CLC_UPSAMPLE_VEC(ulong, uint, uint) \
+
+__CLC_UPSAMPLE_TYPES()
+
+#undef __CLC_UPSAMPLE_TYPES
+#undef __CLC_UPSAMPLE_DECL
+#undef __CLC_UPSAMPLE_VEC
+

Modified: libclc/trunk/generic/lib/SOURCES
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=186691&r1=186690&r2=186691&view=diff
==============================================================================
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Fri Jul 19 11:44:37 2013
@@ -17,6 +17,7 @@ integer/rotate.cl
 integer/sub_sat.cl
 integer/sub_sat_if.ll
 integer/sub_sat_impl.ll
+integer/upsample.cl
 math/fmax.cl
 math/fmin.cl
 math/hypot.cl

Added: libclc/trunk/generic/lib/integer/upsample.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/integer/upsample.cl?rev=186691&view=auto
==============================================================================
--- libclc/trunk/generic/lib/integer/upsample.cl (added)
+++ libclc/trunk/generic/lib/integer/upsample.cl Fri Jul 19 11:44:37 2013
@@ -0,0 +1,34 @@
+#include <clc/clc.h>
+
+#define __CLC_UPSAMPLE_IMPL(BGENTYPE, GENTYPE, UGENTYPE, GENSIZE) \
+    _CLC_OVERLOAD _CLC_DECL BGENTYPE upsample(GENTYPE hi, UGENTYPE lo){ \
+        return ((BGENTYPE)hi << GENSIZE) | lo; \
+    } \
+    _CLC_OVERLOAD _CLC_DECL BGENTYPE##2 upsample(GENTYPE##2 hi, UGENTYPE##2 lo){ \
+        return (BGENTYPE##2){upsample(hi.s0, lo.s0), upsample(hi.s1, lo.s1)}; \
+    } \
+    _CLC_OVERLOAD _CLC_DECL BGENTYPE##3 upsample(GENTYPE##3 hi, UGENTYPE##3 lo){ \
+        return (BGENTYPE##3){upsample(hi.s0, lo.s0), upsample(hi.s1, lo.s1), upsample(hi.s2, lo.s2)}; \
+    } \
+    _CLC_OVERLOAD _CLC_DECL BGENTYPE##4 upsample(GENTYPE##4 hi, UGENTYPE##4 lo){ \
+        return (BGENTYPE##4){upsample(hi.lo, lo.lo), upsample(hi.hi, lo.hi)}; \
+    } \
+    _CLC_OVERLOAD _CLC_DECL BGENTYPE##8 upsample(GENTYPE##8 hi, UGENTYPE##8 lo){ \
+        return (BGENTYPE##8){upsample(hi.lo, lo.lo), upsample(hi.hi, lo.hi)}; \
+    } \
+    _CLC_OVERLOAD _CLC_DECL BGENTYPE##16 upsample(GENTYPE##16 hi, UGENTYPE##16 lo){ \
+        return (BGENTYPE##16){upsample(hi.lo, lo.lo), upsample(hi.hi, lo.hi)}; \
+    } \
+
+#define __CLC_UPSAMPLE_TYPES() \
+    __CLC_UPSAMPLE_IMPL(short, char, uchar, 8) \
+    __CLC_UPSAMPLE_IMPL(ushort, uchar, uchar, 8) \
+    __CLC_UPSAMPLE_IMPL(int, short, ushort, 16) \
+    __CLC_UPSAMPLE_IMPL(uint, ushort, ushort, 16) \
+    __CLC_UPSAMPLE_IMPL(long, int, uint, 32) \
+    __CLC_UPSAMPLE_IMPL(ulong, uint, uint, 32) \
+
+__CLC_UPSAMPLE_TYPES()
+
+#undef __CLC_UPSAMPLE_TYPES
+#undef __CLC_UPSAMPLE_IMPL





More information about the cfe-commits mailing list