c# - Intrinsics - 只获取所有匹配的索引
问题描述
我正在比较两个向量using System.Runtime.Intrinsics
,并想知道仅获取所有匹配索引的最快方法。
目前我的代码如下所示:
static void CompareVectors(Vector128<byte> first, Vector128<byte> second)
{
var matches = Avx2.MoveMask(Avx2.CompareEqual(first, second));
if (matches == 0) return;
var firstIndex = BitOps.TrailingZeroCount(matches) / sizeof(byte);
for (var j = firstIndex; j < Vector128<sbyte>.Count; j++)
{
var matchingValue = first.GetElement(j);
//do stuff
}
}
问题:
如果第一个索引匹配,它会遍历向量中的所有元素,即使只有第一个索引是匹配的。
我怎样才能获得所有匹配的索引只是为了加快速度?
解决方案
推荐阅读
- html - 如何在打印预览中打印时显示 html svg 标签
- sql - 如何将具有树结构的表聚合到单个嵌套 JSON 对象?
- sql - Hive 中的 INSERT OVERWRITE 是否按名称或序号位置插入?
- html - 将响应图像放入 Bootstrap (4) 列和 srcset/sizes 属性
- javascript - 计算多范围滑块值
- macos - 我可以避免用户在 Mac 应用程序中截屏或录制视频吗?
- c++ - 在 C++ 中对结构向量进行排序的问题
- regex - 正则表达式从选择查询中获取所有字段名称
- amazon-web-services - Amazon Elasticsearch 服务 Kibana 的错误:“租户索引迁移失败”
- sql - 如何通过查询输出一个周期内的所有OrderLine