[Libclc-dev] [PATCH 2/2] Add some missing convert_* functions
Tom Stellard
tom at stellard.net
Thu Aug 1 19:22:40 PDT 2013
From: Tom Stellard <thomas.stellard at amd.com>
---
generic/include/clc/convert.h | 31 +--------------------------
generic/lib/convert.cl | 49 +++++++++++++++++++++++++++++++++----------
2 files changed, 39 insertions(+), 41 deletions(-)
diff --git a/generic/include/clc/convert.h b/generic/include/clc/convert.h
index a7ae94a..7c4e5c5 100644
--- a/generic/include/clc/convert.h
+++ b/generic/include/clc/convert.h
@@ -1,37 +1,8 @@
#define _CLC_CONVERT_DECL(FROM_TYPE, TO_TYPE, SUFFIX) \
_CLC_OVERLOAD _CLC_DECL TO_TYPE convert_##TO_TYPE##SUFFIX(FROM_TYPE x);
-_CLC_CONVERT_DECL(long, char, )
-_CLC_CONVERT_DECL(ulong, uchar, )
-_CLC_CONVERT_DECL(long, short, )
-_CLC_CONVERT_DECL(ulong, ushort, )
-_CLC_CONVERT_DECL(long, int, )
-_CLC_CONVERT_DECL(ulong, uint, )
-_CLC_CONVERT_DECL(long, long, )
-_CLC_CONVERT_DECL(ulong, ulong, )
-#ifdef cl_khr_fp64
-_CLC_CONVERT_DECL(double, float, )
-_CLC_CONVERT_DECL(double, double, )
-#else
-_CLC_CONVERT_DECL(float, float, )
-#endif
-
-_CLC_CONVERT_DECL(long, char, _sat)
-_CLC_CONVERT_DECL(ulong, uchar, _sat)
-_CLC_CONVERT_DECL(long, short, _sat)
-_CLC_CONVERT_DECL(ulong, ushort, _sat)
-_CLC_CONVERT_DECL(long, int, _sat)
-_CLC_CONVERT_DECL(ulong, uint, _sat)
-_CLC_CONVERT_DECL(long, long, _sat)
-_CLC_CONVERT_DECL(ulong, ulong, _sat)
-#ifdef cl_khr_fp64
-_CLC_CONVERT_DECL(double, float, _sat)
-_CLC_CONVERT_DECL(double, double, _sat)
-#else
-_CLC_CONVERT_DECL(float, float, _sat)
-#endif
-
#define _CLC_VECTOR_CONVERT_DECL(FROM_TYPE, TO_TYPE, SUFFIX) \
+ _CLC_CONVERT_DECL(FROM_TYPE, TO_TYPE, SUFFIX) \
_CLC_CONVERT_DECL(FROM_TYPE##2, TO_TYPE##2, SUFFIX) \
_CLC_CONVERT_DECL(FROM_TYPE##3, TO_TYPE##3, SUFFIX) \
_CLC_CONVERT_DECL(FROM_TYPE##4, TO_TYPE##4, SUFFIX) \
diff --git a/generic/lib/convert.cl b/generic/lib/convert.cl
index d5a6f31..c2ac9be 100644
--- a/generic/lib/convert.cl
+++ b/generic/lib/convert.cl
@@ -30,21 +30,48 @@
return (TO_TYPE##16)(convert_##TO_TYPE##8##SUFFIX(x.lo), convert_##TO_TYPE##8##SUFFIX(x.hi)); \
}
-CONVERT_ID(long, char, )
-CONVERT_ID(ulong, uchar, )
-CONVERT_ID(long, short, )
-CONVERT_ID(ulong, ushort, )
-CONVERT_ID(long, int, )
-CONVERT_ID(ulong, uint, )
-CONVERT_ID(long, long, )
-CONVERT_ID(ulong, ulong, )
+#define CONVERT_ID_FROM1(FROM_TYPE) \
+ CONVERT_ID(FROM_TYPE, char, ) \
+ CONVERT_ID(FROM_TYPE, uchar, ) \
+ CONVERT_ID(FROM_TYPE, int, ) \
+ CONVERT_ID(FROM_TYPE, uint, ) \
+ CONVERT_ID(FROM_TYPE, short, ) \
+ CONVERT_ID(FROM_TYPE, ushort, ) \
+ CONVERT_ID(FROM_TYPE, long, ) \
+ CONVERT_ID(FROM_TYPE, ulong, ) \
+ CONVERT_ID(FROM_TYPE, float, )
+
#ifdef cl_khr_fp64
-CONVERT_ID(double, float, )
-CONVERT_ID(double, double, )
+#define CONVERT_ID_FROM(FROM_TYPE) \
+ CONVERT_ID_FROM1(FROM_TYPE) \
+ CONVERT_ID(FROM_TYPE, double, )
#else
-CONVERT_ID(float, float, )
+#define CONVERT_ID_FROM(FROM_TYPE) \
+ CONVERT_ID_FROM1(FROM_TYPE)
#endif
+#define CONVERT_ID_TO1()
+ CONVERT_ID_FROM(char)
+ CONVERT_ID_FROM(uchar)
+ CONVERT_ID_FROM(int)
+ CONVERT_ID_FROM(uint)
+ CONVERT_ID_FROM(short)
+ CONVERT_ID_FROM(ushort)
+ CONVERT_ID_FROM(long)
+ CONVERT_ID_FROM(ulong)
+ CONVERT_ID_FROM(float)
+
+#ifdef cl_khr_fp64
+#define CONVERT_ID_TO() \
+ CONVERT_ID_TO1() \
+ CONVERT_ID_FROM(double)
+#else
+#define CONVERT_ID_TO() \
+ CONVERT_ID_TO1()
+#endif
+
+CONVERT_ID_TO()
+
_CLC_OVERLOAD _CLC_DEF char convert_char_sat(long l) {
return l > 127 ? 127 : l < -128 ? -128 : l;
}
--
1.7.11.4
More information about the Libclc-dev
mailing list