<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Mar 3, 2015 at 7:20 PM, Tom Stellard <span dir="ltr"><<a href="mailto:thomas.stellard@amd.com" target="_blank">thomas.stellard@amd.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">We need to reinterpret float/double types as uint/ulong in order to<br>
perform the bitwise operations.<br>
<br>
This has been tested with piglit, OpenCV, and the ocl conformance tests.<br>
---<br>
 generic/include/clc/relational/bitselect.h   | 29 ++++++++++++++++-<br>
 generic/include/clc/relational/bitselect.inc | 23 ++++++++++++++<br>
 generic/lib/SOURCES                          |  1 +<br>
 generic/lib/relational/<a href="http://bitselect.cl" target="_blank">bitselect.cl</a>          | 47 ++++++++++++++++++++++++++++<br>
 generic/lib/relational/bitselect.inc         | 27 ++++++++++++++++<br>
 5 files changed, 126 insertions(+), 1 deletion(-)<br>
 create mode 100644 generic/include/clc/relational/bitselect.inc<br>
 create mode 100644 generic/lib/relational/<a href="http://bitselect.cl" target="_blank">bitselect.cl</a><br>
 create mode 100644 generic/lib/relational/bitselect.inc<br>
<br>
diff --git a/generic/include/clc/relational/bitselect.h b/generic/include/clc/relational/bitselect.h<br>
index e91cbfd..0c7b2f7 100644<br>
--- a/generic/include/clc/relational/bitselect.h<br>
+++ b/generic/include/clc/relational/bitselect.h<br>
@@ -1 +1,28 @@<br>
-#define bitselect(x, y, z) ((x) ^ ((z) & ((y) ^ (x))))<br>
+/*<br>
+ * Copyright (c) 2015 Advanced Micro Devices, Inc.<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a copy<br>
+ * of this software and associated documentation files (the "Software"), to deal<br>
+ * in the Software without restriction, including without limitation the rights<br>
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell<br>
+ * copies of the Software, and to permit persons to whom the Software is<br>
+ * furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice shall be included in<br>
+ * all copies or substantial portions of the Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE<br>
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,<br>
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN<br>
+ * THE SOFTWARE.<br>
+ */<br>
+<br>
+#define __CLC_BODY <clc/relational/bitselect.inc><br>
+#include <clc/math/gentype.inc><br>
+#define __CLC_BODY <clc/relational/bitselect.inc><br>
+#include <clc/integer/gentype.inc><br>
+<br>
+#undef __CLC_BODY<br>
diff --git a/generic/include/clc/relational/bitselect.inc b/generic/include/clc/relational/bitselect.inc<br>
new file mode 100644<br>
index 0000000..364d649<br>
--- /dev/null<br>
+++ b/generic/include/clc/relational/bitselect.inc<br>
@@ -0,0 +1,23 @@<br>
+/*<br>
+ * Copyright (c) 2015 Advanced Micro Devices, Inc.<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a copy<br>
+ * of this software and associated documentation files (the "Software"), to deal<br>
+ * in the Software without restriction, including without limitation the rights<br>
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell<br>
+ * copies of the Software, and to permit persons to whom the Software is<br>
+ * furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice shall be included in<br>
+ * all copies or substantial portions of the Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE<br>
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,<br>
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN<br>
+ * THE SOFTWARE.<br>
+ */<br>
+<br>
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE bitselect(__CLC_GENTYPE x, __CLC_GENTYPE y, __CLC_GENTYPE z);<br>
diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES<br>
index a7b2fa2..ac3d870 100644<br>
--- a/generic/lib/SOURCES<br>
+++ b/generic/lib/SOURCES<br>
@@ -80,6 +80,7 @@ math/<a href="http://sincos_helpers.cl" target="_blank">sincos_helpers.cl</a><br>
 math/<a href="http://tan.cl" target="_blank">tan.cl</a><br>
 relational/<a href="http://all.cl" target="_blank">all.cl</a><br>
 relational/<a href="http://any.cl" target="_blank">any.cl</a><br>
+relational/<a href="http://bitselect.cl" target="_blank">bitselect.cl</a><br>
 relational/<a href="http://isequal.cl" target="_blank">isequal.cl</a><br>
 relational/<a href="http://isfinite.cl" target="_blank">isfinite.cl</a><br>
 relational/<a href="http://isgreater.cl" target="_blank">isgreater.cl</a><br>
