From e107f85fb008c9f391ed675d68d1cc09fe9fdd1a Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Sun, 31 Jul 2022 17:16:35 -0500 Subject: [PATCH] check bounds when aligning --- src/pixie/paths.nim | 8 ++------ src/pixie/simd/avx2.nim | 8 ++++---- src/pixie/simd/sse2.nim | 22 +++++++++------------- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/pixie/paths.nim b/src/pixie/paths.nim index 7c9bf0c..e738e54 100644 --- a/src/pixie/paths.nim +++ b/src/pixie/paths.nim @@ -1448,9 +1448,7 @@ proc blendLineCoverageNormal( ) {.hasSimd.} = for i in 0 ..< len: let coverage = coverages[i] - if coverage == 255 and rgbx.a == 255: - line[i] = rgbx - elif coverage == 0: + if coverage == 0: discard else: line[i] = blendNormal(line[i], rgbx * coverage) @@ -1463,9 +1461,7 @@ proc blendLineCoverageMask( ) {.hasSimd.} = for i in 0 ..< len: let coverage = coverages[i] - if coverage == 0: - line[i] = rgbx(0, 0, 0, 0) - elif coverage == 255: + if coverage == 255: discard else: line[i] = blendMask(line[i], rgbx * coverage) diff --git a/src/pixie/simd/avx2.nim b/src/pixie/simd/avx2.nim index 5ef6591..97807c3 100644 --- a/src/pixie/simd/avx2.nim +++ b/src/pixie/simd/avx2.nim @@ -419,7 +419,7 @@ proc blendLineNormalAvx2*( line: ptr UncheckedArray[ColorRGBX], rgbx: ColorRGBX, len: int ) {.simd.} = var i: int - while (cast[uint](line[i].addr) and 31) != 0: + while i < len and (cast[uint](line[i].addr) and 31) != 0: line[i] = blendNormal(line[i], rgbx) inc i @@ -445,7 +445,7 @@ proc blendLineNormalAvx2*( a, b: ptr UncheckedArray[ColorRGBX], len: int ) {.simd.} = var i: int - while (cast[uint](a[i].addr) and 31) != 0: + while i < len and (cast[uint](a[i].addr) and 31) != 0: a[i] = blendNormal(a[i], b[i]) inc i @@ -477,7 +477,7 @@ proc blendLineMaskAvx2*( line: ptr UncheckedArray[ColorRGBX], rgbx: ColorRGBX, len: int ) {.simd.} = var i: int - while (cast[uint](line[i].addr) and 31) != 0: + while i < len and (cast[uint](line[i].addr) and 31) != 0: line[i] = blendMask(line[i], rgbx) inc i @@ -502,7 +502,7 @@ proc blendLineMaskAvx2*( a, b: ptr UncheckedArray[ColorRGBX], len: int ) {.simd.} = var i: int - while (cast[uint](a[i].addr) and 31) != 0: + while i < len and (cast[uint](a[i].addr) and 31) != 0: a[i] = blendMask(a[i], b[i]) inc i diff --git a/src/pixie/simd/sse2.nim b/src/pixie/simd/sse2.nim index e8fd2f7..df849dd 100644 --- a/src/pixie/simd/sse2.nim +++ b/src/pixie/simd/sse2.nim @@ -538,7 +538,7 @@ proc blendLineCoverageOverwriteSse2*( len: int ) {.simd.} = var i: int - while (cast[uint](line[i].addr) and 15) != 0: + while i < len and (cast[uint](line[i].addr) and 15) != 0: let coverage = coverages[i] if coverage != 0: line[i] = rgbx * coverage @@ -575,7 +575,7 @@ proc blendLineNormalSse2*( line: ptr UncheckedArray[ColorRGBX], rgbx: ColorRGBX, len: int ) {.simd.} = var i: int - while (cast[uint](line[i].addr) and 15) != 0: + while i < len and (cast[uint](line[i].addr) and 15) != 0: line[i] = blendNormal(line[i], rgbx) inc i @@ -597,7 +597,7 @@ proc blendLineNormalSse2*( a, b: ptr UncheckedArray[ColorRGBX], len: int ) {.simd.} = var i: int - while (cast[uint](a[i].addr) and 15) != 0: + while i < len and (cast[uint](a[i].addr) and 15) != 0: a[i] = blendNormal(a[i], b[i]) inc i @@ -628,11 +628,9 @@ proc blendLineCoverageNormalSse2*( len: int ) {.simd.} = var i: int - while (cast[uint](line[i].addr) and 15) != 0: + while i < len and (cast[uint](line[i].addr) and 15) != 0: let coverage = coverages[i] - if coverage == 255 and rgbx.a == 255: - line[i] = rgbx - elif coverage == 0: + if coverage == 0: discard else: line[i] = blendNormal(line[i], rgbx * coverage) @@ -669,9 +667,7 @@ proc blendLineCoverageNormalSse2*( for i in i ..< len: let coverage = coverages[i] - if coverage == 255 and rgbx.a == 255: - line[i] = rgbx - elif coverage == 0: + if coverage == 0: discard else: line[i] = blendNormal(line[i], rgbx * coverage) @@ -680,7 +676,7 @@ proc blendLineMaskSse2*( line: ptr UncheckedArray[ColorRGBX], rgbx: ColorRGBX, len: int ) {.simd.} = var i: int - while (cast[uint](line[i].addr) and 15) != 0: + while i < len and (cast[uint](line[i].addr) and 15) != 0: line[i] = blendMask(line[i], rgbx) inc i @@ -701,7 +697,7 @@ proc blendLineMaskSse2*( a, b: ptr UncheckedArray[ColorRGBX], len: int ) {.simd.} = var i: int - while (cast[uint](a[i].addr) and 15) != 0: + while i < len and (cast[uint](a[i].addr) and 15) != 0: a[i] = blendMask(a[i], b[i]) inc i @@ -731,7 +727,7 @@ proc blendLineCoverageMaskSse2*( len: int ) {.simd.} = var i: int - while (cast[uint](line[i].addr) and 15) != 0: + while i < len and (cast[uint](line[i].addr) and 15) != 0: let coverage = coverages[i] if coverage == 0: line[i] = rgbx(0, 0, 0, 0)