core.simd ubyte16 initialization weirdness.
    realhet 
    real_het at hotmail.com
       
    Mon May  8 12:20:00 UTC 2023
    
    
  
On Monday, 8 May 2023 at 11:43:33 UTC, Richard (Rikki) Andrew 
Cattermole wrote:
> Don't forget to type bad2 which gives the same result as the 
> good one. Otherwise it only has 7 elements in it.
Thank You, now that's good too.
So here are the weird stuff:
Pure arrays produce errors:
enum ubyte16 x = [1, 2, 3]               ->  bad SSE calculation
static immutable ubyte16 x = [1, 2, 3]   ->  calculates good, but 
pragma msg crashes
And there ar 2 possible fixes:
* Send the constant array through mixin()
* Send the constant array through Phobos: For example .array or 
.dub will do.
I think I will prefer the static immutable ubyte16 way with the 
simples looking array. The pragma will crash on it, but I can 
live with that.
```
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([0, 1, 
2, 3, 4, 5, 6, 7]),
     	                     bad1                 = [0, 1, 2, 3, 4, 
5, 6, 7];
     static immutable ubyte16 good2                = iota(8).array,
     	                     goodButPragmaCrash   = [0, 1, 2, 3, 4, 
5, 6, 7],
     	                     goodAndNoPragmaCrash = [0, 1, 2, 3, 4, 
5, 6, 7].dup;
     //pragma(msg, goodButPragmaCrash);
     pragma(msg, goodAndNoPragmaCrash);
     void test(string s)(){
         mixin(q{
             writef!"%s\n%s\n%s\n\n"("$", $, pshufb(input, $));
         }.replace("$", s));
     }
     test!"good";
     test!"bad1";
     test!"good2";
     test!"goodButPragmaCrash";
     test!"goodAndNoPragmaCrash";
}
```
    
    
More information about the Digitalmars-d-learn
mailing list