This commit is contained in:
Ryan Oldenburg 2022-06-20 22:00:20 -05:00
parent 14576fcd27
commit 3c769291af

View file

@ -108,15 +108,20 @@ proc isOneColor*(image: Image): bool {.raises: [].} =
var i: int var i: int
when defined(amd64) and allowSimd: when defined(amd64) and allowSimd:
let colorVec = mm_set1_epi32(cast[int32](color)) let colorVec = mm_set1_epi32(cast[int32](color))
for _ in 0 ..< image.data.len div 8: for _ in 0 ..< image.data.len div 16:
let let
values0 = mm_loadu_si128(image.data[i + 0].addr) values0 = mm_loadu_si128(image.data[i + 0].addr)
values1 = mm_loadu_si128(image.data[i + 4].addr) values1 = mm_loadu_si128(image.data[i + 4].addr)
mask0 = mm_movemask_epi8(mm_cmpeq_epi8(values0, colorVec)) values2 = mm_loadu_si128(image.data[i + 8].addr)
mask1 = mm_movemask_epi8(mm_cmpeq_epi8(values1, colorVec)) values3 = mm_loadu_si128(image.data[i + 12].addr)
if mask0 != 0xffff or mask1 != 0xffff: eq0 = mm_cmpeq_epi8(values0, colorVec)
eq1 = mm_cmpeq_epi8(values1, colorVec)
eq2 = mm_cmpeq_epi8(values2, colorVec)
eq3 = mm_cmpeq_epi8(values3, colorVec)
eq = mm_and_si128(mm_and_si128(eq0, eq1), mm_and_si128(eq2, eq3))
if mm_movemask_epi8(eq) != 0xffff:
return false return false
i += 8 i += 16
for j in i ..< image.data.len: for j in i ..< image.data.len:
if image.data[j] != color: if image.data[j] != color: