You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This instruction calculates a 2-bit value by rotating the source register right by `imm32` bits and taking the 2 least significant bits (the value of the source register is unaffected). The result is stored in the `fprc` register. This changes the rounding mode of all subsequent floating point instructions.
606
606
607
607
#### 5.4.2 CBRANCH
608
608
609
-
This instruction performs a conditional jump in the Program Buffer. It uses an implicit integer register operand `creg`. This register is determined based on preceding instructions. For this purpose, the VM assigns each integer register two tag values:
609
+
This instruction adds an immediate value `cimm` (constructed from `imm32`, see below) to the destination register and then performs a conditional jump in the Program Buffer based on the value of the destination register. The target of the jump is the instruction following the instruction when register `dst` was last modified.
610
610
611
-
*`lastUsed` - the index of the instruction when the register was last modified. The initial value at the start of each program iteration is `-1`, meaning the register is unmodified.
612
-
*`count` - the number of times the register has been selected as the operand of a CBRANCH instruction. The initial value at the start of each program iteration is `0`.
613
-
614
-
A register is considered as modified by an instruction in the following cases:
611
+
At the beginning of each program iteration, all registers are considered to be unmodified. A register is considered as modified by an instruction in the following cases:
615
612
616
613
* It is the destination register of an integer instruction except IMUL_RCP and ISWAP_R.
617
614
* It is the destination register of IMUL_RCP and `imm32` is not zero or a power of 2.
618
615
* It is the source or the destination register of ISWAP_R and the destination and source registers are distinct.
619
616
* The CBRANCH instruction is considered to modify all integer registers.
620
617
621
-
There are 3 rules for the selection of the `creg` register, evaluated in this order:
622
-
623
-
1. The register with the lowest value of `lastUsed` tag is selected.
624
-
1. In case multiple registers have the same value of the `lastUsed` tag, the register with the lowest value of the `count` tag is selected from them.
625
-
1. In case multiple registers have the same values of both `lastUsed` and `count` tags, the register with the lowest index is selected (`r0` before `r1` etc.) from them.
626
-
627
-
Whenever a register is selected as the operand of a CBRANCH instruction, its `count` tag is increased by 1.
618
+
If register `dst` has not been modified yet, the jump target is the first instruction in the Program Buffer.
628
619
629
620
The CBRANCH instruction performs the following steps:
630
621
631
622
1. A constant `b` is calculated as `mod.cond + RANDOMX_JUMP_OFFSET`.
632
623
1. A constant `cimm` is constructed as sign-extended `imm32` with bit `b` set to 1 and bit `b-1` set to 0 (if `b > 0`).
633
-
1.`cimm` is added to `creg`.
634
-
1. If bits `b` to `b + RANDOMX_JUMP_BITS - 1` of `creg`are zero, execution jumps to instruction `creg.lastUsed + 1` (the instruction following the instruction where `creg` was last modified).
624
+
1.`cimm` is added to the destination register.
625
+
1. If bits `b` to `b + RANDOMX_JUMP_BITS - 1` of the destination register are zero, the jump is executed (target is the instruction following the instruction where `dst` was last modified).
635
626
636
627
Bits in immediate and register values are numbered from 0 to 63 with 0 being the least significant bit. For example, for `b = 10` and `RANDOMX_JUMP_BITS = 8`, the bits are arranged like this:
`S` is a copied sign bit from `imm32`. `M` denotes bits of `imm32`. The 9th bit is set to 0 and the 10th bit is set to 1. This value would be added to `creg`.
634
+
`S` is a copied sign bit from `imm32`. `M` denotes bits of `imm32`. The 9th bit is set to 0 and the 10th bit is set to 1. This value will be added to `dst`.
644
635
645
-
The second line uses `X` to mark bits of `creg` that would be checked by the condition. If all these bits are 0 after adding `cimm`, the jump is executed.
636
+
The second line uses `X` to mark bits of `dst` that will be checked by the condition. If all these bits are 0 after adding `cimm`, the jump is executed.
646
637
647
638
The construction of the CBRANCH instruction ensures that no inifinite loops are possible in the program.
0 commit comments