www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Templates and SIMD - examining types

reply Cecil Ward <cecil cecilward.com> writes:
I am using SIMD and I have a case in a template where I am being 
passed an argument that is a pointer to a 128-bit chunk of either 
16 bytes or 8 uwords but I don’t know which? What’s the best way 
to discover this at compile time - using the ‘is’ operator ? I 
forget for the moment. It will only ever be either a ubyte16 or a 
ushort8 (if those are the correct type names)? I’ll exclude other 
possibilities with an if qualifier on the template (somehow).

I need to then work out what is the size of the internal units 
within the 128-bit value, size in bytes,1 or 2, at compile time.
Jul 22 2020
parent reply Dennis <dkorpel gmail.com> writes:
On Wednesday, 22 July 2020 at 21:58:16 UTC, Cecil Ward wrote:
 I need to then work out what is the size of the internal units 
 within the 128-bit value, size in bytes,1 or 2, at compile time.
You can use the .sizeof property on the type. ``` import core.simd; void main() { ubyte16 a; ushort8 b; pragma(msg, a.sizeof); pragma(msg, b.sizeof); pragma(msg, a[0].sizeof); pragma(msg, b[0].sizeof); pragma(msg, typeof(a[0])); pragma(msg, typeof(b[0])); } ``` 16LU 16LU 1LU 2LU ubyte ushort
Jul 22 2020
parent Cecil Ward <cecil cecilward.com> writes:
On Wednesday, 22 July 2020 at 22:21:47 UTC, Dennis wrote:
 On Wednesday, 22 July 2020 at 21:58:16 UTC, Cecil Ward wrote:
 I need to then work out what is the size of the internal units 
 within the 128-bit value, size in bytes,1 or 2, at compile 
 time.
You can use the .sizeof property on the type. ``` import core.simd; void main() { ubyte16 a; ushort8 b; pragma(msg, a.sizeof); pragma(msg, b.sizeof); pragma(msg, a[0].sizeof); pragma(msg, b[0].sizeof); pragma(msg, typeof(a[0])); pragma(msg, typeof(b[0])); } ``` 16LU 16LU 1LU 2LU ubyte ushort
Brilliant. I am sooo stupid, I forgot you can access SIMD variables like normal arrays. Thank you for waking me up again :-)
Jul 27 2020