简体   繁体   English

x86_64上无用的jp / jnp汇编指令

[英]Useless jp / jnp assembly instruction on x86_64

I'm trying to figure out what purpose jp / jnp instructions serve in LLVM-generated C code. 我试图找出jp / jnp指令在LLVM生成的C代码中的用途。 Sample: 样品:

int main(int argc, const char * argv[]) {
    double value = 1.5;

    if (value == 1.5) {
        value = 3.0;
    }

    return 0;
}

Assembly output: 装配输出:

Ltmp4:
    movsd   LCPI0_0(%rip), %xmm0
    movl    $0, -4(%rbp)
    movl    %edi, -8(%rbp)
    movq    %rsi, -16(%rbp)
Ltmp5:
    movsd   %xmm0, -24(%rbp)
Ltmp6:
    movsd   -24(%rbp), %xmm1
    ucomisd %xmm0, %xmm1
    jne LBB0_2
    jp  LBB0_2
## BB#1:
    movabsq $3, %rax
    cvtsi2sdq   %rax, %xmm0
Ltmp7:
    movsd   %xmm0, -24(%rbp)
Ltmp8:
LBB0_2:
    movl    $0, %eax
    popq    %rbp
    retq

The jne is checking if value != 1.5 and jumping over the assignment, but what is the jp doing in this context? jne正在检查value != 1.5并跳过赋值,但jp在这种情况下做了什么?

jne is jump if not equal , ie jump if the zero flag is not set. jump if not equal jne jump if not equal ,即如果未设置零标志则跳转。 jp is jump if parity . jump if parity jpjump if parity

ucomisd is defined to compare two doubles . ucomisd被定义为比较两个doubles It will indicate that they are one of four things: unordered, equal, greater than or less than. 它表明它们是四个方面之一:无序,相等,大于或小于。

The zero flag is set if the numbers are unordered or equal. 如果数字是无序的或相等的,则设置零标志。 So the jne avoids the remaining cases of greater than or less than. 因此, jne避免了大于或小于的剩余情况。

Parity is set only if the result is unordered. 仅在结果无序时才设置奇偶校验。 The jp catches that. jp抓住了这个。

So the two together avoid: unordered, greater than, less than. 所以两者一起避免:无序,大于,小于。 Leaving only the fourth possibility, of equal. 只剩下第四种可能性。

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

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