[PATCH 1/3] Add all(igentype) builtin

Signed-off-by: Aaron Watry <awatry@gmail.com>

Signed-off-by: Aaron Watry <awatry@gmail.com>

Signed-off-by: Aaron Watry <awatry@gmail.com>

Signed-off-by: Aaron Watry <awatry@gmail.com>
---
generic/include/clc/clc.h | 1 +
generic/include/clc/relational/all.h | 16 ++++++++++++++++
generic/lib/SOURCES | 1 +
generic/lib/relational/all.cl | 30 ++++++++++++++++++++++++++++++
4 files changed, 48 insertions(+)
create mode 100644 generic/include/clc/relational/all.h
create mode 100644 generic/lib/relational/all.cl

diff --git a/generic/include/clc/clc.h b/generic/include/clc/clc.h
index 4aa9caa..0a1503a 100644
--- a/generic/include/clc/clc.h
+++ b/generic/include/clc/clc.h
@@ -102,6 +102,7 @@
#include <clc/geometric/normalize.h>

/* 6.11.6 Relational Functions */
+#include <clc/relational/all.h>
#include <clc/relational/any.h>
#include <clc/relational/bitselect.h>
#include <clc/relational/isgreater.h>
diff --git a/generic/include/clc/relational/all.h b/generic/include/clc/relational/all.h
new file mode 100644
index 0000000..f917419
--- /dev/null
+++ b/generic/include/clc/relational/all.h
@@ -0,0 +1,16 @@
+
+#define _CLC_ALL_DECL(TYPE) \
+ _CLC_OVERLOAD _CLC_DECL int all(TYPE v);
+
+#define _CLC_VECTOR_ALL_DECL(TYPE) \
+ _CLC_ALL_DECL(TYPE) \
+ _CLC_ALL_DECL(TYPE##2) \
+ _CLC_ALL_DECL(TYPE##3) \
+ _CLC_ALL_DECL(TYPE##4) \
+ _CLC_ALL_DECL(TYPE##8) \
+ _CLC_ALL_DECL(TYPE##16)
+
+_CLC_VECTOR_ALL_DECL(char)
+_CLC_VECTOR_ALL_DECL(short)
+_CLC_VECTOR_ALL_DECL(int)
+_CLC_VECTOR_ALL_DECL(long)
diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES
index 45f7c4a..6a8e34d 100644
--- a/generic/lib/SOURCES
+++ b/generic/lib/SOURCES
@@ -34,6 +34,7 @@ math/mad.cl
math/clc_nextafter.cl
math/nextafter.cl
math/sincos.cl
+relational/all.cl
relational/any.cl
relational/isgreater.cl
relational/isgreaterequal.cl
diff --git a/generic/lib/relational/all.cl b/generic/lib/relational/all.cl
new file mode 100644
index 0000000..6fcc318
--- /dev/null
+++ b/generic/lib/relational/all.cl
@@ -0,0 +1,30 @@
+#include <clc/clc.h>
+
+#define _CLC_ALL(v) (((v) >> ((sizeof(v) * 8) - 1)) & 0x1)
+#define _CLC_ALL2(v) (_CLC_ALL((v).s0) & _CLC_ALL((v).s1))
+#define _CLC_ALL3(v) (_CLC_ALL2((v)) & _CLC_ALL((v).s2))
+#define _CLC_ALL4(v) (_CLC_ALL3((v)) & _CLC_ALL((v).s3))
+#define _CLC_ALL8(v) (_CLC_ALL4((v)) & _CLC_ALL((v).s4) & _CLC_ALL((v).s5) \
+ & _CLC_ALL((v).s6) & _CLC_ALL((v).s7))
+#define _CLC_ALL16(v) (_CLC_ALL8((v)) & _CLC_ALL((v).s8) & _CLC_ALL((v).s9) \
+ & _CLC_ALL((v).sA) & _CLC_ALL((v).sB) \
+ & _CLC_ALL((v).sC) & _CLC_ALL((v).sD) \
+ & _CLC_ALL((v).sE) & _CLC_ALL((v).sf))
+
+
+#define ALL_ID(TYPE) \
+ _CLC_OVERLOAD _CLC_DEF int all(TYPE v)
+
+#define ALL_VECTORIZE(TYPE) \
+ ALL_ID(TYPE) { return _CLC_ALL(v); } \
+ ALL_ID(TYPE##2) { return _CLC_ALL2(v); } \
+ ALL_ID(TYPE##3) { return _CLC_ALL3(v); } \
+ ALL_ID(TYPE##4) { return _CLC_ALL4(v); } \
+ ALL_ID(TYPE##8) { return _CLC_ALL8(v); } \
+ ALL_ID(TYPE##16) { return _CLC_ALL16(v); }
+

Have you looked at the macros in generic/include/clc/clcmacro.h? Do you
think you would be able to use some of those here.

-Tom

Signed-off-by: Aaron Watry <awatry@gmail.com>
---
generic/include/clc/clc.h | 1 +
generic/include/clc/relational/all.h | 16 ++++++++++++++++
generic/lib/SOURCES | 1 +
generic/lib/relational/all.cl | 30 ++++++++++++++++++++++++++++++
4 files changed, 48 insertions(+)
create mode 100644 generic/include/clc/relational/all.h
create mode 100644 generic/lib/relational/all.cl

diff --git a/generic/include/clc/clc.h b/generic/include/clc/clc.h
index 4aa9caa..0a1503a 100644
--- a/generic/include/clc/clc.h
+++ b/generic/include/clc/clc.h
@@ -102,6 +102,7 @@
#include <clc/geometric/normalize.h>

/* 6.11.6 Relational Functions */
+#include <clc/relational/all.h>
#include <clc/relational/any.h>
#include <clc/relational/bitselect.h>
#include <clc/relational/isgreater.h>
diff --git a/generic/include/clc/relational/all.h b/generic/include/clc/relational/all.h
new file mode 100644
index 0000000..f917419
--- /dev/null
+++ b/generic/include/clc/relational/all.h
@@ -0,0 +1,16 @@
+
+#define _CLC_ALL_DECL(TYPE) \
+ _CLC_OVERLOAD _CLC_DECL int all(TYPE v);
+
+#define _CLC_VECTOR_ALL_DECL(TYPE) \
+ _CLC_ALL_DECL(TYPE) \
+ _CLC_ALL_DECL(TYPE##2) \
+ _CLC_ALL_DECL(TYPE##3) \
+ _CLC_ALL_DECL(TYPE##4) \
+ _CLC_ALL_DECL(TYPE##8) \
+ _CLC_ALL_DECL(TYPE##16)
+
+_CLC_VECTOR_ALL_DECL(char)
+_CLC_VECTOR_ALL_DECL(short)
+_CLC_VECTOR_ALL_DECL(int)
+_CLC_VECTOR_ALL_DECL(long)
diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES
index 45f7c4a..6a8e34d 100644
--- a/generic/lib/SOURCES
+++ b/generic/lib/SOURCES
@@ -34,6 +34,7 @@ math/mad.cl
math/clc_nextafter.cl
math/nextafter.cl
math/sincos.cl
+relational/all.cl
relational/any.cl
relational/isgreater.cl
relational/isgreaterequal.cl
diff --git a/generic/lib/relational/all.cl b/generic/lib/relational/all.cl
new file mode 100644
index 0000000..6fcc318
--- /dev/null
+++ b/generic/lib/relational/all.cl
@@ -0,0 +1,30 @@
+#include <clc/clc.h>
+
+#define _CLC_ALL(v) (((v) >> ((sizeof(v) * 8) - 1)) & 0x1)
+#define _CLC_ALL2(v) (_CLC_ALL((v).s0) & _CLC_ALL((v).s1))
+#define _CLC_ALL3(v) (_CLC_ALL2((v)) & _CLC_ALL((v).s2))
+#define _CLC_ALL4(v) (_CLC_ALL3((v)) & _CLC_ALL((v).s3))
+#define _CLC_ALL8(v) (_CLC_ALL4((v)) & _CLC_ALL((v).s4) & _CLC_ALL((v).s5) \
+ & _CLC_ALL((v).s6) & _CLC_ALL((v).s7))
+#define _CLC_ALL16(v) (_CLC_ALL8((v)) & _CLC_ALL((v).s8) & _CLC_ALL((v).s9) \
+ & _CLC_ALL((v).sA) & _CLC_ALL((v).sB) \
+ & _CLC_ALL((v).sC) & _CLC_ALL((v).sD) \
+ & _CLC_ALL((v).sE) & _CLC_ALL((v).sf))
+
+
+#define ALL_ID(TYPE) \
+ _CLC_OVERLOAD _CLC_DEF int all(TYPE v)
+
+#define ALL_VECTORIZE(TYPE) \
+ ALL_ID(TYPE) { return _CLC_ALL(v); } \
+ ALL_ID(TYPE##2) { return _CLC_ALL2(v); } \
+ ALL_ID(TYPE##3) { return _CLC_ALL3(v); } \
+ ALL_ID(TYPE##4) { return _CLC_ALL4(v); } \
+ ALL_ID(TYPE##8) { return _CLC_ALL8(v); } \
+ ALL_ID(TYPE##16) { return _CLC_ALL16(v); }
+

Have you looked at the macros in generic/include/clc/clcmacro.h? Do you
think you would be able to use some of those here.

-Tom

Sadly, the existing macros won't work. The macros in clmacro.h break
all vector operations down to scalar, which then changes the return
value of TRUE for the relational functions from -1 to 1. I tried
using these macros at first, and kept getting invalid return values
from the relational functions because of the nature of scalar/vector
true.

I could, however, change the macros in clmacro.h to only reduce down
to vec2 operations, and then change the *_vectorize() macros to invoke
both the operation which reduces vec2 to scalar and also invoke the
expansion of vec3/4/8/16 to vec2 (although the vec3 expansion could be
awkward as we usually treat that as a vec2 + scalar operation).

--Aaron

>> Signed-off-by: Aaron Watry <awatry@gmail.com>
>> ---
>> generic/include/clc/clc.h | 1 +
>> generic/include/clc/relational/all.h | 16 ++++++++++++++++
>> generic/lib/SOURCES | 1 +
>> generic/lib/relational/all.cl | 30 ++++++++++++++++++++++++++++++
>> 4 files changed, 48 insertions(+)
>> create mode 100644 generic/include/clc/relational/all.h
>> create mode 100644 generic/lib/relational/all.cl
>>
>> diff --git a/generic/include/clc/clc.h b/generic/include/clc/clc.h
>> index 4aa9caa..0a1503a 100644
>> --- a/generic/include/clc/clc.h
>> +++ b/generic/include/clc/clc.h
>> @@ -102,6 +102,7 @@
>> #include <clc/geometric/normalize.h>
>>
>> /* 6.11.6 Relational Functions */
>> +#include <clc/relational/all.h>
>> #include <clc/relational/any.h>
>> #include <clc/relational/bitselect.h>
>> #include <clc/relational/isgreater.h>
>> diff --git a/generic/include/clc/relational/all.h b/generic/include/clc/relational/all.h
>> new file mode 100644
>> index 0000000..f917419
>> --- /dev/null
>> +++ b/generic/include/clc/relational/all.h
>> @@ -0,0 +1,16 @@
>> +
>> +#define _CLC_ALL_DECL(TYPE) \
>> + _CLC_OVERLOAD _CLC_DECL int all(TYPE v);
>> +
>> +#define _CLC_VECTOR_ALL_DECL(TYPE) \
>> + _CLC_ALL_DECL(TYPE) \
>> + _CLC_ALL_DECL(TYPE##2) \
>> + _CLC_ALL_DECL(TYPE##3) \
>> + _CLC_ALL_DECL(TYPE##4) \
>> + _CLC_ALL_DECL(TYPE##8) \
>> + _CLC_ALL_DECL(TYPE##16)
>> +
>> +_CLC_VECTOR_ALL_DECL(char)
>> +_CLC_VECTOR_ALL_DECL(short)
>> +_CLC_VECTOR_ALL_DECL(int)
>> +_CLC_VECTOR_ALL_DECL(long)
>> diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES
>> index 45f7c4a..6a8e34d 100644
>> --- a/generic/lib/SOURCES
>> +++ b/generic/lib/SOURCES
>> @@ -34,6 +34,7 @@ math/mad.cl
>> math/clc_nextafter.cl
>> math/nextafter.cl
>> math/sincos.cl
>> +relational/all.cl
>> relational/any.cl
>> relational/isgreater.cl
>> relational/isgreaterequal.cl
>> diff --git a/generic/lib/relational/all.cl b/generic/lib/relational/all.cl
>> new file mode 100644
>> index 0000000..6fcc318
>> --- /dev/null
>> +++ b/generic/lib/relational/all.cl
>> @@ -0,0 +1,30 @@
>> +#include <clc/clc.h>
>> +
>> +#define _CLC_ALL(v) (((v) >> ((sizeof(v) * 8) - 1)) & 0x1)
>> +#define _CLC_ALL2(v) (_CLC_ALL((v).s0) & _CLC_ALL((v).s1))
>> +#define _CLC_ALL3(v) (_CLC_ALL2((v)) & _CLC_ALL((v).s2))
>> +#define _CLC_ALL4(v) (_CLC_ALL3((v)) & _CLC_ALL((v).s3))
>> +#define _CLC_ALL8(v) (_CLC_ALL4((v)) & _CLC_ALL((v).s4) & _CLC_ALL((v).s5) \
>> + & _CLC_ALL((v).s6) & _CLC_ALL((v).s7))
>> +#define _CLC_ALL16(v) (_CLC_ALL8((v)) & _CLC_ALL((v).s8) & _CLC_ALL((v).s9) \
>> + & _CLC_ALL((v).sA) & _CLC_ALL((v).sB) \
>> + & _CLC_ALL((v).sC) & _CLC_ALL((v).sD) \
>> + & _CLC_ALL((v).sE) & _CLC_ALL((v).sf))
>> +
>> +
>> +#define ALL_ID(TYPE) \
>> + _CLC_OVERLOAD _CLC_DEF int all(TYPE v)
>> +
>> +#define ALL_VECTORIZE(TYPE) \
>> + ALL_ID(TYPE) { return _CLC_ALL(v); } \
>> + ALL_ID(TYPE##2) { return _CLC_ALL2(v); } \
>> + ALL_ID(TYPE##3) { return _CLC_ALL3(v); } \
>> + ALL_ID(TYPE##4) { return _CLC_ALL4(v); } \
>> + ALL_ID(TYPE##8) { return _CLC_ALL8(v); } \
>> + ALL_ID(TYPE##16) { return _CLC_ALL16(v); }
>> +
>
> Have you looked at the macros in generic/include/clc/clcmacro.h? Do you
> think you would be able to use some of those here.
>
> -Tom

Sadly, the existing macros won't work. The macros in clmacro.h break
all vector operations down to scalar, which then changes the return
value of TRUE for the relational functions from -1 to 1. I tried
using these macros at first, and kept getting invalid return values
from the relational functions because of the nature of scalar/vector
true.

I could, however, change the macros in clmacro.h to only reduce down
to vec2 operations, and then change the *_vectorize() macros to invoke
both the operation which reduces vec2 to scalar and also invoke the
expansion of vec3/4/8/16 to vec2 (although the vec3 expansion could be
awkward as we usually treat that as a vec2 + scalar operation).

The patch is fine as is, I was just hoping there was an opportunity to share code

LGTM.

Signed-off-by: Aaron Watry <awatry@gmail.com>
---
generic/include/clc/clc.h | 1 +
generic/include/clc/relational/all.h | 16 ++++++++++++++++
generic/lib/SOURCES | 1 +
generic/lib/relational/all.cl | 30 ++++++++++++++++++++++++++++++
4 files changed, 48 insertions(+)
create mode 100644 generic/include/clc/relational/all.h
create mode 100644 generic/lib/relational/all.cl

LGTM for the series, feel free to commit.

-Tom