一个在研的任意精度算术库(GMP 的替代方案)
1 分•作者: Tommyrexx•4 个月前
我正在用 C 语言积极开发一个任意精度算术库,目标是提供一个与 GNU 的 LibGMP 速度相近的替代方案,但采用 MIT 许可证。作为一个全日制大学生,独自完成这项工作有点枯燥,但进展缓慢而稳定。
GitHub 链接:https://github.com/EpsilonNought117/libapac
我的 API 和命名方案受到了 GMP 公共 API 的启发,但内部实现(据我所知)完全是我自己的。该库目前在 x86-64 CPU 上使用运行时分发到特定于微架构的汇编函数版本,适用于类 Unix 和 Windows 操作系统,未来计划在两者上都支持 ARM64。我手写了所有汇编例程(从写作风格可能很明显),使用了 MASM 和 GAS 汇编器,并使用编译器内部函数编写了一些基于 SIMD 的例程。
到目前为止,性能似乎与 GMP 在中小型大整数方面相当(性能图表在 README 中)。我已经实现了一些算法,例如 Karatsuba 算法和分治除法(平衡和不平衡),并且会根据需要添加更多算法。《现代计算机算术》(作者:Brent 和 Zimmerman)和《黑客的喜悦》(作者:Henry Warren Jr.)这两本书确实帮助很大。
目前仍处于 WIP(进行中)阶段。
欢迎任何反馈和/或批评。乐于回答任何问题。
查看原文
I am actively developing an arbitrary-precision arithmetic library in C with the aim to offer a nearly-as-fast alternative to GNU's LibGMP, but under the MIT License. The solo effort has been a bit tedious as a full-time college student, but there's slow and steady progress.<p>GitHub Link: https://github.com/EpsilonNought117/libapac<p>I have inspired my API and naming scheme from GMP's public API, but the internals are (to the best of my knowledge) completely my own. The library uses a runtime dispatch to micro-arch specific versions of assembly functions on x86-64 CPUs currently for Unix-like and Windows OS, with future support planned on ARM64 on both as well. I have handwritten all the assembly routines (probably obvious by the writing style) using MASM and GAS assemblers, with a few SIMD based routines written with compiler intrinsic functions.<p>The performance (so far) seems to be on par with GMP for small to medium-sized Big Integers (performance graphs in README). I have implemented a few algorithms such as the Karatsuba Algorithm and Divide-&-Conquer division (Balanced and Unbalanced) with more algorithms on the way as needed. The books "Modern Computer Arithmetic" by Brent and Zimmerman and "Hacker's Delight" by Henry Warren Jr have really helped a lot.<p>Still largely WIP.<p>Interested in any feedback and/or criticisms. Happy to answer any questions.