Created
December 19, 2017 19:05
-
-
Save RedBeard0531/2ee8a18ba3fb354557f7f113ca39d732 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
when defined(useSSE42): | |
import x86_simd/x86_sse42 | |
import x86_simd/x86_sse41 | |
import x86_simd/x86_sse2 | |
import bitops | |
let prStr = "azAZ09\x80\xFF\0 " # padded to hold at least 16 bytes. | |
let pcStr = "+,/_:.~()}{@=!-\0 " | |
let plain_ranges = loadu_si128(cast[ptr m128i](unsafeAddr prStr[0])) | |
let plain_chars = loadu_si128(cast[ptr m128i](unsafeAddr pcStr[0])) | |
#... | |
while true: | |
let c = s[i] | |
inc i | |
case c | |
of plain: | |
let begin = i-1 | |
block findPlainRange: | |
when defined(useSSE42): | |
if s.len-i >= 16: | |
while s.len-i >= 16: | |
let vec = loadu_si128(cast[ptr m128i](unsafeAddr s[i])) | |
const commonFlags = SIDD_NEGATIVE_POLARITY or SIDD_UNIT_MASK | |
let rMask = cmpistrm(plain_ranges, vec, SIDD_CMP_RANGES or commonFlags) | |
let pMask = cmpistrm(plain_chars, vec, SIDD_CMP_EQUAL_ANY or commonFlags) | |
if not testz_si128(rMask, pMask).bool: | |
let mask = and_si128(rMask, pMask) | |
let bits = movemask_epi8(mask) | |
i += bits.countTrailingZeroBits | |
break findPlainRange | |
i += 16 | |
while s[i] in plain: inc i | |
curStr &= s[begin..<i] | |
#... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment