简体   繁体   English

FLAGS / EFLAGS是clobber列表的“CC”(条件控制)的一部分吗?

[英]Is FLAGS/EFLAGS part of “CC” (condition control) for clobber list?

This is a follow up to What is "=qm" in extended assembler . 这是扩展汇编程序中什么是“= qm”的后续内容。

When using RDRAND , it sets (or unsets) the Carry Flag ( CF ): 使用RDRAND ,它会设置(或RDRAND设置)进位标志( CF ):

char rc;
unsigned int val;

__asm__ volatile(
    "rdrand %0 ; setc %1"
    : "=r" (val), "=qm" (rc)
);

// 1 = success, 0 = underflow
if(rc) {
    // use val
    ...
}

Are the FLAGS and EFLAGS registers considered part of condition control so that it conveys the proper information to the compiler? FLAGSEFLAGS寄存器是否被视为条件控制的一部分,以便向编译器传达适当的信息? Should the above be written as: 以上是否应写为:

__asm__ volatile(
    "rdrand %0 ; setc %1"
    : "=r" (val), "=qm" (rc)
    :
    : "cc"
);

Or is the use of "cc" spurious? 或者是使用"cc"虚假?

I know its harmless to use if unneeded. 我知道如果不需要它可以使用它是无害的。 From Extended ASM : 来自Extended ASM

If your assembler instruction can alter the condition code register, add 'cc' to the list of clobbered registers. 如果汇编指令可以改变条件代码寄存器,则将“cc”添加到修改寄存器列表中。 GCC on some machines represents the condition codes as a specific hardware register; 某些机器上的GCC将条件代码表示为特定的硬件寄存器; 'cc' serves to name this register. 'cc'用于命名此寄存器。 On other machines, the condition code is handled differently, and specifying 'cc' has no effect. 在其他机器上,条件代码的处理方式不同,指定“cc”无效。 But it is valid no matter what the machine. 但无论机器是什么,它都是有效的。

If its spurious, what architectures does it apply to? 如果它是虚假的,它适用于哪些架构? (I presume ARM and the CPSR register, but I could be mistaken). (我假设ARM和CPSR寄存器,但我可能会弄错)。

According to the manual, yes - cc is clobbered. 根据手册,是的 - cc被破坏了。 RDRAND also sets OF, SF, ZF, AF, PF <- 0. RDRAND还设置OF,SF,ZF,AF,PF < - 0。

In practice, gcc assumes that an __asm__ block always clobbers the [E|R]FLAGS condition code register for x86. 在实践中,gcc假设__asm__总是破坏x86的[E|R]FLAGS条件代码寄存器。 I don't have the reference, but you can see this assumption in places like the longlong.h header used in various GNU packages. 我没有引用,但你可以在各种GNU包中使用的longlong.h头之类的地方看到这个假设。

It is, as you say, harmless if not used. 正如你所说,如果不使用,它就是无害的。 For that reason, you might as well include it, since it still provides semantic intent, or commentary at worst. 出于这个原因,您可能也包括它,因为它仍然提供语义意图或最坏的评论。 Also consider that Clang and ICC implement GCC asm syntax, and they would be conforming to the documentation if they honoured the "cc" clobber, rather than presume it - even though this is unlikely. 还要考虑Clang和ICC实现GCC asm语法,如果他们尊重"cc" clobber而不是假设它们,它们将符合文档,即使这不太可能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM