RA4E2是一款基于Cortex -M33内核的ARM MCU,理论上是具备硬件浮点运算单元的,所以这里就测试下RA4E2的硬件浮点运算能力,就是跑常用的浮点数加减乘除,sin,cos ,tan, atan,等等基本操作。
当然为了测试出硬件浮点运算性能,这里很有必要在测试一下软件浮点运算能力,方便做个测试对比,怎么做软件浮点运算呢?
这个可以使用开源库Qfplib,这是国外的大师基于ARM处理器,采用纯汇编编写的极致性能的浮点库,号称能达到实际硬件FPU的性能,就差几个us,不超过10us,本帖就是来验证下这个qfplib库的浮点性能,直接和M33作比较
https://www.quinapalus.com/qfplib.html
这是网站qfplib
大家选择
下面的M3进行下载
上面是我写的函数时间测量
下面是Qfplib库
添加路劲
同时工程添加文件
库是纯汇编,所以添加.s文件
添加头文件
#include "hal_data.h"
#include "code_time_measurement.h"
#include "qfplib-m3.h"
#include "math.h"
软件qfplib浮点测试代码
printf("======================qfplib==========================\r\n");
CODE_TIME_START("qfplib浮点运算");
printf("qfp_fsqrt = %f\r\n", qfp_fsqrt(3.4f));
CODE_TIME_EVENT("qfp_fsqrt(3.4f)");
printf("qfp_fexp = %f\r\n", qfp_fexp(4.124f));
CODE_TIME_EVENT("qfp_fexp(4.124f)");
printf("qfp_fln = %f\r\n", qfp_fln(88.124f));
CODE_TIME_EVENT("qfp_fln(88.124f)");
printf("qfp_fsin = %f\r\n", qfp_fsin(3.1415926f/4));
CODE_TIME_EVENT("qfp_fsin(3.1415926f/4)");
printf("qfp_fcos = %f\r\n", qfp_fcos(3.1415926f/4));
CODE_TIME_EVENT("qfp_fcos(3.1415926f/4)");
printf("qfp_ftan = %f\r\n", qfp_ftan(3.1415926f/4));
CODE_TIME_EVENT("qfp_ftan(3.1415926f/4)");
printf("qfp_fatan2 = %f\r\n", qfp_fatan2(1.0f, 2.0f));
CODE_TIME_EVENT("qfp_fatan2(1.0f, 2.0f)");
CODE_TIME_STOP();
要运行,先要禁用硬件浮点功能
在KEIL里设置后编译
打开串口助手
下面是硬件浮点运算测试代码
printf("======================hardfpu==========================\r\n");
CODE_TIME_START("硬件浮点运算");
printf("sqrtf = %f\r\n", sqrtf(3.4f));
CODE_TIME_EVENT("sqrtf(3.4f)");
printf("expf = %f\r\n", expf(4.124f));
CODE_TIME_EVENT("expf(4.124f)");
printf("logf = %f\r\n", logf(88.124f));
CODE_TIME_EVENT("logf(88.124f)");
printf("sinf = %f\r\n", sinf(3.1415926f/4));
CODE_TIME_EVENT("sinf(3.1415926f/4)");
printf("cosf = %f\r\n", cosf(3.1415926f/4));
CODE_TIME_EVENT("cosf(3.1415926f/4)");
printf("tanf = %f\r\n", tanf(3.1415926f/4));
CODE_TIME_EVENT("tanf(3.1415926f/4)");
printf("atan2f = %f\r\n", atan2f(1.0f, 2.0f));
CODE_TIME_EVENT("atan2f(1.0f, 2.0f)");
CODE_TIME_STOP();
编译后烧录板子
打开串口助手
qfplib软件浮点和硬件浮点进行对比
可以看到两者的性能非常接近了,Qfplib库的浮点性能接近M33的硬件浮点性能!!!!!
更多回帖