bdo*_*lan 9 linux floating-point x86
是否(很容易)可以在i386 linux上使用软件浮点而不会在每次调用时产生陷入内核的费用?我试过-msoft-float,但看起来普通(ubuntu)C库没有包含FP库:
$ gcc -m32 -msoft-float -lm -o test test.c
/tmp/cc8RXn8F.o: In function `main':
test.c:(.text+0x39): undefined reference to `__muldf3'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
令人惊讶的是,gcc本身不支持这一点,因为代码在名为的目录中的源代码中清晰可用soft-fp.可以手动编译该库:
$ svn co svn://gcc.gnu.org/svn/gcc/trunk/libgcc/ libgcc
$ cd libgcc/soft-fp/
$ gcc -c -O2 -msoft-float -m32 -I../config/arm/ -I.. *.c
$ ar -crv libsoft-fp.a *.o
Run Code Online (Sandbox Code Playgroud)
有一些c文件由于错误而无法编译,但大多数都编译.libsoft-fp.a使用我们的源文件复制到目录后,它们现在可以正常编译-msoft-float:
$ gcc -g -m32 -msoft-float test.c -lsoft-fp -L.
Run Code Online (Sandbox Code Playgroud)
快速检查使用
$ objdump -D --disassembler-options=intel a.out | less
Run Code Online (Sandbox Code Playgroud)
表明正如预期的那样,没有调用x87浮点指令,并且代码运行速度也相当慢,在我的例子中使用了大量的除法.
注意:我宁愿用软件编译soft-float库
$ gcc -c -O2 -msoft-float -m32 -I../config/i386/ -I.. *.c
Run Code Online (Sandbox Code Playgroud)
但这会导致大量的错误信息
adddf3.c: In function '__adddf3':
adddf3.c:46: error: unknown register name 'st(1)' in 'asm'
Run Code Online (Sandbox Code Playgroud)
似乎i386版本没有得到很好的维护作为st(1)x87寄存器之一,使用时显然不可用-msoft-float.奇怪或幸运的是,arm版本编译好i386并且似乎工作得很好.
除非您想手动引导整个工具链,否则您可以从uclibc 工具链(我想是 i386 版本)开始——软浮动(据我所知)不直接支持 debian 和衍生品上的“本机”编译,但它可以通过 uclibc 工具链的“嵌入式”方法使用。
如果没有一些额外的库,GCC 不支持这一点。从386 文档:
-msoft-float Generate output containing library calls for floating point. Warning: the requisite libraries are not part of GCC. Normally the facilities of the machine's usual C compiler are used, but this can't be done directly in cross-compilation. You must make your own arrangements to provide suitable library functions for cross-compilation.
On machines where a function returns floating point results in the 80387 register stack, some floating point opcodes may be emitted even if -msoft-float is used
Also, you cannot set -mfpmath=unit to "none", it has to be sse, 387 or both.
However, according to this gnu wiki page, there is fp-soft and ieee. There is also SoftFloat.
(对于 ARM,有 -mfloat-abi=softfp,但 386 SX 似乎没有类似的东西)。
tcc似乎也不支持软件浮点数。
祝你找到一个适合你的图书馆。