<div><div class="gmail_quote">On 24 September 2011 15:37, Iain Buclaw <span dir="ltr"><<a href="mailto:ibuclaw@ubuntu.com">ibuclaw@ubuntu.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
== Quote from Manu Evans (<a href="mailto:turkeyman@gmail.com">turkeyman@gmail.com</a>)'s article<br>
> > > How can I do this in a nice way in D? I'm long sick of writing<br>
> > > unsightly vector classes in C++, but fortunately using vendor<br>
> > > specific compiler intrinsics usually leads to decent code<br>
> > > generation. I can currently imagine an equally ugly (possibly worse)<br>
> > > hardware vector library in D, if it's even possible. But perhaps<br>
> > > I've missed something here?<br>
> > Your C++ vector code should be amenable to translation to D, so that effort of<br>
> > yours isn't lost, except that it'd have to be in inline asm rather than<br>
intrinsics.<br>
> But sadly, in that case, it wouldn't work. Without an intrinsic hardware vector<br>
type, there's<br>
> no way to pass vectors to functions in registers, and also, using explicit asm,<br>
you tend to<br>
> end up with endless unnecessary loads and stores, and potentially a lot of redundant<br>
> shuffling/permutation. This will differ radically between architectures too.<br>
> I think I read in another post too that functions containing inline asm will not<br>
be inlined?<br>
> How does the D compiler go at optimising code around inline asm blocks? Most<br>
compilers have a<br>
> lot of trouble optimising around inline asm blocks, and many don't even attempt<br>
to do so...<br>
> How does GDC compare to DMD? Does it do a good job?<br>
> I really need to take the weekend and do a lot of experiments I think.<br>
<br>
GDC is just the same as DMD (same runtime library implementation for vector array<br>
operations).<br>
<br>
<br>
You can define vector types in the language through use of GCC's attribute though<br>
(is a pragma in GDC), then use a union to interface between it and the<br>
corresponding static array. It's deliberately UGLY and PRONE to you hitting lots<br>
of brick walls if you don't handle them in a very specific way though. :~)<br>
<br>
Stock example:<br>
<br>
pragma(attribute, vector_size())<br>
typedef float __v4sf_t<br>
<br>
union __v4sf {<br>
float[4] f;<br>
__v4sf_t v;<br>
}<br>
<br>
<br>
__v4sf a = {[1,2,3,4]}<br>
b = {[1,2,3,4]}<br>
c;<br>
<br>
c.v = a.v + b.v;<br>
assert(c.f == [2,4,6,8]);<br>
<br>
<br>
The assignment compiles down to ~5 instructions:<br>
movaps -0x88(%ebp),%xmm1<br>
movaps -0x78(%ebp),%xmm0<br>
addps %xmm1,%xmm0<br>
movaps %xmm0,-0x68(%ebp)<br>
flds -0x68(%ebp)<br>
<br>
And is far quicker than c[] = a[] + b[] due to it being inlined, and not an<br>
external library call.<br>
<br>
Regards<br>
<font color="#888888">Iain<br>
</font></blockquote></div><br></div><div>Nice!<div>Is there an IRC channel, or anywhere for realtime D discussion?</div><div>I'm interested in trying to build some GDC cross compilers, and perhaps contributing to the standard library on a few embedded systems, but I have a lot of little questions and general things that don't suit a mailing list...<br>
</div></div><div>Perhaps some IM? It seems to me that you are the authority on GDC implementation and support...</div>