UDA from template args
Artur Skawina via Digitalmars-d
digitalmars-d at puremagic.com
Thu May 22 06:53:47 PDT 2014
On 05/22/14 12:54, Manu via Digitalmars-d wrote:
> This issue has been there for a long time, and std.simd has been
> blocked on this for a year.
> https://issues.dlang.org/show_bug.cgi?id=10193
>
> Can anyone chime in and suggest options, or perhaps how to fix?
It's not entirely clear from that report what exactly you need, but
one way would be:
enum targets = [ "hello":"sse2", "world":"avx" ];
template func(string Target)
{
@attribute("target", targets[Target]) T func(T)(T arg)
{
return arg;
}
}
Using CTFE instead of the above AA look-up could be more natural,
but that does not work here, as it crashes the frontend...
> To address this, in GCC, you can use attributes or pragma's to specify
> the code-gen on a per-function basis, ie: __attribute__ ((__target__
> ("sse2"))), or #pragma GCC target ("sse2")
> To access this with GDC, I use the code above.
Keep in mind that GDC will not inline those functions into callers
marked with a different (or no) target attribute.
artur
More information about the Digitalmars-d
mailing list