4 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:
```
The name of the file: src/cmd/compile/internal/ssa/_gen/AMD64.rules
Insertions: 1, Deletions: 1.
@@ -1814,7 +1814,7 @@
(VPMOVMToVec64x8 (VCMPPD512 [3] x y))
// remove flags → bool → flags roundtrip
-// Only do it if the flag generating instruction is local otherwise the likely hood flagalloc wont undo this optimization and makes things worst are slim.
+// Only do it if the flag generating instruction is local otherwise the likelihood flagalloc won't undo this optimization and makes things worse are slim.
(NE t:(TESTQ x:(MOVBQZX s:(SET(EQ|NE|L|G|LE|GE|A|B|AE|BE|EQF|NEF|GF|GEF) flags)) x) yes no) && t.Block == s.Block => ((EQ|NE|LT|GT|LE|GE|UGT|ULT|UGE|ULE|EQF|NEF|UGE|UGT) flags yes no)
(NE t:(TESTL x:(MOVBQZX s:(SET(EQ|NE|L|G|LE|GE|A|B|AE|BE|EQF|NEF|GF|GEF) flags)) x) yes no) && t.Block == s.Block => ((EQ|NE|LT|GT|LE|GE|UGT|ULT|UGE|ULE|EQF|NEF|UGE|UGT) flags yes no)
(NE t:(TESTW x:(MOVBQZX s:(SET(EQ|NE|L|G|LE|GE|A|B|AE|BE|EQF|NEF|GF|GEF) flags)) x) yes no) && t.Block == s.Block => ((EQ|NE|LT|GT|LE|GE|UGT|ULT|UGE|ULE|EQF|NEF|UGE|UGT) flags yes no)
```
cmd/compile: remove flags → bool → flags roundtrips on amd64
Fixes #76056
Fixes #76060
If we modify the issue's fieldReduceOnce2 function to:
// fieldReduceOnce reduces a value a < 2q.
func fieldReduceOnce2(a uint32) fieldElement {
x, b := bits.Sub(uint(a), uint(q), 0)
return fieldElement(subtle.ConstantTimeSelect(int(b), int(a), int(x)))
}
We get the wanted assembly*:
MOVL AX, CX
MOVL AX, DX
SUBQ $8380417, CX
CMOVQCS DX, CX
MOVQ CX, AX ; not ideal code size but handled by the register renaming unit
RET
Changes made to fieldReduceOnce2:
- fixed a bug where a and x arguments to subtle.ConstantTimeSelect were swapped.
we should use a when the sub underflows and x otherwise.
- use bits.Sub rather than bits.Sub32 which is intriscified.
*we use CMOVQCS + MOVQ because the CMOV randomly gets generated backward,
I believe this would be fixed if we teach regalloc to commut CMOV
(by swapping the two register args and inverting the condition).
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |