Support for gcc vector attributes, SIMD builtins

Iain Buclaw ibuclaw at ubuntu.com
Tue Feb 1 10:57:08 PST 2011


== Quote from Mike Farnsworth (mike.farnsworth at gmail.com)'s article
> Iain Buclaw Wrote:
> > Interestingly enough, this particular example actually ICEs the compiler. It
> > appears that while *explicit* casting is done in the code, DMDFE actually
> > *ignores* this, which is terrible on DMD's part...
> Hah.  It's obvious dmdfe doesn't understand that the builtin's signature
correctly, so I'll hold off on a bug report until I can figure out what kind of
signature that builtin had registered with dmdfe.

Actually, it appears it's much more simpler than that.

IntA a;
IntB b;
a = cast(IntA)b;

Although explicit casts are required to not get errors, somewhere in the semantic
stage (I presume), the frontend decides no codegen is required to perform the
cast, so omits it.

Where this puts GDC (I think), is that the backend is told to perform a
convert/move where the to and from register types are different (due to attributes
applied to the type), and triggers an assert.

It's nothing too much to worry about, but maybe raise a bug (to remind me to look
at it in better depth sometime).

> > Saying that, workaround is to use array types.
> > typedef float[4] __m128;
> > typedef float[4] __v4sf;
> >
> >
> > All the more reason to show you that pragma(attribute) is still very incomplete to
> > use. Any ideas to improve it are welcome though. :)
> In my (not very abundant) spare time, I'll poke around the attribute stuff to
see if I can attach the vector_size(16) attribute to a float[4] array type.  I
know the __builtin_ia32_addps function, for example, takes a v4sf (__m128 is just
Intel's version that can change personalities at will; I feel no inclination to
keep it around, and instead go with more strictly defined types and cast
intrinsics).  If I can get that builtin to take a typedef'd float[4] without a
cast, perhaps dmdfe will not drop any data and the codegen will happen properly.
> Where do I look to see the attribute pragmas in gdc?  Where do I look to
potentially change the signature that dmdfe sees for the __builtin_ia32_*
functions?  If I can get a hand-coded signature to work, then we'll be in business.
> -Mike

In d-builtins2.cc:
// Entry point for import gcc.builtins, builds GCC builtins in DMD AST on the fly.
d_gcc_magic_builtins_module()

// Convert GCC type to DMD type, builds functions as well normal D types.
gcc_type_to_d_type()

In d-bi-attrs*.h are all handlers for supported attributes (you needn't touch
them, as they are all copied from c-common.c).

Regards
Iain


More information about the D.gnu mailing list