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

查看:25
本文介绍了何时在扩展 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;"   // separate bug: modifies input-only operand
    "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.

推荐答案

默认情况下,编译器假定在写入任何输出寄存器之前将消耗所有输入,因此允许对两者使用相同的寄存器.这会在可能的情况下产生更好的代码,但如果假设错误,事情将发生灾难性的失败.early clobber"标记是一种告诉编译器该输出将在所有输入被消耗之前写入的方式,因此它不能与任何输入共享一个寄存器.

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天全站免登陆