On 20 February 2013 02:03, bearophile <bearophileh...@lycos.com> wrote:
> Don: > >> Simd comparison generally doesn't return a bool, it returns a bool array, >> one per element. >> >> 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" ? >> >> All make sense. That's the problem. >> > > Right, it's a design problem. > 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]. > So in this case monarch_dodra has to add some more code to test all/any. > > Bye, > bearophile > Don is on the money. 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. 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: 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. auto result = select(mask, c, d); // <- select components from c or d according to the bit mask.