Thread overview | |||||
---|---|---|---|---|---|
|
July 22, 2020 Templates and SIMD - examining types | ||||
---|---|---|---|---|
| ||||
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. |
July 22, 2020 Re: Templates and SIMD - examining types | ||||
---|---|---|---|---|
| ||||
Posted in reply to Cecil Ward | 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
|
July 28, 2020 Re: Templates and SIMD - examining types | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dennis | 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 :-)
|
Copyright © 1999-2021 by the D Language Foundation