工具/软件:
TL;DR: atan2f
sinf
cosf,
<cmath>
<math.h>, t
ATANPUF32
SINPUF32
COSPUF32
当显式启用 TMU 支持(通过--tmu_support=tmu1
)且适当设置优化标志(-O4
、--opt_for_speed=5
等)时、为什么 TI 编译器(例如 cl2000 v22.6.1.LTS)不自动映射标准数学函数、如、、并通过或包含其相应的 TMU 加速内在函数(例如、、、)?
在以下说明性案例中:
#include <cmath>
float test(float x, float y) {
float a = atan2(x, y);
float b = sin(a);
float c = cos(a);
return a + b + c;
}
编译后的输出清楚地表明、atan2f
sinf
cosf
尽管存在 TMU 和 FPU64支持、但标准、和函数被称为外部符号:
LCR #||atan2f||
...
LCR #||sinf||
...
LCR #||cosf||
只有当用显式调用内在函数(__atan2
,__sin
__cos
)的内联包装器手动覆盖标准函数时,才会生成基于 TMU 的高效代码生成:
inline float atan2(float x, float y) { return __atan2(y, x); }
inline float sin(float x) { return __sin(x); }
inline float cos(float x) { return __cos(x); }
这将导致预期使用硬件指令:
ATANPUF32 R0H,R0H
...
SINPUF32 R1H,R1H
COSPUF32 R2H,R2H
鉴于启用了 TMU 支持、我们希望编译器和标准库头能够检测目标架构并以透明方式将这些高级数学函数映射到其经过优化的硬件加速函数。
构建命令如下所示:
/opt/ti/ti-cgt-c2000_22.6.1.LTS/bin/cl2000 -c \ -D=USE_20MHZ_XTAL -D=_FLASH -D=CPU1 -D=__TMS320C28XX__ \ --issue_remarks --abi=eabi --tmu_support=tmu1 \ --float_support=fpu64 --gen_opt_info=2 \ -v28 -ml -O4 -op=3 --c_src_interlist --auto_inline \ --verbose_diagnostics --advice:performance=all \ --opt_for_speed=5 --preproc_with_compile --keep_asm \ -I/opt/ti/ti-cgt-c2000_22.6.1.LTS/include -z main.obj -o exec.out
TI 标准 C 库(math.h
)和 C++包装器(<cmath>
)是否集成了特定于目标的逻辑(例如、通过条件宏或内联定义)、以便在可用时将标准数学函数重定向到硬件内在函数? 为什么此重定向完全留给用户? 是否有编译器标志或 TI 提供的配置可以在 TMU 支持的编译版本下启用到内在函数的自动映射?