www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.ldc - portably determine HW SIMD width

reply Bruce Carneal <bcarneal gmail.com> writes:
With dmd you can import core.simd and use a static if/else ladder 
of (is(Vector!(T[SomeSize]))) or is(ubytexx) expressions to 
determine HW SIMD widths.  This doesn't work with ldc because ldc 
is very permissive when it comes to 'SIMD' vector sizes.

I like that about LDC in most contexts but here I'm looking for a 
discriminant rather than an accommodation.  Suggestions?
Aug 27 2020
parent reply kinke <noone nowhere.com> writes:
If x86 only, the predefined versions might do it - 
`version(D_AVX2)` for 512 bit vectors (`-mattr=+avx2`), and D_AVX 
for 256 bit. There aren't other alternatives at the moment AFAIK; 
a trait might be a nice addition.
Aug 27 2020
next sibling parent kinke <noone nowhere.com> writes:
Argh scratch the AVX2 part, that's still 256 bit. There's no 
`D_AVX512` yet, but you can use something like 
`__traits(targetHasFeature, "avx512f")` (AVX512 seems to be a 
mess, not sure what the exact attr is - see `-mattr=help` output).
Aug 27 2020
prev sibling parent Bruce Carneal <bcarneal gmail.com> writes:
On Friday, 28 August 2020 at 00:19:12 UTC, kinke wrote:
 If x86 only, the predefined versions might do it - 
 `version(D_AVX2)` for 512 bit vectors (`-mattr=+avx2`), and 
 D_AVX for 256 bit. There aren't other alternatives at the 
 moment AFAIK; a trait might be a nice addition.
Thanks. I was hoping to avoid the x86 tie-in but it's certainly better than nothing.
Aug 27 2020