System.Numerics.Vector.GreaterThan and bool results



我正在尝试转换一些可以使用 SIMD 指令进行优化的现有代码。我正在测试转换 SIMD 后可以从 SIMD 中获得多少性能,下面是我用来分析它的过于简化的块。

Random r = new Random();
var random1 = new double[65536000*4];
var random2 = new double[random1.Length];
var result = new bool[random1.Length];
for (i = 0; i < random1.Length; i++)
{
random1[i] = r.Next();
random2[i] = r.Next();
}
var longRes = new long[random1.Length];
for (int i = 0; i < result.Length; i += Vector<double>.Count)
{
Vector<double> v1 = new Vector<double>(random1, i);
Vector<double> v2 = new Vector<double>(random2, i);
Vector<long> res = System.Numerics.Vector.GreaterThan(v1, v2);
res.CopyTo(longRes, i);
}

是否有一种技术可以用来有效地将结果res放入result数组中?

最初我以为我可以忍受Vector<long>并把口罩放在long[]但我意识到这也许是不可行的。

正如对原始问题的评论,我意识到System.Numberics.Vector.GreaterThan和其他类似的方法(如LesserThan等(是为与ConditionalSelect()一起使用而设计的。

就我而言,我试图生成一个表示图像掩码的bool数组,该图像掩码稍后在整个 API 中使用,将长整型转换为布尔值是不可行的。

换句话说,这些比较方法并不是为了通用。

最新更新