Handle the remainder in MemoryExtensions.Count vectorized (#82687)
authorGünther Foidl <gue@korporal.at>
Mon, 15 May 2023 22:06:22 +0000 (00:06 +0200)
committerGitHub <noreply@github.com>
Mon, 15 May 2023 22:06:22 +0000 (18:06 -0400)
commit50d4ecb73508223ea80339cb278b3abdc8d4e236
treecd7d9fb91559a2cd579ce26656ef57f2805b42a9
parent31658c683e225446c0b45e4c13bded81469cb26d
Handle the remainder in MemoryExtensions.Count vectorized (#82687)

* Re-use targetVector from Vector256 in Vector128 code-path

Saves an additional vpbroadcastb.

* Process remainder vectorized

* Use unsigned division for remaining elements

Avoids the signed integer division.

* Process remainder vectorized only if more than half of vector remains

Benchmarking showed that the cost is quite high, so for just a few elements the scalar loop seems better.

* Added comment why / 2 got chosen
src/libraries/System.Private.CoreLib/src/System/SpanHelpers.T.cs