I wonder how it would be possible to replace byte values in a Vector128<byte>
I think it is okay to assume the code below where we have a resultvector
with
those values :
<0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0>
Here I like to create a new vector where all "0" will be replaced with "2" and all "1" will be replaced with "0" like this : <2,2,2,2,0,0,0,0,2,2,2,2,2,2,2,2>
I am not sure if there is an intrinsics for this or how to achieve this?
Thank you!
//Create array
byte[] array = new byte[16];
for (int i = 0; i < 4; i++) { array[i] = 0; }
for (int i = 4; i < 8; i++) { array[i] = 1; }
for (int i = 8; i < 16; i++) { array[i] = 0; }
fixed (byte* ptr = array)
{
byte* pointarray = &*((byte*)(ptr + 0));
System.Runtime.Intrinsics.Vector128<byte> resultvector = System.Runtime.Intrinsics.X86.Avx.LoadVector128(&pointarray[0]);
//<0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0>
//resultvector
}
2-(resultvector<<1)
(if shifts are not possible, just add to itself). But how did you actually computeresultvector
? (If you are able to modify that calculation, there could be more efficient ways). - chtzresultvector
. I am not sure what this means:2-(resultvector<<1)
? I use C#. - Andreas<<
is the shift operator. I'm not very familiar with C# so I don't know if it allows that on SIMD types (or if C# overloads operators for SIMD types ...). Essentially you need to calculate2-(a[i]+a[i])
for each element (for which there must be a way with just two SIMD instructions). - chtzresultvector
". If your code was how you actually calculate it, just replacearray[i]=0;
byarray[i]=2;
andarray[i]=1;
byarray[i]=0
(I'm sure this is not what you need ...). - chtz<<
is possible to use. I have never seen that one to be used in C#. I think it is not possible. I beleive there must be some kind of SIMD instruction in C# to use somehow, I hope. - Andreas