【问题标题】:SSE4a with ctypes in python? (gcc __builtin_popcount)SSE4a 与 python 中的 ctypes? (gcc __builtin_popcount)
【发布时间】:2011-11-01 03:27:27
【问题描述】:

这里是示例代码

Efficiently find binary strings with low Hamming distance in large set

static inline int distance(unsigned x, unsigned y)
{
   return __builtin_popcount(x^y);
}

是否可以使用 ctypes 在 python 中重写上述 gcc 代码 (最好是 Win/*nix 兼容)?

TIA!

【问题讨论】:

  • __builtin_* 是 GCC 内置的,而不是 C 函数,所以我不希望 ctypes 能够调用它们。

标签: python gcc ctypes sse


【解决方案1】:

gmpy 库可以计算两个整数之间的汉明距离。尽管它可能比您需要的更通用,但它会比通过 ctypes 调用代码更快。

免责声明:我维护 gmpy。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-13
    • 2013-03-12
    • 1970-01-01
    • 2013-03-30
    • 2012-01-05
    • 2017-01-11
    • 2010-09-13
    • 1970-01-01
    相关资源
    最近更新 更多