-
Notifications
You must be signed in to change notification settings - Fork 368
Open
Description
At the end of lesson 3, the following code is given as being analogous to pshufb:
for(int i = 0; i < 16; i++) {
if(src[i] & 0x80)
dst[i] = 0;
else
dst[i] = dst[src[i]]
}This code is not analogous because it overwrites dst while looping. If you try swapping two bytes, the second byte will just use its own value that was swapped to the first byte earlier. Example:
/* not 16 bytes but just pretend */
dst = { 4, 8, 12 };
src = { -1, 2, 1 };
shuffle();
/* dst is now { 0, 12, 12 } when it should be { 0, 12, 8 } instead */"although in SIMD all 16 loop iterations happen in parallel" may have been an attempt to address this, but I feel like it should be made clearer that this code does not work properly when ran normally.
The easiest way to address this would be to copy the contents of dst to a temporary variable and use that instead of dst when assigning in the loop.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels