simd comparison operator?

2013-02-19 Thread monarch_dodra
Are there any plans that would allow using opEqual or opCmp operators with simd? My use case is that I have arrays, and I need to verify that ALL the elements in my array are comprised between two values (in this specific case 10 and 93). I was hoping I would be able to use: ubyte[] arr = ..

Re: simd comparison operator?

2013-02-19 Thread bearophile
monarch_dodra: is there a reason that simd can't do this? I find it strange, since simd allows for straight up array to array opEquals, but not array to value? SIMD instructions support those operations, so it's mostly a matter of designing a good semantics for D and implementing it. Bye,

Re: simd comparison operator?

2013-02-19 Thread Don
On Tuesday, 19 February 2013 at 14:03:54 UTC, monarch_dodra wrote: Are there any plans that would allow using opEqual or opCmp operators with simd? My use case is that I have arrays, and I need to verify that ALL the elements in my array are comprised between two values (in this specific case

Re: simd comparison operator?

2013-02-19 Thread bearophile
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 se

Re: simd comparison operator?

2013-02-19 Thread John Colvin
On Tuesday, 19 February 2013 at 16:03:58 UTC, bearophile 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 whic

Re: simd comparison operator?

2013-02-19 Thread bearophile
John Colvin: I think the right design here is to return a bool[N]. ... There is significant opposition to any simd operators that allocate. The reasoning is that they appear fast but are in actual fact slow (for most normal size vectors, the allocation would be much slower than the calculati

Re: simd comparison operator?

2013-02-19 Thread John Colvin
On Tuesday, 19 February 2013 at 16:46:36 UTC, bearophile wrote: John Colvin: I think the right design here is to return a bool[N]. ... There is significant opposition to any simd operators that allocate. The reasoning is that they appear fast but are in actual fact slow (for most normal size

Re: simd comparison operator?

2013-02-19 Thread bearophile
John Colvin: a) quite counter-intuitive. An operation between two normal, heap allocated arrays generating a stack allocated array, with the scoping rules that entails? Then maybe: bool[4] res = a > b; Bye, bearophile

Re: simd comparison operator?

2013-02-19 Thread tn
On Tuesday, 19 February 2013 at 16:28:15 UTC, John Colvin wrote: On Tuesday, 19 February 2013 at 16:03:58 UTC, bearophile 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

Re: simd comparison operator?

2013-02-19 Thread John Colvin
On Tuesday, 19 February 2013 at 17:46:56 UTC, bearophile wrote: John Colvin: a) quite counter-intuitive. An operation between two normal, heap allocated arrays generating a stack allocated array, with the scoping rules that entails? Then maybe: bool[4] res = a > b; Bye, bearophile Yes, b

Re: simd comparison operator?

2013-02-19 Thread jerro
Anybody have any idea as a workaround? My program has very high data throughput, and never actually handles the array elements individually, just manipulates them simd chunks at once. Validating the content is important, but performance is taking a real toll... One possible workaround is to u

Re: simd comparison operator?

2013-02-19 Thread monarch_dodra
On Tuesday, 19 February 2013 at 17:58:14 UTC, John Colvin wrote: On Tuesday, 19 February 2013 at 17:46:56 UTC, bearophile wrote: John Colvin: a) quite counter-intuitive. An operation between two normal, heap allocated arrays generating a stack allocated array, with the scoping rules that enta

Re: simd comparison operator?

2013-02-19 Thread jerro
One possible workaround is to use simd operation eplicitly. I've played around a bit with this and came up with this: https://gist.github.com/jerro/4988229 This currently only works with GDC and LDC (but it probably could be made to work with DMD too). I've update the gist now so that it wor

Re: simd comparison operator?

2013-02-22 Thread Marco Leise
Am Tue, 19 Feb 2013 18:51:35 +0100 schrieb "tn" : > In many cases it would be nice, if "arr[] < x" translated to > "map!(a => a < x)(arr)" and similarly "arr1[] < arr2[]" > translated to "map!((a, b) => a < b)(arr1, arr2)" or equivalent > (*). This would make the compiler depend on std.algorit

Re: simd comparison operator?

2013-03-03 Thread Manu
On 20 February 2013 02:03, bearophile 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 t

Re: simd comparison operator?

2013-03-03 Thread bearophile
Manu: 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) Isn't something like this better? uint4 mask = a > b; Bye, bearophile

Re: simd comparison operator?

2013-03-03 Thread Manu
I don't think opCmp can fit that model? But aside from that, I think that's misleading, and suggests to the user that it's a trivial operation. Additionally, it's not necessarily even possible in a portable way. I also think most users would expect that comparison operators produce a boolean resu