4343 * sensitive ; since aborting the program will be quicker than completing it,
4444 * the flag's value is likely clearly visible to an attacker through timing.
4545 *
46- * @param [ in ] w31: all - zero
4746 * @param [ in ] FG0.Z: boolean indicating fault condition
4847 *
49- * clobbered registers: x2
48+ * clobbered registers: x2 , w31
5049 * clobbered flag groups: none
5150 * /
5251trigger_fault_if_fg0_z:
5352 / * Read the FG0.Z flag (position 3 ).
5453 x2 <= FG0.Z * /
5554 csrrw x2 , FG0 , x0
5655 andi x2 , x2 , 8
57- srli x2 , x2 , 3
56+ addi x2 , x2 , 31
5857
59- / * Subtract FG0.Z from 0 .
60- x2 <= 0 - x2 = FG0.Z ? 2 ^ 32 - 1 : 0 * /
61- sub x2 , x0 , x2
62-
63- / * The `bn.lid` instruction causes an `BAD_DATA_ADDR` error if the
64- memory address is out of bounds. Therefore , if FG0.Z is 1 , this
65- instruction causes an error , but if FG0.Z is 0 it simply loads the word at
66- address 0 into w31. * /
67- li x3 , 31
68- bn.lid x3 , 0 (x2)
58+ / * The `bn.lid` instruction causes an `ILLEGAL_INSN` error if the index of the
59+ bignum register (stored in x2 in this case) is invalid. Therefore , if FG0.Z
60+ is 1 , this instruction causes an error , but if FG0.Z is 0 it simply loads
61+ the word at address 0 into w31. * /
62+ bn.lid x2 , 0 (x0)
6963
7064 / * If we get here , the flag must have been 0 . Restore w31 to zero and return.
7165 w31 <= 0 * /
72- bn. xor w31 , w31 , w31
66+ bn. xor w31 , w31 , w31
7367
7468 ret
7569
@@ -84,29 +78,28 @@ trigger_fault_if_fg0_z:
8478 * sensitive ; since aborting the program will be quicker than completing it,
8579 * the flag's value is likely clearly visible to an attacker through timing.
8680 *
87- * @param [ in ] w31: all - zero
8881 * @param [ in ] FG0.Z: boolean indicating fault condition
8982 *
90- * clobbered registers: x2
83+ * clobbered registers: x2 , w31
9184 * clobbered flag groups: none
9285 * /
9386trigger_fault_if_fg0_not_z:
9487 / * Read the FG0.Z flag (position 3 ).
9588 x2 <= FG0.Z * /
9689 csrrw x2 , FG0 , x0
9790 andi x2 , x2 , 8
98- slli x2 , x2 , 3
91+ xori x2 , x2 , 8
92+ addi x2 , x2 , 31
9993
100- / * The `bn.lid` instruction causes an `BAD_DATA_ADDR` error if the
101- memory address is out of bounds. Therefore , if FG0.Z is 1 , this
102- instruction causes an error , but if FG0.Z is 0 it simply loads the word at
103- address 0 into w31. * /
104- li x3 , 31
105- bn.lid x3 , 0 (x2)
94+ / * The `bn.lid` instruction causes an `ILLEGAL_INSN` error if the index of the
95+ bignum register (stored in x2 in this case) is invalid. Therefore , if FG0.Z
96+ is 0 , this instruction causes an error , but if FG0.Z is 1 it simply loads
97+ the word at address 0 into w31. * /
98+ bn.lid x2 , 0 (x0)
10699
107- / * If we get here , the flag must have been 1 . Restore w31 to zero and return.
100+ / * If we get here , the flag must have been 0 . Restore w31 to zero and return.
108101 w31 <= 0 * /
109- bn. xor w31 , w31 , w31
102+ bn. xor w31 , w31 , w31
110103
111104 ret
112105
0 commit comments