在关于musl工具链的尝试中,我惊讶发现这条工具链尽管--with-abi=lp64
,却能够编译出带有浮点指令的程序,并使用FPU,这令我感到十分困惑。
我通过移植whetstone基准测试判断确实如此,详细过程见rt-thread仓库 issue#9812
我完全不能够理解,但是这个旧工具链竟然确实是编译出了带有浮点指令的程序,尽管它只能指定lp64的ABI而不能指定lp64f与lp64d。这实在是一个太出乎意料的工具链,我真是完全不能够理解。现在缺乏编译器知识的我是足够困惑的。有没有大佬能点拨一下为什么一个-mabi=lp64的工具链,在编译时接收的ABI参数也是lp64,却能够编译出带有浮点指令的程序。
话说回来,我是通过移植whetstone浮点计算基准测试确定了这一点。在QEMU中运行这种基准测试并不是好的做法,但以下结果应该仍然能够反映出结论。
rt smart:使用这个ci中的musl工具链,编译器信息如上条评论。
关闭fpu并设置rtconfig.py中-march=rv64imac, 保持-mabi=lp64
Loops: 100000, Iterations: 1, Duration: 103 sec.
C Converted Double Precision Whetstones: 97.1 MIPS
开启fpu,改回rtconfig.py的-march=rv64ima, 保持-mabi=lp64
Loops: 100000, Iterations: 1, Duration: 39 sec.
C Converted Double Precision Whetstones: 256.4 MIPS
rt-thread standard: 使用的工具链是一个挺正常的工具链,
❯ $RTT_EXEC_PATH/riscv64-unknown-elf-gcc -v
Using built-in specs.
COLLECT_GCC=/home/zhaocake/WorkSpace/Embeded/riscv64-unknown-elf-toolchain-for-rtt/bin/riscv64-unknown-elf-gcc
COLLECT_LTO_WRAPPER=/home/zhaocake/WorkSpace/Embeded/riscv64-unknown-elf-toolchain-for-rtt/bin/../libexec/gcc/riscv64-unknown-elf/10.2.0/lto-wrapper
Target: riscv64-unknown-elf
Configured with: /scratch/jenkins/workspace/tpp-freedom-tools/tpp03--build-binary-packages--parameterized/obj/x86_64-linux-ubuntu14/build/riscv64-unknown-elf-gcc/riscv-gcc/configure --target=riscv64-unknown-elf --host=x86_64-linux-gnu --prefix=/scratch/jenkins/workspace/tpp-freedom-tools/tpp03--build-binary-packages--parameterized/obj/x86_64-linux-ubuntu14/install/riscv64-unknown-elf-gcc-10.2.0-2020.12.8-x86_64-linux-ubuntu14 --with-pkgversion='SiFive GCC-Metal 10.2.0-2020.12.8' --with-bugurl=https://github.com/sifive/freedom-tools/issues --disable-shared --disable-threads --enable-languages=c,c++ --enable-tls --with-newlib --with-sysroot=/scratch/jenkins/workspace/tpp-freedom-tools/tpp03--build-binary-packages--parameterized/obj/x86_64-linux-ubuntu14/install/riscv64-unknown-elf-gcc-10.2.0-2020.12.8-x86_64-linux-ubuntu14/riscv64-unknown-elf --with-native-system-header-dir=/include --disable-libmudflap --disable-libssp --disable-libquadmath --disable-libgomp --disable-nls --disable-tm-clone-registry --src=../riscv-gcc --with-system-zlib --enable-checking=yes --enable-multilib --with-abi=lp64d --with-arch=rv64imafdc CFLAGS=-O2 CXXFLAGS=-O2 'CFLAGS_FOR_TARGET=-Os -mcmodel=medany' 'CXXFLAGS_FOR_TARGET=-Os -mcmodel=medany'
Thread model: single
Supported LTO compression algorithms: zlib
gcc version 10.2.0 (SiFive GCC-Metal 10.2.0-2020.12.8)
可以看到它的--with-abi=lp64d
。
关闭fpu并修改rtconfig.py中-march=rv64imac, -mabi=lp64
Loops: 100000, Iterations: 1, Duration: 64 sec.
C Converted Double Precision Whetstones: 156.2 MIPS
开启fpu并修改rtconfig.py中-march=rv64imafdc, -mabi=lp64d。(如果不修改mabi理所当然地会报错,所以这个musl工具链令我头疼)
Loops: 100000, Iterations: 1, Duration: 26 sec.
C Converted Double Precision Whetstones: 384.6 MIPS
对比结果显然得出结论,该ci中的musl库工具链能够在lp64的目标ABI下编译出能够运行的带有浮点指令的程序。