Very simple SIMD programming

Manu turkeyman at gmail.com
Thu Oct 25 03:57:14 PDT 2012


On 25 October 2012 13:38, Iain Buclaw <ibuclaw at ubuntu.com> wrote:

> On 25 October 2012 09:36, Manu <turkeyman at gmail.com> wrote:
> > On 25 October 2012 02:18, Iain Buclaw <ibuclaw at ubuntu.com> wrote:
> >>
> >> On 25 October 2012 00:16, Manu <turkeyman at gmail.com> wrote:
> >> > On 25 October 2012 02:01, Iain Buclaw <ibuclaw at ubuntu.com> wrote:
> >> >>
> >> >> On 24 October 2012 23:46, Manu <turkeyman at gmail.com> wrote:
> >> >>
> >> >> > Let's consider your example above for instance, I would rewrite
> >> >> > (given
> >> >> > existing syntax):
> >> >> >
> >> >> > // vector length of context = 1; current_mask = T
> >> >> > int4 v = [0,3,4,1];
> >> >> > int4 w = 3; // [3,3,3,3] via broadcast
> >> >> > uint4 m = maskLess(v, w); // [T,F,F,T] (T == ones, F == zeroes)
> >> >> > v += int4(1); // [1,4,5,2]
> >> >> >
> >> >> > // the if block is trivially rewritten:
> >> >> > int4 trueSide = v + int4(2);
> >> >> > int4 falseSize = v + int4(3);
> >> >> > v = select(m, trueSide, falseSide); // [3,7,8,4]
> >> >> >
> >> >> >
> >> >>
> >> >> This should work....
> >> >>
> >> >> int4 trueSide = v + 2;
> >> >> int4 falseSide = v + 3;
> >> >
> >> >
> >> > Probably, just wasn't sure.
> >>
> >> The idea with vectors is that they support the same operations that D
> >> array operations support. :-)
> >
> >
> > I tried to have indexing banned... I presume indexing works? :(
>
> You can't index directly, no.  Only through .array[] property, which
> isn't an lvalue.
>

Yeah, good. That's how I thought it was :)

Let me rewrite ti again then:

int4 v = [0,3,4,1];
int4 w = 3; // [3,3,3,3] via broadcast
v = selectLess(v, w, v + 3, v + 4); // combine the prior few lines: v < w =
[T,F,F,T]  ->  [0+3, 3+4, 4+4, 1+3] == [3,7,8,4]

I think this is far more convenient than any crazy 'if' syntax :) .. It's
also perfectly optimal on all architectures I know aswell!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20121025/ddd49939/attachment.html>


More information about the Digitalmars-d mailing list