www.digitalmars.com         C & C++   DMDScript  

D.gnu - Changing "target" parameter via attribute

--047d7b2e489accc03a04ddaec034
Content-Type: text/plain; charset=UTF-8

So we talked about this at DConf.

Working on std.simd, I need to be able to change the target parameter on a
per-function basis.
GCC supports this via: __attribute__((target("sse2"))) for instance.

I need the ability to set this from D, but the trick is, I need to be able
to set the target string according to a template arg.

Eg:
  enum Targets { SSE2, SSE3 };
  enum targets[] = [ "sse2", "sse3" ];

   attribute("target", targets[T]) // <- attribute needs to refer to the
template arg T
  void func(Targets T)();


  {
    // this way, it is possibly to produce dynamic selection of code paths
optimised for different CPU features (a task which is usually very tedious
in C/C++)
    func!(Targets.SSE2)();
  }

--047d7b2e489accc03a04ddaec034
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">So we talked about this at DConf.<div><br></div><div style=
Working on std.simd, I need to be able to change the target parameter on a=

target(&quot;sse2&quot;))) for instance.</div> <div style><br></div><div style>I need the ability to set this from D, but = the trick is, I need to be able to set the target string according to a tem= plate arg.</div><div style><br></div><div style>Eg:</div><div style>=C2=A0 = enum Targets { SSE2, SSE3 };</div> <div style>=C2=A0 enum targets[] =3D [ &quot;sse2&quot;, &quot;sse3&quot; ]= ;<br></div><div style><br></div><div style>=C2=A0 attribute(&quot;target&q= uot;, targets[T]) // &lt;- attribute needs to refer to the template arg T</= div><div style> =C2=A0 void func(Targets T)();</div><div style><br></div><div style><br></d= iv><div style>=C2=A0 {</div><div style>=C2=A0 =C2=A0 // this way, it is pos= sibly to produce dynamic selection of code paths optimised for different CP= U features (a task which is usually very tedious in C/C++)</div> <div style>=C2=A0 =C2=A0 func!(Targets.SSE2)();</div><div style>=C2=A0 }</d= iv><div style><br></div></div> --047d7b2e489accc03a04ddaec034--
May 27 2013