Port SequenceEqual to crossplat Vectors, optimize vector compare on x64 #67202
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR does:
SequenceEqualto use cross-plat vectorsvec1 == vec2with xor+vptest if available:codegen diff:
; Method Proga:Test G_M56888_IG01: vzeroupper G_M56888_IG02: vmovupd xmm0, xmmword ptr [rdx] - vpcmpeqd xmm0, xmm0, xmmword ptr [r8] - vpmovmskb eax, xmm0 - cmp eax, 0xFFFF + vpxor xmm0, xmm0, xmmword ptr [r8] + vptest xmm0, xmm0 sete al movzx rax, al G_M56888_IG03: ret -; Total bytes of code: 28 +; Total bytes of code: 24 ; Method Proga:Test G_M5176_IG01: vzeroupper G_M5176_IG02: vmovupd ymm0, ymmword ptr[rdx] - vpcmpeqd ymm0, ymm0, ymmword ptr[r8] - vpmovmskb eax, ymm0 - cmp eax, -1 + vpxor ymm0, ymm0, ymmword ptr[r8] + vptest ymm0, ymm0 sete al movzx rax, al G_M5176_IG03: vzeroupper ret -; Total bytes of code: 29 +; Total bytes of code: 27However, it seems like in some cases/on some CPUs movmsk is faster 🤔
cc @tannergooding
PS: seems like the main loop in
SequenceEqualis not properly aligned and hits JCC erratum each iteration