core.simd ubyte16 initialization weirdness.

realhet real_het at hotmail.com
Mon May 8 11:01:53 UTC 2023


On Monday, 8 May 2023 at 08:05:13 UTC, Richard (Rikki) Andrew 
Cattermole wrote:

Yes, there is a pragma msg bug, but there is also a functionality 
'bug'.

I collected some more info:

```
import std, core.simd, ldc.llvmasm;

T pshufb(T, U)(T a, in U b) { return __asm!ubyte16("pshufb $2, 
$1", "=x,0,x", a, b); }

void main()
{
     enum ubyte16
         input = mixin(iota(100, 116).array),
         good = mixin([1, 2, 3, 4, 5, 6, 7]),
     	bad1 = [1, 2, 3, 4, 5, 6, 7];
     static immutable
     	bad2 = [1, 2, 3, 4, 5, 6, 7];

     //pragma(msg, somewhat_good); <-crash

	writeln(good);
     writeln(pshufb(input, good));
     writeln;
     writeln(bad1);
     writeln(pshufb(input, bad1));
     writeln;
     writeln(bad2);
     writeln(pshufb(input, bad2));
}

[1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[101, 102, 103, 104, 105, 106, 107, 100, 100, 100, 100, 100, 100, 
100, 100, 100]

[1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 
100, 100, 100]

[1, 2, 3, 4, 5, 6, 7]
[107, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 
100, 100, 100]
```

In the declaration of pshufb I let anything pass through to the 
__asm statement.

Only the   enum ubyte16 = mixin(...);   variant calculates the 
correct results, and luckily that can accept iota... calculated 
inputs as well.

But at this point I have to memorize this and be aware when I'm 
having weird results.


After all, this is the best SSE assembler I ever used so far *big 
thumbs up*. I like that I don't even have to allocate registers 
manually.


More information about the Digitalmars-d-learn mailing list