Any usable SIMD implementation?
xenon325 via Digitalmars-d
digitalmars-d at puremagic.com
Tue Apr 12 03:55:18 PDT 2016
On Thursday, 7 April 2016 at 00:42:30 UTC, Walter Bright wrote:
> [...] especially if one is writing applications that
> dynamically adjusts based on the CPU the user is running on.
> The main trouble comes about when different modules are
> compiled with different settings. What happens with template
> code generation, when the templates are pulled from different
> modules? What happens when COMDAT functions are generated? (The
> linker picks one arbitrarily and discards the others.) Which
> settings wind up in the executable will be not easily
> predictable.
>
> I suspect that using a pragma would be a much better approach:
>
> pragma(SIMD, AFX)
> {
> ... code ...
> }
>
> Doing it on the command line is certainly the traditional way,
> but it strikes me as being bug-prone and as unhygienic and
> obsolete as the C preprocessor is (for similar reasons).
Have you seen how GCC's function multiversioning [1] ?
This whole thread is far too low-level for me and I'm not sure if
GCC's dispatcher overhead is OK, but the syntax looks really nice
and it seems to address all of your concerns.
__attribute__ ((target ("default")))
int foo ()
{
// The default version of foo.
return 0;
}
__attribute__ ((target ("sse4.2")))
int foo ()
{
// foo version for SSE4.2
return 1;
}
__attribute__ ((target ("arch=atom")))
int foo ()
{
// foo version for the Intel ATOM processor
return 2;
}
[1] https://gcc.gnu.org/wiki/FunctionMultiVersioning
-Alexander
More information about the Digitalmars-d
mailing list