我必须承认我在C语言方面不是很有经验。尝试将Perl模块LCS :: BV移植到C并调整我在一个会话中获得的代码的速度令人惊讶,每秒5 G迭代(相比于12 M / s之前)。
现在,在隔离原因期间,Intel Core i7-4770HQ的差异为〜50 G / s至〜70 M / s。
为了确保clang不会展开基准测试的循环,我可以使用_mm_popcnt_u64(~v)然后反编译:
$ otool -tv lcstest > lcstest.dump.txt
$ grep popcnt lcstest.dump.txt
0000000100000e26 popcntq %rax, %rax
Run Code Online (Sandbox Code Playgroud)
我不确定基准代码或方法是否有问题。请参阅带注释的代码(也可以在GitHub上找到):
#include <stdio.h>
#include <limits.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <nmmintrin.h>
static const uint64_t width = 64;
int count_bits(uint64_t bits) {
bits = bits - ((bits >> 1) & 0x5555555555555555ull);
bits = (bits & 0x3333333333333333ull) + ((bits …Run Code Online (Sandbox Code Playgroud)