This commit is contained in:
Ryan Oldenburg 2021-06-19 18:50:33 -05:00
parent 75acaf0105
commit ac1bd9e64c

View file

@ -95,25 +95,18 @@ when defined(amd64) and not defined(pixieNoSimd):
proc unpackAlphaValues*(v: M128i): M128i {.inline.} =
## Unpack the first 32 bits into 4 rgba(0, 0, 0, value)
let
first32 = cast[M128i]([uint32.high, 0, 0, 0]) # First 32 bits
alphaMask = mm_set1_epi32(cast[int32](0xff000000)) # Only `a`
result = mm_shuffle_epi32(v, MM_SHUFFLE(0, 0, 0, 0))
let mask = cast[M128i]([uint8.high.uint64, 0])
var
i = mm_and_si128(result, first32)
j = mm_and_si128(result, mm_slli_si128(first32, 4))
k = mm_and_si128(result, mm_slli_si128(first32, 8))
l = mm_and_si128(result, mm_slli_si128(first32, 12))
i = mm_and_si128(v, mask)
j = mm_and_si128(v, mm_slli_si128(mask, 1))
k = mm_and_si128(v, mm_slli_si128(mask, 2))
l = mm_and_si128(v, mm_slli_si128(mask, 3))
# Shift the values to `a`
# Shift the values to uint32 `a`
i = mm_slli_si128(i, 3)
j = mm_slli_si128(j, 2)
k = mm_slli_si128(k, 1)
# l = mm_slli_si128(l, 0)
j = mm_slli_si128(j, 6)
k = mm_slli_si128(k, 9)
l = mm_slli_si128(l, 12)
result = mm_and_si128(
mm_or_si128(mm_or_si128(i, j), mm_or_si128(k, l)),
alphaMask
)
result = mm_or_si128(mm_or_si128(i, j), mm_or_si128(k, l))