最快的 128 位整数库

发布于 2024-09-18 08:53:18 字数 1539 浏览 2 评论 0原文

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

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

发布评论

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

评论(3

怀中猫帐中妖 2024-09-25 08:53:18

您没有提到您的平台/可移植性要求。如果您愿意使用 gccclang,在 64 位平台上,它们有免费的内置 128 位类型,__uint128_t 和 <代码>__int128_t。也许其他平台也有类似的类型扩展。

无论如何,应该可以在 gcc 源代码中找到相应的通用代码,该代码将两个宽度为 N 的整数组合成一个宽度为 2N 的整数。代码>.这可能是为此目的制作独立库的一个很好的起点。

You didn't mention your platform / portability requirements. If you are willing to use gcc or clang, on 64 bit platforms they have a builtin 128 bit types that come for free, __uint128_t and __int128_t. Maybe other platforms have similar type extensions.

In any case it should be possible to find the corresponding generic code in the gcc sources that assembles two integers of width N to synthesize one integer of width 2N. This would probably be a good starting point to make a standalone library for that purpose.

薄荷港 2024-09-25 08:53:18

ttmath 库可以满足您的需求。

The ttmath library does what you want.

小ぇ时光︴ 2024-09-25 08:53:18

这可能并不适合所有人,但我要做的是选择带有源代码和其他适合该工作的最高性能的任意整数库,并将其修改为固定的整数大小。将某些变量“nbits”更改为硬编码的 128。它可能在运行时分配内存,直到那时才知道字节数。将其更改为使用带有就地数据的结构,从而在每次读取数据时保存指针取消引用。手动展开某些关键循环。对其他可能重要的内容进行硬编码。那么编译器可能会更容易优化事情。当然,其中大部分将是组装,使用奇特的 SIMD 以及本周使用的技术。

会很有趣的!但后来,作为一名程序员,我从机器代码和非常低级的东西开始。

但对于那些不像我那么疯狂的人来说,也许可用的库之一使用模板或具有某种生成特定大小的自定义代码的方法。并且,某些编译器具有可能合适的“long long”整数类型。

This might not be for everyone, but what I would do is pick the highest-performance arbitrary integer library with source code and otherwise suitable for the job, and hack it to be for fixed integer sizes. Change some variable "nbits" to 128 hard-coded. It probably allocates memory at runtime, not knowing the number of bytes until then. Change it to use struct with data in-place, saving a pointer dereferencing every time data is read. Unroll certain critical loops by hand. Hard-code anything else that might be critical. Then the compiler will probaby have an easier time optimizing things. Of course, much of this will be assembly, using fancy SIMD with whatever the technology is in use this week.

It would be fun! But then, as a programmer I started off with machine code and very low level stuff.

But for those not as crazy as I am, perhaps one of the available libraries uses templates or has some means of generating code custom to some size. And, some compilers have a "long long" integer type which might be suitable.

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