首页 > 解决方案 > 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

标签: c++arm

解决方案


推荐阅读