D vectors

Artur Skawina art.08.09 at gmail.com
Mon Jan 9 16:46:09 PST 2012


On 01/10/12 00:43, Iain Buclaw wrote:
> ^Manu got an itchy knees to try out vector support. ;)
> 

BTW, how are vector literals supposed to work in D?

Turns out i was right to be worried about ebp - see the vtst()
function below...

--------------------------------------
alias __vector(int[4]) i4;

i4 vadd(i4 a, i4 b) { return a+b;}
i4 vtst(i4 a, i4 b) { return a*b+a-b;}

i4 vvvv() {
   i4 a = void;
   i4 b = void;
   
   return vadd(a, b);
}

--------------------------------------

00000000 <_D5vect14vaddFNhG4iNhG4iZNhG4i>:
   0:   55                      push   %ebp
   1:   66 0f fe c1             paddd  %xmm1,%xmm0
   5:   89 e5                   mov    %esp,%ebp
   7:   5d                      pop    %ebp
   8:   c3                      ret    

00000010 <_D5vect14vtstFNhG4iNhG4iZNhG4i>:
  10:   66 0f 6f d0             movdqa %xmm0,%xmm2
  14:   66 0f 38 40 c1          pmulld %xmm1,%xmm0
  19:   55                      push   %ebp
  1a:   89 e5                   mov    %esp,%ebp
  1c:   5d                      pop    %ebp
  1d:   66 0f fe c2             paddd  %xmm2,%xmm0
  21:   66 0f fa c1             psubd  %xmm1,%xmm0
  25:   c3                      ret    

00000030 <_D5vect14vvvvFZNhG4i>:
  30:   55                      push   %ebp
  31:   66 0f ef c0             pxor   %xmm0,%xmm0
  35:   89 e5                   mov    %esp,%ebp
  37:   5d                      pop    %ebp
  38:   c3                      ret    
-----------------------------------------

The "extern(C)" hack works, and result in eg:

--------------------------------------------------
00000010 <vtst>:
  10:   66 0f 6f d0             movdqa %xmm0,%xmm2
  14:   66 0f 38 40 c1          pmulld %xmm1,%xmm0
  19:   66 0f fe c2             paddd  %xmm2,%xmm0
  1d:   66 0f fa c1             psubd  %xmm1,%xmm0
  21:   c3                      ret    
--------------------------------------------------

but marking large parts of D code that way seems wrong...

I'm going to assume the vvvv() transformation is an
optimization. :)

artur


More information about the D.gnu mailing list