FLAGS/EFLAGS是"CC"的一部分吗? (条件控制)清单清单? [英] Is FLAGS/EFLAGS part of "CC" (condition control) for clobber list?

查看:103
本文介绍了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:

如果您的汇编指令可以更改条件代码寄存器, 将"cc"添加到被破坏的寄存器列表中.在某些机器上的GCC 将条件代码表示为特定的硬件寄存器; ‘cc’ 用于命名该寄存器.在其他计算机上,条件代码为 处理方式不同,指定"cc"无效.但它是 无论在什么机器上都有效.

If your assembler instruction can alter the condition code register, add ‘cc’ to the list of clobbered registers. GCC on some machines represents the condition codes as a specific hardware register; ‘cc’ serves to name this register. On other machines, the condition code is handled differently, and specifying ‘cc’ has no effect. But it is valid no matter what the machine.

如果是虚假的,它适用于什么架构? (我猜想是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设置为<-0.

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"的一部分吗? (条件控制)清单清单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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