We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 9 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
您没有提到您的平台/可移植性要求。如果您愿意使用
gcc
或clang
,在 64 位平台上,它们有免费的内置 128 位类型,__uint128_t
和 <代码>__int128_t。也许其他平台也有类似的类型扩展。无论如何,应该可以在
gcc
源代码中找到相应的通用代码,该代码将两个宽度为N
的整数组合成一个宽度为2N
的整数。代码>.这可能是为此目的制作独立库的一个很好的起点。You didn't mention your platform / portability requirements. If you are willing to use
gcc
orclang
, 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 widthN
to synthesize one integer of width2N
. This would probably be a good starting point to make a standalone library for that purpose.ttmath 库可以满足您的需求。
The ttmath library does what you want.
这可能并不适合所有人,但我要做的是选择带有源代码和其他适合该工作的最高性能的任意整数库,并将其修改为固定的整数大小。将某些变量“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.