如果没有比较指令,不相等如何分支?

How does it branch if not equal if there is no compare instruction?

.text:91C034B4                 li        r11, 0x1E     # Load Immediate
.text:91C034B8                 divw      r11, r27, r11 # Divide Word
.text:91C034BC                 mulli     r11, r11, 0x1E # Multiply Low Immediate
.text:91C034C0                 subf.     r11, r11, r27 # Subtract from
.text:91C034C4                 bne       loc_91C034E0

通常在 PowerPC 中,在 bne(如果不相等则转移)指令之前有一个比较指令。有人可以解释一下这是如何比较的或者上面的说明中发生了什么吗?

Power 上的 BNE 指令,与许多具有类似分支指令的指令集一样,实际上不需要比较功能。上电时,这条指令只是检查条件寄存器 (CR) 中的位,测试某些位是否已设置或清除。

在您提供的情况下,subf 的结果将根据结果修改 CR 寄存器。程序员就是靠这个减法的副作用来进行测试的。

事实上,这通常等同于实际的比较指令,因为比较通常会执行减法以确定要在 CR 中设置哪些位。程序员只是同时做两件事。

我建议您查看 PowerPC User Instruction Architecture 参考资料中的第 2 章,其中介绍了分支处理器。特别注意第 2.3.1 节:

For Compare instructions, a specified CR field is set to reflect the result of the comparison. The bits of the specified CR field are interpreted as follows. A complete description of how the bits are set is given in the instruction descriptions in Section 3.3.9, “Fixed- Point Compare Instructions” on page 58 and Section 4.6.7, “Floating-Point Compare Instructions” on page 113.

Bit Description:

0- Less Than, Floating-Point Less Than (LT, FL) For fixed-point Compare instructions, (RA) < SI or (RB) (signed comparison) or (RA)

1- Greater Than, Floating-Point Greater Than (GT, FG) For fixed-point Compare instructions, (RA) > SI or (RB) (signed comparison) or (RA) >u UI or (RB) (unsigned comparison). For floating-point Compare instructions, (FRA) > (FRB).

2- Equal, Floating-Point Equal (EQ, FE) For fixed-point Compare instructions, (RA) = SI, UI, or (RB). For floating-point Compare instructions, (FRA) = (FRB).

3- Summary Overflow, Floating-Point Unordered (SO, FU) For fixed-point Compare instructions, this is a copy of the final state of XERSO at the completion of the instruction. For floating-point Compare instructions, one or both of (FRA) and (FRB) is a NaN.

请注意,这是在比较后设置这些位的方式,因此随后由分支指令使用。如果您检查 subf 指令的引用,您可以看到哪些 CR 位也受到减法的影响,从而允许您像完成比较一样执行分支。