• 中国计算机学会会刊
  • 中国科技核心期刊
  • 中文核心期刊

计算机工程与科学 ›› 2023, Vol. 45 ›› Issue (09): 1532-1543.

• 高性能计算 • 上一篇    下一篇

RISC-V基础数学库性能优化

李飞,郭绍忠,周蓓,宋广辉,郝江伟,许瑾晨   

  1. (信息工程大学网络空间安全学院,河南 郑州 450001)
  • 收稿日期:2023-02-06 修回日期:2023-04-11 接受日期:2023-09-25 出版日期:2023-09-25 发布日期:2023-09-12
  • 基金资助:
    数学工程与先进计算国家重点实验室开放基金(2023B02) 

Performance optimization of  RISC-V basic math library

LI Fei,GUO Shao-zhong,ZHOU Bei,SONG Guang-hui,HAO Jiang-wei,XU Jin-chen   

  1. (School of Cyberspace Security,University of Information Engineering,Zhengzhou 450001,China)
  • Received:2023-02-06 Revised:2023-04-11 Accepted:2023-09-25 Online:2023-09-25 Published:2023-09-12

摘要: 基础数学库作为计算机系统最基础的软件库之一,其性能是影响上层应用执行效率的主要因素之一。现有的RISC-V基础数学库虽然可以实现正确计算,但其源码中存在大量访存指令和冗余指令,导致函数性能不高;同时RISC-V数学函数的汇编代码量大,分支判断复杂,增加了直接优化的难度。针对上述问题,遵循从局部到整体的优化思路,提出了RISC-V数学函数的关键路径自动检测方法,重点解决对关键分支进行优化时其他分支寄存器依赖易被改变的问题。依据队列式寄存器分配策略,对同一路径内寄存器进行再分配,提高了寄存器利用率,最大限度地减少了访存指令数。此外,还对冗余指令进行了组合功能重构。实验结果表明,67个RISC-V数学函数由平均144个时钟周期优化为85个时钟周期,性能平均提升了29.61%。

关键词: RISC-V, 数学库, 关键路径, 寄存器分配, 性能优化

Abstract: The basic mathematical library is one of the fundamental software libraries in a computer system, and its performance is one of the key factors affecting the efficiency of higher-level applications. The existing RISC-V basic mathematical library can achieve correct calculations, but it contains a large number of memory access instructions and redundant instructions in its source code, which leads to suboptimal function performance. Additionally, the assembly code for RISC-V mathematical functions is large and involves complex branch conditions, which increases the difficulty of direct optimization. To address these issues, this paper follows a local-to-global optimization approach from and proposes a method for automatically detecting critical paths in RISC-V mathematical functions. This method focuses on solving the problem of other branch registers being easily modified when optimizing critical branches. By using a queue-based register allocation strategy, the registers within the same path are reallocated, which improves register utilization and minimizes the number of memory access instructions. Furthermore, redundant instructions are also combined and functionally refactored. Experimental results show that the average execution cycles for 67 RISC-V mathematical functions have been optimized from 144 cycles to 85 cycles, resulting in an average performance improvement of 29.61%.

Key words: RISC-V, math library, critical path, register scheduling, performance optimization