Stay in vectors longer before doing a horizontal sum

This commit is contained in:
David Smith
2022-03-18 12:38:53 -07:00
parent f2ce515662
commit dbaada435c

View File

@@ -533,14 +533,18 @@ extension String.UTF16View {
//Find the number of continuations (0b10xxxxxx)
let sValue = Builtin.loadRaw(readPtr._rawValue) as S
let continuations = S.zero.replacing(with: S.one, where: sValue .< -65 + 1)
let continuationCount = Int(continuations.wrappedSum())
//Find the number of 4 byte code points (0b11110xxx)
let uValue = Builtin.loadRaw(readPtr._rawValue) as U
let fourBytes = U.zero.replacing(with: U.one, where: uValue .>= 0b11110000)
let fourByteCount = Int(fourBytes.wrappedSum())
utf16Count &+= (U.scalarCount - continuationCount) + fourByteCount
let fourBytes = S.zero.replacing(
with: S.one,
where: unsafeBitCast(
uValue .>= 0b11110000,
to: SIMDMask<S.MaskStorage>.self
)
)
utf16Count &+= U.scalarCount + Int((fourBytes &- continuations).wrappedSum())
readPtr += MemoryLayout<U>.stride
}