当使用在扩展GCC内联汇编earlyclobber约束? [英] When to use earlyclobber constraint in extended GCC inline assembly?

查看:369
本文介绍了当使用在扩展GCC内联汇编earlyclobber约束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解什么时候使用一个补鞋匠列表(例如列出这是在大会修改,因此它不会选择用作输入寄存器等寄存器),但我不能换我的头周围的在earlyclobber约束&安培; 。如果你列出你的产出,那不是已经意味着输入不能使用选定的寄存器(除了数字匹配约束)?

I understand when to use a cobbler list (e.g. listing a register which is modified in the assembly so that it doesn't get chosen for use as an input register, etc), but I can't wrap my head around the the earlyclobber constraint &. If you list your outputs, wouldn't that already mean that inputs can't use the selected register (aside from matching digit constraints)?

例如:

asm(
    "movl $1, %0;"
    "addl $3, %0;"
    "addl $4, %1;"
    "addl %1, %0;"
    : "=g"(num_out)
    : "g"(num_in)
    :
);

应该&安培; 甚至需要为输出变量?编译器应该知​​道被选定为输出寄存器,因此不知道用它来输入。

Would & even be needed for the output variables? The compiler should know the register that was selected for the output, and thus know not to use it for the input.

推荐答案

默认情况下,编译器假定任何输出寄存器写入前,所有的输入将被消耗,因此,它的允许使用相同的寄存器两种。这导致更好的code时可能的,但如果假设是错误的,事情会突然失效。 早期撞标志是一种方法来告诉所有的输入已被消耗在此之前的输出将被写入编译器,所以它不能与任何输入共用一个寄存器。

By default, the compiler assumes all inputs will be consumed before any output registers are written to, so that it's allowed to use the same registers for both. This leads to better code when possible, but if the assumption is wrong, things will fail catastrophically. The "early clobber" marker is a way to tell the compiler that this output will be written before all the input has been consumed, so it cannot share a register with any input.

这篇关于当使用在扩展GCC内联汇编earlyclobber约束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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