Support for gcc vector attributes, SIMD builtins

Mike Farnsworth mike.farnsworth at gmail.com
Tue Feb 1 00:10:09 PST 2011


I built gdc from tip on Fedora 13 (x86-64) and started playing around
with creating a vector struct (x,y,z,w) to see what kind of optimization
the code generator did with it.  It was able to partially drop into SSE
registers and instructions, but not as well as I had hoped from writing
"regular" D code.

I poked through the builtins that get pulled into d-builtins.c /
d-builtins2.cc but I don't see anything that might be pulling in
definitions such as __builtin_ia32_* for SSE, for example.

How hard would it be to get some sort of vector attribute attached to a
type (or just plain indroduce v4sf, __m128, or something like that) and
get those SIMD builtins available?

For the curious, here are how they are defined in, for example,
xmmintrin.h for gcc:

typedef float __m128 __attribute__ ((__vector_size__ (16), __may_alias__));

typedef float __v4sf __attribute__ ((__vector_size__ (16)));

extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__,
__artificial__))
_mm_add_ps (__m128 __A, __m128 __B)
{
  return (__m128) __builtin_ia32_addps ((__v4sf)__A, (__v4sf)__B);
}

I'm game for making an attempt myself if someone can point me in the
right direction.  I'm a hardcore ray tracing / rendering guy, and
performance is of the utmost importance.  If I could write a ray tracer
in D that matches my C++ tracer for performance, I'd be ecstatic.

-Mike



More information about the D.gnu mailing list