internal.nim
This commit is contained in:
parent
8140326a2a
commit
5e3e489f61
4 changed files with 49 additions and 46 deletions
|
@ -35,10 +35,10 @@ type
|
||||||
bmIntersectMask
|
bmIntersectMask
|
||||||
bmExcludeMask
|
bmExcludeMask
|
||||||
|
|
||||||
Blender* = proc(backdrop, source: ColorRGBA): ColorRGBA ## Function signature
|
Blender* = proc(backdrop, source: ColorRGBA): ColorRGBA
|
||||||
## returned by blender.
|
## Function signature returned by blender.
|
||||||
Masker* = proc(backdrop, source: uint8): uint8 ## Function signature returned
|
Masker* = proc(backdrop, source: uint8): uint8
|
||||||
## by masker.
|
## Function signature returned by masker.
|
||||||
|
|
||||||
when defined(release):
|
when defined(release):
|
||||||
{.push checks: off.}
|
{.push checks: off.}
|
||||||
|
@ -515,46 +515,10 @@ when defined(amd64) and not defined(pixieNoSimd):
|
||||||
import nimsimd/sse2
|
import nimsimd/sse2
|
||||||
|
|
||||||
type
|
type
|
||||||
BlenderSimd* = proc(blackdrop, source: M128i): M128i ## Function signature
|
BlenderSimd* = proc(blackdrop, source: M128i): M128i
|
||||||
## returned by blenderSimd.
|
## Function signature returned by blenderSimd.
|
||||||
MaskerSimd* = proc(blackdrop, source: M128i): M128i ## Function signature
|
MaskerSimd* = proc(blackdrop, source: M128i): M128i
|
||||||
## returned by maskerSimd.
|
## Function signature returned by maskerSimd.
|
||||||
|
|
||||||
proc packAlphaValues*(v: M128i): M128i {.inline.} =
|
|
||||||
## Shuffle the alpha values for these 4 colors to the first 4 bytes
|
|
||||||
result = mm_srli_epi32(v, 24)
|
|
||||||
let
|
|
||||||
i = mm_srli_si128(result, 3)
|
|
||||||
j = mm_srli_si128(result, 6)
|
|
||||||
k = mm_srli_si128(result, 9)
|
|
||||||
first32 = cast[M128i]([uint32.high, 0, 0, 0])
|
|
||||||
result = mm_or_si128(mm_or_si128(result, i), mm_or_si128(j, k))
|
|
||||||
result = mm_and_si128(result, first32)
|
|
||||||
|
|
||||||
proc unpackAlphaValues*(v: M128i): M128i {.inline.} =
|
|
||||||
## Unpack the first 32 bits into 4 rgba(0, 0, 0, value)
|
|
||||||
let
|
|
||||||
first32 = cast[M128i]([uint32.high, 0, 0, 0]) # First 32 bits
|
|
||||||
alphaMask = mm_set1_epi32(cast[int32](0xff000000)) # Only `a`
|
|
||||||
|
|
||||||
result = mm_shuffle_epi32(v, MM_SHUFFLE(0, 0, 0, 0))
|
|
||||||
|
|
||||||
var
|
|
||||||
i = mm_and_si128(result, first32)
|
|
||||||
j = mm_and_si128(result, mm_slli_si128(first32, 4))
|
|
||||||
k = mm_and_si128(result, mm_slli_si128(first32, 8))
|
|
||||||
l = mm_and_si128(result, mm_slli_si128(first32, 12))
|
|
||||||
|
|
||||||
# Shift the values to `a`
|
|
||||||
i = mm_slli_si128(i, 3)
|
|
||||||
j = mm_slli_si128(j, 2)
|
|
||||||
k = mm_slli_si128(k, 1)
|
|
||||||
# l = mm_slli_si128(l, 0)
|
|
||||||
|
|
||||||
result = mm_and_si128(
|
|
||||||
mm_or_si128(mm_or_si128(i, j), mm_or_si128(k, l)),
|
|
||||||
alphaMask
|
|
||||||
)
|
|
||||||
|
|
||||||
proc blendNormalSimd(backdrop, source: M128i): M128i =
|
proc blendNormalSimd(backdrop, source: M128i): M128i =
|
||||||
let
|
let
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import blends, bumpy, chroma, common, masks, system/memory, vmath
|
import blends, bumpy, chroma, common, masks, pixie/internal, system/memory, vmath
|
||||||
|
|
||||||
when defined(amd64) and not defined(pixieNoSimd):
|
when defined(amd64) and not defined(pixieNoSimd):
|
||||||
import nimsimd/sse2
|
import nimsimd/sse2
|
||||||
|
|
38
src/pixie/internal.nim
Normal file
38
src/pixie/internal.nim
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
when defined(amd64) and not defined(pixieNoSimd):
|
||||||
|
import nimsimd/sse2
|
||||||
|
|
||||||
|
proc packAlphaValues*(v: M128i): M128i {.inline.} =
|
||||||
|
## Shuffle the alpha values for these 4 colors to the first 4 bytes
|
||||||
|
result = mm_srli_epi32(v, 24)
|
||||||
|
let
|
||||||
|
i = mm_srli_si128(result, 3)
|
||||||
|
j = mm_srli_si128(result, 6)
|
||||||
|
k = mm_srli_si128(result, 9)
|
||||||
|
first32 = cast[M128i]([uint32.high, 0, 0, 0])
|
||||||
|
result = mm_or_si128(mm_or_si128(result, i), mm_or_si128(j, k))
|
||||||
|
result = mm_and_si128(result, first32)
|
||||||
|
|
||||||
|
proc unpackAlphaValues*(v: M128i): M128i {.inline.} =
|
||||||
|
## Unpack the first 32 bits into 4 rgba(0, 0, 0, value)
|
||||||
|
let
|
||||||
|
first32 = cast[M128i]([uint32.high, 0, 0, 0]) # First 32 bits
|
||||||
|
alphaMask = mm_set1_epi32(cast[int32](0xff000000)) # Only `a`
|
||||||
|
|
||||||
|
result = mm_shuffle_epi32(v, MM_SHUFFLE(0, 0, 0, 0))
|
||||||
|
|
||||||
|
var
|
||||||
|
i = mm_and_si128(result, first32)
|
||||||
|
j = mm_and_si128(result, mm_slli_si128(first32, 4))
|
||||||
|
k = mm_and_si128(result, mm_slli_si128(first32, 8))
|
||||||
|
l = mm_and_si128(result, mm_slli_si128(first32, 12))
|
||||||
|
|
||||||
|
# Shift the values to `a`
|
||||||
|
i = mm_slli_si128(i, 3)
|
||||||
|
j = mm_slli_si128(j, 2)
|
||||||
|
k = mm_slli_si128(k, 1)
|
||||||
|
# l = mm_slli_si128(l, 0)
|
||||||
|
|
||||||
|
result = mm_and_si128(
|
||||||
|
mm_or_si128(mm_or_si128(i, j), mm_or_si128(k, l)),
|
||||||
|
alphaMask
|
||||||
|
)
|
|
@ -1,4 +1,5 @@
|
||||||
import blends, bumpy, chroma, common, images, masks, paints, strutils, vmath
|
import blends, bumpy, chroma, common, images, masks, paints, pixie/internal,
|
||||||
|
strutils, vmath
|
||||||
|
|
||||||
when defined(amd64) and not defined(pixieNoSimd):
|
when defined(amd64) and not defined(pixieNoSimd):
|
||||||
import nimsimd/sse2
|
import nimsimd/sse2
|
||||||
|
|
Loading…
Reference in a new issue