isOpaqueSimd
This commit is contained in:
parent
d76550052e
commit
1c6fa86ac0
|
@ -126,10 +126,7 @@ proc toPremultipliedAlpha*(data: var seq[ColorRGBA | ColorRGBX]) {.raises: [].}
|
|||
|
||||
proc isOpaque*(data: var seq[ColorRGBX], start, len: int): bool =
|
||||
when allowSimd and compiles(isOpaqueSimd):
|
||||
return isOpaqueSimd(
|
||||
cast[ptr UncheckedArray[ColorRGBX]](data[start].addr),
|
||||
len
|
||||
)
|
||||
return isOpaqueSimd(data, start, len)
|
||||
|
||||
result = true
|
||||
|
||||
|
|
|
@ -61,18 +61,19 @@ proc isTransparentAvx2*(data: ptr UncheckedArray[ColorRGBX], len: int): bool =
|
|||
if data[i].a != 0:
|
||||
return false
|
||||
|
||||
proc isOpaqueAvx2*(data: ptr UncheckedArray[ColorRGBX], len: int): bool =
|
||||
proc isOpaqueAvx2*(data: var seq[ColorRGBX], start, len: int): bool =
|
||||
result = true
|
||||
|
||||
var i: int
|
||||
while i < len and (cast[uint](data[i].addr) and 31) != 0: # Align to 32 bytes
|
||||
var i = start
|
||||
# Align to 32 bytes
|
||||
while i < (start + len) and (cast[uint](data[i].addr) and 31) != 0:
|
||||
if data[i].a != 255:
|
||||
return false
|
||||
inc i
|
||||
|
||||
let
|
||||
vec255 = mm256_set1_epi8(255)
|
||||
iterations = (len - i) div 16
|
||||
iterations = (start + len - i) div 16
|
||||
for _ in 0 ..< iterations:
|
||||
let
|
||||
values0 = mm256_load_si256(data[i].addr)
|
||||
|
@ -83,7 +84,7 @@ proc isOpaqueAvx2*(data: ptr UncheckedArray[ColorRGBX], len: int): bool =
|
|||
return false
|
||||
i += 16
|
||||
|
||||
for i in i ..< len:
|
||||
for i in i ..< start + len:
|
||||
if data[i].a != 255:
|
||||
return false
|
||||
|
||||
|
|
|
@ -130,21 +130,22 @@ when defined(amd64):
|
|||
if data[i].a != 0:
|
||||
return false
|
||||
|
||||
proc isOpaqueSimd*(data: ptr UncheckedArray[ColorRGBX], len: int): bool =
|
||||
proc isOpaqueSimd*(data: var seq[ColorRGBX], start, len: int): bool =
|
||||
if cpuHasAvx2:
|
||||
return isOpaqueAvx2(data, len)
|
||||
return isOpaqueAvx2(data, start, len)
|
||||
|
||||
result = true
|
||||
|
||||
var i: int
|
||||
while i < len and (cast[uint](data[i].addr) and 15) != 0: # Align to 16 bytes
|
||||
var i = start
|
||||
# Align to 16 bytes
|
||||
while i < (start + len) and (cast[uint](data[i].addr) and 15) != 0:
|
||||
if data[i].a != 255:
|
||||
return false
|
||||
inc i
|
||||
|
||||
let
|
||||
vec255 = mm_set1_epi8(255)
|
||||
iterations = (len - i) div 16
|
||||
iterations = (start + len - i) div 16
|
||||
for _ in 0 ..< iterations:
|
||||
let
|
||||
values0 = mm_load_si128(data[i].addr)
|
||||
|
@ -159,7 +160,7 @@ when defined(amd64):
|
|||
return false
|
||||
i += 16
|
||||
|
||||
for i in i ..< len:
|
||||
for i in i ..< start + len:
|
||||
if data[i].a != 255:
|
||||
return false
|
||||
|
||||
|
|
Loading…
Reference in a new issue