SSE4a与python中的ctypes? (gcc __builtin_popcount)

发布于 2024-12-13 09:36:18 字数 378 浏览 6 评论 0原文

这是示例代码

高效在大集合中查找汉明距离低的二进制字符串

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

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

蒂亚!

Here is the sample code

Efficiently find binary strings with low Hamming distance in large set

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

Is it possible to rewrite the above gcc code in python using ctypes
(preferably Win/*nix compatible)?

TIA!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少女七分熟 2024-12-20 09:36:18

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

免责声明:我维护 gmpy。

The gmpy library can calculate the Hamming distance between two integers. Even though it may be more general than you require, it will be faster than calling code via ctypes.

Disclaimer: I maintain gmpy.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文