c++ - ARM __sqrtf 函数要包含哪个头文件?
问题描述
我正在考虑__sqrtf
在我们的产品代码中使用函数。为此,我想首先针对 C 数学库sqrtf
函数来衡量它的性能。我编写了以下代码来快速测试。
#include<arm_neon.h>
#include<iostream>
#include<cmath>
#include<chrono>
using namespace std;
using namespace std::chrono;
int main()
{
srand(static_cast<unsigned int>(time(NULL)));
for (int i = 0; i < 100; i++)
{
float f = static_cast<float>(rand() / (static_cast<float>(RAND_M AX / 100.0)));
high_resolution_clock::time_point t1 = high_resolution_clock::no w();
float ans1 = sqrtf(f);
high_resolution_clock::time_point t2 = high_resolution_clock::no w();
float ans2 = __sqrtf(f);
high_resolution_clock::time_point t3 = high_resolution_clock::no w();
auto duration1 = duration_cast<microseconds>(t2 - t1).count();
auto duration2 = duration_cast<microseconds>(t3 - t2).count();
cout << duration1 << " " << duration2 << endl;
}
return 0;
}
当我尝试g++ -mfpu=neon-vfpv4 test.cpp
在我的 Raspberry Pi 3 上编译代码时,它给出了错误
pi@raspberrypi:~/temp $ g++ -mfpu=neon-vfpv4 test.cpp
/tmp/ccK08ITT.o: In function `main':
test.cpp:(.text+0x74): undefined reference to `__sqrtf'
collect2: error: ld returned 1 exit status
我认为我的 Raspberry Pi 3 具有 VFP 协处理器。
pi@raspberrypi:~/temp $ cat /proc/cpuinfo
processor : 0
model name : ARMv7 Processor rev 4 (v7l)
BogoMIPS : 38.40
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4
processor : 1
model name : ARMv7 Processor rev 4 (v7l)
BogoMIPS : 38.40
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4
processor : 2
model name : ARMv7 Processor rev 4 (v7l)
BogoMIPS : 38.40
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4
processor : 3
model name : ARMv7 Processor rev 4 (v7l)
BogoMIPS : 38.40
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4
我是否必须包含一些头文件才能使用__sqrtf
?此页面未提及 - http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0491e/CJAIFJIF.html
解决方案
推荐阅读
- python - 将包含 GeoJSON 的 CSV 字符串压缩到 python 字典
- angular - 重定向到另一个页面Angular 7后如何重新加载主要组件
- python - 将函数转换为 Python 类
- javascript - 未捕获的类型错误:TransportU2F.create 不是函数
- javascript - 使用 javascript 在多选下拉列表中动态填充所选选项
- gradle - 不知道为什么doFirst()和doLst()没有执行
- flutter - 比将回调函数传递给子 Widget 更好的架构
- c# - 如何在c#中将两个数据源绑定到数据网格中
- javascript - 没有表单标签的复选框,没有找到选中的复选框
- r - 在 R 中按组自定义归一化