Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Benchmark]
- public unsafe bool Intrinsics() {
- const int vectorSize = 256 / 8;
- int i = 0;
- var arrayA = ArrayA;
- var arrayB = ArrayB;
- int length = arrayA.Length;
- fixed (byte* ptrA = arrayA)
- fixed (byte* ptrB = arrayB) {
- int l = length - vectorSize;
- for (; i <= l; i += vectorSize) {
- if (Avx2.MoveMask(Avx2.CompareEqual(Avx2.LoadVector256(ptrA + i), Avx2.LoadVector256(ptrB + i))) != unchecked((int) 0b11111111111111111111111111111111)) {
- return false;
- }
- }
- int rem = length - i;
- if (rem >=24) {
- if (*(long*) (ptrA + i) != *(long*) (ptrB + i) || *(long*) (ptrA + i + 8) != *(long*) (ptrB + i + 8) || *(long*) (ptrA + i + 16) != *(long*) (ptrB + i + 16)) {
- return false;
- }
- i += 24;
- } else if (rem >= 16) {
- if (*(long*) (ptrA + i) != *(long*) (ptrB + i) || *(long*) (ptrA + i + 8) != *(long*) (ptrB + i + 8)) {
- return false;
- }
- i += 16;
- }
- else if (rem >= 8) {
- if (*(long*) (ptrA + i) != *(long*) (ptrB + i)) {
- return false;
- }
- i += 8;
- }
- for (;i < length; i++) {
- if (arrayA[i] != arrayB[i]) {
- return false;
- }
- }
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement