Created
March 1, 2021 18:38
-
-
Save IKoshelev/71a758afecb8ebc2bc152cb13f95f2a1 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
public static int IntrinsicTest(byte[] lhs, byte[] rhs) | |
{ | |
byte ths = 16; | |
Intrinsics.Vector128<byte> threshold = Intrinsics.Vector128.Create(ths, ths, ths, ths, ths, ths, ths, ths, ths, ths, ths, ths, ths, ths, ths, ths); | |
byte bit = 1; | |
var VECTOR_ONE = Intrinsics.Vector128.Create(bit, bit, bit, bit, bit, bit, bit, bit, bit, bit, bit, bit, bit, bit, bit, bit); | |
var result = new Intrinsics.Vector128<uint>(); | |
var i = 0; | |
for (i = 0; i <= lhs.Length - 16; i += 16) | |
{ | |
var v128a = Intrinsics.Vector128.Create( | |
lhs[i], | |
lhs[i + 1], | |
lhs[i + 2], | |
lhs[i + 3], | |
lhs[i + 4], | |
lhs[i + 5], | |
lhs[i + 6], | |
lhs[i + 7], | |
lhs[i + 8], | |
lhs[i + 9], | |
lhs[i + 10], | |
lhs[i + 11], | |
lhs[i + 12], | |
lhs[i + 13], | |
lhs[i + 14], | |
lhs[i + 15] | |
); | |
var v128b = Intrinsics.Vector128.Create( | |
rhs[i], | |
rhs[i + 1], | |
rhs[i + 2], | |
rhs[i + 3], | |
rhs[i + 4], | |
rhs[i + 5], | |
rhs[i + 6], | |
rhs[i + 7], | |
rhs[i + 8], | |
rhs[i + 9], | |
rhs[i + 10], | |
rhs[i + 11], | |
rhs[i + 12], | |
rhs[i + 13], | |
rhs[i + 14], | |
rhs[i + 15] | |
); | |
var subtracted = Intrinsics.Arm.AdvSimd.AbsoluteDifference(v128a, v128b); | |
var thresholdPassed = Intrinsics.Arm.AdvSimd.CompareGreaterThanOrEqual(subtracted, threshold); | |
var normalized = Intrinsics.Arm.AdvSimd.And(thresholdPassed, VECTOR_ONE); | |
//dot product does not work yet :-( | |
var rtemp = Intrinsics.Arm.AdvSimd.AddPairwiseWidening(normalized); | |
result = Intrinsics.Arm.AdvSimd.AddPairwiseWideningAndAdd(result, rtemp); | |
} | |
return (int)(Intrinsics.Arm.AdvSimd.Extract(result, 0) | |
+ Intrinsics.Arm.AdvSimd.Extract(result, 1) | |
+ Intrinsics.Arm.AdvSimd.Extract(result, 2) | |
+ Intrinsics.Arm.AdvSimd.Extract(result, 3)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment