本文介绍了FLAGS/EFLAGS是"CC"的一部分吗? (条件控制)清单清单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是对> = qm"的后续操作.在扩展汇编程序中.

使用RDRAND时,它设置(或取消设置)进位标志(CF):

When using RDRAND, it sets (or unsets) the Carry Flag (CF):

char rc;
unsigned int val;

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

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

FLAGSEFLAGS寄存器是否被视为条件控制的一部分,以便将正确的信息传达给编译器?以上代码应写为:

Are the FLAGS and EFLAGS registers considered part of condition control so that it conveys the proper information to the compiler? Should the above be written as:

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

还是使用"cc"是伪造的?

如果不需要,我知道使用它是无害的.来自扩展了ASM :

I know its harmless to use if unneeded. From Extended ASM:

如果是虚假的,它适用于什么架构? (我猜想是ARM和CPSR寄存器,但是我可能会误会.)

If its spurious, what architectures does it apply to? (I presume ARM and the CPSR register, but I could be mistaken).

推荐答案

根据手册,是的-cc被破坏了. RDRAND还将OF,SF,ZF,AF,PF设置为

According to the manual, yes - cc is clobbered. RDRAND also sets OF, SF, ZF, AF, PF <- 0.

实际上,gcc假定__asm__始终会掩盖x86的[E|R]FLAGS条件代码寄存器.我没有参考,但是您可以在各种GNU软件包中使用的longlong.h标头之类的地方看到这种假设.

In practice, gcc assumes that an __asm__ block always clobbers the [E|R]FLAGS condition code register for x86. I don't have the reference, but you can see this assumption in places like the longlong.h header used in various GNU packages.

正如您所说,如果不使用,它是无害的.因此,您最好将其包括在内,因为它仍然提供语义意图或最坏的注释.还要考虑Clang和ICC实现了GCC asm语法,如果他们尊敬"cc" clobber,而不是假设它们,那么它们将符合文档要求,即使这不太可能.

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.

这篇关于FLAGS/EFLAGS是"CC"的一部分吗? (条件控制)清单清单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 14:45