diff --git a/generic/lib/relational/<a href="http://bitselect.cl" target="_blank">bitselect.cl</a> b/generic/lib/relational/<a href="http://bitselect.cl" target="_blank">bitselect.cl</a><br>
new file mode 100644<br>
index 0000000..29f07d1<br>
--- /dev/null<br>
+++ b/generic/lib/relational/<a href="http://bitselect.cl" target="_blank">bitselect.cl</a><br>
@@ -0,0 +1,47 @@<br>
+/*<br>
+ * Copyright (c) 2014,2015 Advanced Micro Devices, Inc.<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a copy<br>
+ * of this software and associated documentation files (the "Software"), to deal<br>
+ * in the Software without restriction, including without limitation the rights<br>
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell<br>
+ * copies of the Software, and to permit persons to whom the Software is<br>
+ * furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice shall be included in<br>
+ * all copies or substantial portions of the Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE<br>
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,<br>
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN<br>
+ * THE SOFTWARE.<br>
+ */<br>
+<br>
+#include <clc/clc.h><br>
+<br>
+#include "../clcmacro.h"<br>
+<br>
+#define __CLC_BODY <bitselect.inc><br>
+#include <clc/integer/gentype.inc><br>
+#undef __CLC_BODY<br>
+<br>
+_CLC_OVERLOAD _CLC_DEF float bitselect(float x, float y, float z) {<br>
+  return as_float(bitselect(as_uint(x), as_uint(y), as_uint(z)));<br>
+}<br>
+<br>
+_CLC_TERNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, bitselect, float, float, float);<br>
+<br></blockquote><div><br></div><div>This looks ok as it is, but I do want to point out that by doing the float/double bitselects this way, we are explicitly splitting the float/double vectors into scalars, running bitselect(int_type), and then rebuilding a float vector from the results of the individual scalar operations.<br><br></div><div>Previously, this was handled directly as vectors (even though incorrectly).  For SI, this probably doesn't matter.  For EG/NI, it might.  In either case, we're forcing LLVM to do more work when running optimization passes.<br><br></div><div>If you don't want to change this, that's fine.  It was broken before, and will be correct now. That's good enough for me.  We can always speed it up later as needed.<br></div><div><br></div><div>--Aaron<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+#ifdef cl_khr_fp64<br>
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable<br>
+<br>
+_CLC_OVERLOAD _CLC_DEF double bitselect(double x, double y, double z) {<br>
+  return as_double(bitselect(as_ulong(x), as_ulong(y), as_ulong(z)));<br>
+}<br>
+<br>
+_CLC_TERNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, bitselect, double, double, double);<br>
+<br>
+#endif<br>
diff --git a/generic/lib/relational/bitselect.inc b/generic/lib/relational/bitselect.inc<br>
new file mode 100644<br>
index 0000000..8157331<br>
--- /dev/null<br>
+++ b/generic/lib/relational/bitselect.inc<br>
@@ -0,0 +1,27 @@<br>
+/*<br>
+ * Copyright (c) 2014,2015 Advanced Micro Devices, Inc.<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a copy<br>
+ * of this software and associated documentation files (the "Software"), to deal<br>
+ * in the Software without restriction, including without limitation the rights<br>
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell<br>
+ * copies of the Software, and to permit persons to whom the Software is<br>
+ * furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice shall be included in<br>
+ * all copies or substantial portions of the Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE<br>
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,<br>
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN<br>
+ * THE SOFTWARE.<br>
+ */<br>
+<br>
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE bitselect(__CLC_GENTYPE x, __CLC_GENTYPE y, __CLC_GENTYPE z) {<br>
+  return ((x) ^ ((z) & ((y) ^ (x))));<br>
+}<br>
+<br>
+<br>
<span class=""><font color="#888888">--<br>
2.0.4<br>
<br>
<br>
_______________________________________________<br>
Libclc-dev mailing list<br>
<a href="mailto:Libclc-dev@pcc.me.uk">Libclc-dev@pcc.me.uk</a><br>
<a href="http://www.pcc.me.uk/cgi-bin/mailman/listinfo/libclc-dev" target="_blank">http://www.pcc.me.uk/cgi-bin/mailman/listinfo/libclc-dev</a><br>
</font></span></blockquote></div><br></div></div>