Any usable SIMD implementation?
Marco Leise via Digitalmars-d
digitalmars-d at puremagic.com
Tue Apr 12 10:19:00 PDT 2016
Am Tue, 12 Apr 2016 10:55:18 +0000
schrieb xenon325 <anm at programmer.net>:
> 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;
> }
>
>
> [1] https://gcc.gnu.org/wiki/FunctionMultiVersioning
>
> -Alexander
Awesome! I just tried it and it ties runtime and compile-time
selection of code paths together in an unprecedented way!
As you said, there is the runtime dispatcher overhead if you
just compile normally. But if you specifically compile with
"gcc -msse4.2 <…>", GCC calls the correct function directly:
0000000000400512 <main>:
400512: e8 f5 ff ff ff callq 40050c <_Z3foov.sse4.2>
400517: f3 c3 repz retq
400519: 0f 1f 80 00 00 00 00 nopl 0x0(%rax)
For demonstration purposes I disabled the inliner here.
The best thing about it is that for users of libraries
employing this technique, it happens behind the scenes and user
code stays clean of instrumentation. No ugly versioning and
hand written switch-case blocks! (It currently only works with
C++ on x86, but I like the general direction.)
--
Marco
More information about the Digitalmars-d
mailing list