This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] TMS320F280025C:为什么 C 标准三角函数"sin ()"需要5秒的执行时间?

Guru**** 2442090 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1036133/tms320f280025c-why-the-c-standard-trigonometric-function-sin-is-taking-5-secs-for-execution

器件型号:TMS320F280025C

您好!

当我在  CCS 调试模式下"步越"指令 y=sin (x)时、CCS 更新变量 y 的值大约需要5秒。MCU 执行此类三角函数真的需要这么长时间吗?

Note:  I measured the time with hand stop watch.

Relevant code lines are given below

#include <math.h>

float32_t x=10;
float32_t y=0;
y=sin(x);

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    如果使用较新的 EABI 而不是较旧的 COFF ABI 进行编译,则...

    [引用 userid="483831" URL"~/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1036133/tms320f280025c-why-the-c-standard-trigonometric-function-sin-is-taking-5-secs-for-execution ]y=sin (x);

    (笑声) 与...相同

    y = (float32_t) sin((double)x);

    x 被转换为64位双精度型;sin 计算是使用64位宽双精度运算执行的;结果在分配给 y 之前被转换为32位浮点型。 最糟糕的是、这一点都不使用此器件上提供的32位浮点指令。   

    请考虑调用 sinf。 然后没有转换、计算是通过32位浮点指令完成的。   

    如果您希望编译器在发生此特定错误时向您发出警告、请添加构建选项 -float_operations_allowed=32。  请在 C28x 编译器手册中搜索它

    请告诉我这些建议是否能解决问题。

    谢谢、此致、

    乔治

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    非常感谢 George 的回复!

    而是使用sinf可将时间缩短至3秒。 设置-fp_mode=relaxed 后、它的执行速率与其他指令大致相同。 --fp_mode=relaxed 是否意味着不使用 FPU? 如果三角函数花费太多的时间来执行、TMU 的重要性是什么?

    此致、

    杜门

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    同时使用--fp_mode=relaxed--tmu_support 两个选项意味着 TMU 指令会用于特定操作,包括 atan2。  如果未发生这种情况、则 对于该源文件、请按照文章 如何提交编译器测试用例中的说明进行操作。

    谢谢、此致、

    乔治