From aaead7ed8425dbfd44b48fbe81e0b8ea4a9dd241 Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Thu, 30 Jun 2022 09:34:01 -0500 Subject: [PATCH] f --- src/pixie/internal.nim | 6 +++--- src/pixie/runtimechecked/avx.nim | 4 +++- src/pixie/simd.nim | 8 +++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/pixie/internal.nim b/src/pixie/internal.nim index 2524847..c7720d9 100644 --- a/src/pixie/internal.nim +++ b/src/pixie/internal.nim @@ -79,16 +79,16 @@ proc fillUnsafe*( ) {.raises: [].} = ## Fills the image data with the color starting at index start and ## continuing for len indices. - let rgbx = color.asRgbx() - when allowSimd and compiles(fillUnsafeSimd): fillUnsafeSimd( cast[ptr UncheckedArray[ColorRGBX]](data[start].addr), len, - rgbx + color ) return + let rgbx = color.asRgbx() + # Use memset when every byte has the same value if rgbx.r == rgbx.g and rgbx.r == rgbx.b and rgbx.r == rgbx.a: nimSetMem(data[start].addr, rgbx.r.cint, len * 4) diff --git a/src/pixie/runtimechecked/avx.nim b/src/pixie/runtimechecked/avx.nim index cb6d8e0..1b7f271 100644 --- a/src/pixie/runtimechecked/avx.nim +++ b/src/pixie/runtimechecked/avx.nim @@ -9,8 +9,10 @@ when defined(release): proc fillUnsafeAvx*( data: ptr UncheckedArray[ColorRGBX], len: int, - rgbx: ColorRGBX + color: SomeColor ) = + let rgbx = color.asRgbx() + var i: int while i < len and (cast[uint](data[i].addr) and 31) != 0: # Align to 32 bytes data[i] = rgbx diff --git a/src/pixie/simd.nim b/src/pixie/simd.nim index d789bdf..359da3f 100644 --- a/src/pixie/simd.nim +++ b/src/pixie/simd.nim @@ -1,4 +1,4 @@ -import chroma, vmath +import chroma when defined(release): {.push checks: off.} @@ -33,11 +33,13 @@ when defined(amd64): proc fillUnsafeSimd*( data: ptr UncheckedArray[ColorRGBX], len: int, - rgbx: ColorRGBX + color: SomeColor ) = if cpuHasAvx and len >= 64: - fillUnsafeAvx(data, len, rgbx) + fillUnsafeAvx(data, len, color) else: + let rgbx = color.asRgbx() + var i: int while i < len and (cast[uint](data[i].addr) and 15) != 0: # Align to 16 bytes data[i] = rgbx