<div dir="ltr"><div>Hi all,</div><div><br></div><div>While working on my GSoC project, I came across an issue with doing comparisons on *4 types (float4, uchar4, half4).<br></div><div><br></div><div>In float4's case, < is overloaded in <i>util/util_math_float4.h</i>, but it returns an int4 instead of a bool, so using this for, say, if statements would not work.</div><div><br></div><div>Here is the relevant code:</div><div>ccl_device_inline int4 operator<(const float4& a, const float4& b)<br>{<br>#ifdef __KERNEL_SSE__<br>    return int4(_mm_castps_si128(_mm_cmplt_ps(a.m128, b.m128)));<br>#else<br>    return make_int4(a.x < b.x, a.y < b.y, a.z < b.z, a.w < b.w);<br>#endif<br>}<br></div><div><br></div><div>There are two ways to resolve this:</div><div>1. Change the function to return a bool (which will probably break everything that currently compares float4s).</div><div>2. Write a conversion operator for int4 so that we may evaluate the int4 comparison result as a bool. However, I have heard that operator bools are discouraged since it can result in weird casting issues.<br></div><div><br></div><div>Implementation of #2 would be something like this:</div><div>/* <i>util/util_types_int4.h</i> */<br></div><div>struct ccl_try_align(16) int4 {</div><div>    int x, y, z, w;<br></div><div>    /* ... */<br></div><div>    operator bool() const { return x && y && z && w;  }<br>};</div><div><br></div><div>For uchar4 and half4, neither of them even have util_math files. A trivial way to solve this would be to just copy most of <i>util/util_math_float4.h</i> for these types, although I would like to ask around first before just adding new util_math files. For these types, if I were to base their util_math files on float4's, should we overload other operators such as +, ==, etc. since we are already creating the files, even if there is no code currently using them?<br></div><div><br></div><div>I am interested in having proper overloaded operators particularly because it would make template code much cleaner. What are your thoughts on what should be done with these types?</div><div><br></div><div>Best regards,</div><div>Geraldine<br></div><div><br></div></div>