f
This commit is contained in:
parent
fc9ab2b5f3
commit
aaead7ed84
3 changed files with 11 additions and 7 deletions
|
@ -79,16 +79,16 @@ proc fillUnsafe*(
|
||||||
) {.raises: [].} =
|
) {.raises: [].} =
|
||||||
## Fills the image data with the color starting at index start and
|
## Fills the image data with the color starting at index start and
|
||||||
## continuing for len indices.
|
## continuing for len indices.
|
||||||
let rgbx = color.asRgbx()
|
|
||||||
|
|
||||||
when allowSimd and compiles(fillUnsafeSimd):
|
when allowSimd and compiles(fillUnsafeSimd):
|
||||||
fillUnsafeSimd(
|
fillUnsafeSimd(
|
||||||
cast[ptr UncheckedArray[ColorRGBX]](data[start].addr),
|
cast[ptr UncheckedArray[ColorRGBX]](data[start].addr),
|
||||||
len,
|
len,
|
||||||
rgbx
|
color
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
let rgbx = color.asRgbx()
|
||||||
|
|
||||||
# Use memset when every byte has the same value
|
# Use memset when every byte has the same value
|
||||||
if rgbx.r == rgbx.g and rgbx.r == rgbx.b and rgbx.r == rgbx.a:
|
if rgbx.r == rgbx.g and rgbx.r == rgbx.b and rgbx.r == rgbx.a:
|
||||||
nimSetMem(data[start].addr, rgbx.r.cint, len * 4)
|
nimSetMem(data[start].addr, rgbx.r.cint, len * 4)
|
||||||
|
|
|
@ -9,8 +9,10 @@ when defined(release):
|
||||||
proc fillUnsafeAvx*(
|
proc fillUnsafeAvx*(
|
||||||
data: ptr UncheckedArray[ColorRGBX],
|
data: ptr UncheckedArray[ColorRGBX],
|
||||||
len: int,
|
len: int,
|
||||||
rgbx: ColorRGBX
|
color: SomeColor
|
||||||
) =
|
) =
|
||||||
|
let rgbx = color.asRgbx()
|
||||||
|
|
||||||
var i: int
|
var i: int
|
||||||
while i < len and (cast[uint](data[i].addr) and 31) != 0: # Align to 32 bytes
|
while i < len and (cast[uint](data[i].addr) and 31) != 0: # Align to 32 bytes
|
||||||
data[i] = rgbx
|
data[i] = rgbx
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import chroma, vmath
|
import chroma
|
||||||
|
|
||||||
when defined(release):
|
when defined(release):
|
||||||
{.push checks: off.}
|
{.push checks: off.}
|
||||||
|
@ -33,11 +33,13 @@ when defined(amd64):
|
||||||
proc fillUnsafeSimd*(
|
proc fillUnsafeSimd*(
|
||||||
data: ptr UncheckedArray[ColorRGBX],
|
data: ptr UncheckedArray[ColorRGBX],
|
||||||
len: int,
|
len: int,
|
||||||
rgbx: ColorRGBX
|
color: SomeColor
|
||||||
) =
|
) =
|
||||||
if cpuHasAvx and len >= 64:
|
if cpuHasAvx and len >= 64:
|
||||||
fillUnsafeAvx(data, len, rgbx)
|
fillUnsafeAvx(data, len, color)
|
||||||
else:
|
else:
|
||||||
|
let rgbx = color.asRgbx()
|
||||||
|
|
||||||
var i: int
|
var i: int
|
||||||
while i < len and (cast[uint](data[i].addr) and 15) != 0: # Align to 16 bytes
|
while i < len and (cast[uint](data[i].addr) and 15) != 0: # Align to 16 bytes
|
||||||
data[i] = rgbx
|
data[i] = rgbx
|
||||||
|
|
Loading…
Reference in a new issue