Achieving speed and accuracy for math library functions like exp, sin, and log is difficult. This is because low-level implementation languages like C do not help math library developers catch mathematical errors, build implementations incrementally, or separate high-level and low-level decision making. This ultimately puts development of such functions out of reach for all but the most experienced experts. To address this, we introduce MegaLibm, a domain-specific language for implementing, testing, and tuning math library implementations. MegaLibm is safe, modular, and tunable. Implementations in MegaLibm can automatically detect mathematical mistakes like sign flips via semantic wellformedness checks, and components like range reductions can be implemented in a modular, composable way, simplifying implementations. Once the high-level algorithm is done, tuning parameters like working precisions and evaluation schemes can be adjusted through orthogonal tuning parameters to achieve the desired speed and accuracy. MegaLibm also enables math library developers to work interactively, compiling, testing, and tuning their implementations and invoking tools like Sollya and type-directed synthesis to complete components and synthesize entire implementations. MegaLibm can express 8 state-of-the-art math library implementations with comparable speed and accuracy to the original C code, and can synthesize 5 variations and 3 from-scratch implementations with minimal guidance.
翻译:实现exp、sin和log等数学库函数的速度和精度极具挑战性。这是因为C语言等底层实现语言无法帮助数学库开发者捕捉数学错误、逐步构建实现,或分离高层与底层决策。这一问题使得此类函数的开发对除最资深专家外的开发者而言遥不可及。为解决这一难题,我们提出MegaLibm——一个用于数学库实现、测试和调优的领域特定语言。MegaLibm具备安全性、模块化和可调优性。基于MegaLibm的实现可通过语义良构性检查自动检测符号翻转等数学错误,而范围缩减等组件可通过模块化、可组合的方式实现,从而简化实现流程。完成高层算法设计后,可通过正交调优参数调整工作精度和评估方案等参数,以达到期望的速度与精度。MegaLibm还支持数学库开发者进行交互式开发,通过编译、测试和调优实现,并调用Sollya及类型导向综合等工具来补全组件或综合完整实现。实验表明,MegaLibm可表达8种前沿数学库实现,其速度与精度与原始C代码相当,并能在最小指导下综合出5种变体实现及3种全新实现。