软浮在x86_64上 [英] Soft Float on x86_64

查看:254
本文介绍了软浮在x86_64上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从事没有FPU的嵌入式系统的软件。我想能够在我的桌面上使用软件浮点库来构建这个软件,以获得更逼真的性能视图。有没有人有任何想法如何实现这个?

I work on software for an embedded system which does not have an FPU. I would like to be able to build this software with a software floating point library on my desktop in order to get a more realistic view of performance. Does anyone have any ideas about how to achieve this?

到目前为止,我没有使用 -msoft-float 与gcc。我目前正在使用。。通过使用标志 -Xclang -msoft-float -Xclang -no-implicit-float 并指定一个具有soft-float例程实现的库,我能够得到我的应用程序编译。当我试图运行它,它总是segfaults。最好的我可以告诉,这是因为这个程序依赖的库不是用软浮动编译。该应用程序依赖于gtk,sqlite,expat,gcrypt,一些内部库和libc。

Thus far I have not made much progress with using -msoft-float with gcc. I am currently looking at using clang. By using the flags -Xclang -msoft-float -Xclang -no-implicit-float and specifying a library which has implementations of soft-float routines, I am able to get my application to compile. When I try to run it, it always segfaults. As best I can tell, this is because the libraries on which this program depends were not compiled with soft-float. The app depends on gtk, sqlite, expat, gcrypt, a number of internal libraries, and libc.

我想尝试找出如何构建一个完整的构建环境与软浮动支持。我试过uclibc的buildroot和设置 CC CXX 到clang的二进制文件,但是这没有工作,由于编译的要求gcc工具链(例如autotools抱怨编译器版本不正确)。因为我想使用clang作为编译器在新的buildroot(为了有软浮动支持),我没有看到一个迫切需要构建gcc。是否可以在没有gcc的情况下这样做?

I would like to try to figure out how to build a complete build environment with soft-float support. I tried uclibc's buildroot and setting CC and CXX to clang's binaries, but this did not work due to the requirements for compiling the gcc toolchain (things such as autotools complaining about the compiler version being incorrect). Since I would like to use clang as the compiler in the new buildroot (in order to have soft-float support), I don't see a pressing need to build gcc. Is it possible to do this without gcc?

推荐答案

GCC不能在没有其他库的情况下执行。基本上, -msoft-float 只是生成对浮点库的调用,但是所需的库不是GCC的一部分。

GCC can not do it out-of-box without some additional libraries. Basically, -msoft-float just generate calls for floating point libraries but the required libraries are not part of GCC.

要链接 soft-fp 库,您可以使用开关 -lsoft-fp

To link the soft-fp libraries you can use the switch -lsoft-fp.

X86_64架构包含SSE扩展,因此编译器将尝试为基本操作(如+ - * /)生成SSE代码。我们将使用 -mno-sse 开关来禁止此未经授权的行为。

X86_64 architecture contains SSE extensions, so the compiler will try to generate SSE-code for basic operations like + - * /. We will use -mno-sse switch suppress this unauthorized behavior.

它可能如下所示:

gcc -g -msoft-float -mno-sse -m64 -lsoft-fp

对于代码:

int main()
{
    float a = 10;
    float b = 20;

    float c = a * b;

    return 0;
}

生成的程序集将是:

    .file   "12.cpp"
    .def    __main; .scl    2;  .type   32; .endef
    .def    __mulsf3;   .scl    2;  .type   32; .endef
    .text
    .globl  main
    .def    main;   .scl    2;  .type   32; .endef
    .seh_proc   main
main:
    pushq   %rbp
    .seh_pushreg    %rbp
    movq    %rsp, %rbp
    subq    $48, %rsp
    .seh_stackalloc 48
    .seh_setframe   %rbp, 48
    .seh_endprologue
    call    __main
    movl    .LC0(%rip), %eax
    movl    %eax, -4(%rbp)
    movl    .LC1(%rip), %eax
    movl    %eax, -8(%rbp)
    movl    -8(%rbp), %edx
    movl    -4(%rbp), %ecx
    call    __mulsf3
    movl    %eax, -12(%rbp)
    movl    $0, %eax
    addq    $48, %rsp
    popq    %rbp
    ret
    .seh_endproc
    .section .rdata,"dr"
    .align 4
.LC0:
    .long   1092616192
    .align 4
.LC1:
    .long   1101004800
    .ident  "GCC: (GNU) 4.8.0 20120624 (experimental)"

未生成SSE指令。请注意对 __ mulsf3 的调用。

No SSE instructions were generated. Note the call to __mulsf3.

在这个问题中可以找到一些有趣的想法:在x86 linux上使用软件浮点

Some interesting ideas can be found in this question: Using software floating point on x86 linux

这篇关于软浮在x86_64上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