【发布时间】:2017-02-26 02:09:30
【问题描述】:
我正在尝试使用 SSE 指令在数组中为 uint64_t 整数累积 POPCOUNTs。
这是我的代码:
#include <emmintrin.h>
#include <nmmintrin.h>
#include <chrono>
int main()
{
uint64_t data[4] = {1,1,1,1};
uint64_t data2[4] = {1,0,1,0};
__m128i* ptr = (__m128i*) data;
__m128i* ptr2 = (__m128i*) data2;
int total = 0;
for (int i = 0; i < 2; ++i, ++ptr, ++ptr2)
total += popcount(_mm_and_si128(*ptr, *ptr2)); // This doesn't work
}
我需要对_mm_and_si128 的输出进行操作的POPCOUNT 函数的等效项,因此我可以将所有POPCOUNTs 累积到total 变量中。
【问题讨论】:
-
你要问one question per instruction :-) 吗?
-
@KerrekSB 我觉得这两个问题在各自的具体空间中运作,我认为将它们放在一起没有帮助:)
-
SSSE3: fast popcount 和 Hand coded assembly beats intrinsics in speed and simplicity 这两个链接可能对您很有帮助。他们都在最近的一篇博文中被提及。
-
@zx485: 没有更多的 SSSE3 链接 wm.ite.pl/articles/sse-popcount.html
-
@IsaacPascual:谢谢。 archive.org 上的新链接:SSSE3: fast popcount