<div dir="ltr">On 20 February 2013 02:03, bearophile <span dir="ltr"><<a href="mailto:bearophileHUGS@lycos.com" target="_blank">bearophileHUGS@lycos.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Don:<div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Simd comparison generally doesn't return a bool, it returns a bool array,<br>
one per element.<br>
<br>
Does  (arr[] < 10) mean "is every element in arr less than 10" OR "is any element of arr less than 10" OR "create a bool array which is true for each element which is less than 10" ?<br>
<br>
All make sense. That's the problem.<br>
</blockquote>
<br></div>
Right, it's a design problem.<br>
I think the right thing to do is to take a look at what's an efficient operation to do in hardware (and then look at what's the most commonly useful operation for users). I think the right design here is to return a bool[N].<br>


So in this case monarch_dodra has to add some more code to test all/any.<br>
<br>
Bye,<br>
bearophile<br>
</blockquote></div><br></div><div class="gmail_extra">Don is on the money.</div><div class="gmail_extra"><br></div><div class="gmail_extra">I drafted: bool allEqual(a,b)/anyEqual(a,b) and friends in std.simd, but I haven't written them yet (been awol for a while). They're actually quite tricky to get right+fast in a portable way.</div>
<div class="gmail_extra"><br></div>
<div class="gmail_extra">all/any comparisons are often used in a boolean way, but they may not be super fast on some architectures. If you want to do component-wise logic, the typical approach is to use component-wise selection, eg:</div>

<div class="gmail_extra">  uint4 mask = compareGreater(a, b); // <- build a bit mask of 0's (false) or 1's (true) where components of a are greater than b.</div><div class="gmail_extra">  auto result = select(mask, c, d); // <- select components from c or d according to the bit mask.</div>

</div>