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

标签 assembly syntax x86 inline-assembly rdrand

这是对 What is "=qm" in extended assembler 的跟进.

使用时 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
    ...
}

FLAGSEFLAGS寄存器被视为条件控制的一部分,以便它向编译器传达正确的信息?上面的应该写成:
__asm__ volatile(
    "rdrand %0 ; setc %1"
    : "=r" (val), "=qm" (rc)
    :
    : "cc"
);

或者是使用"cc"假的?

我知道在不需要时使用它是无害的。来自 Extended ASM :

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 寄存器,但我可能会误会)。

最佳答案

根据手册,是的 - cc被破坏了。 RDRAND还设置 OF、SF、ZF、AF、PF <- 0。

实际上,gcc 假设 __asm__块总是破坏 [E|R]FLAGS x86 的条件代码寄存器。我没有引用资料,但您可以在 longlong.h 之类的地方看到这个假设。各种 GNU 软件包中使用的 header 。

正如你所说,如果不使用它是无害的。出于这个原因,您不妨包括它,因为它仍然提供语义意图,或者最坏的评论。还要考虑到 Clang 和 ICC 实现了 GCC asm 语法,如果他们遵守 "cc",它们将符合文档。破坏,而不是假设它 - 即使这不太可能。

关于assembly - FLAGS/EFLAGS 是 clobber 列表的 "CC"(条件控制)的一部分吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21541968/

相关文章:

python - `**` 在表达式 `dict(d1, **d2)` 中是什么意思?

c++: 解释这个函数声明

assembly - (汇编 x86 实模式)数据在程序结束时得到 "cut off"?

java - Java 中的日期问题

assembly - 对 10 个数字求和并在 NASM 中打印结果

c - 缓冲区溢出漏洞利用示例

assembly - 我应该使用哪些 AVX 寄存器来避免 3 字节 VEX 前缀?

x86 - 是否可以在不设置分页的情况下进入长模式?

c - 这种没有推送寄存器的交换有多安全?

c - 为什么这个汇编程序运行不了?