Commit e24cfe8
authored
cmov: use
The core predication function of the portable implementation is called
`is_non_zero` and it returns a 1-bit mask value which is subsequently
used to "select" between two values using bitwise masking.
In some previous real-world cases in the Rust compiler, it has been able
to deduce, when using this sort of pattern in a loop, that the entire
loop can be skipped when e.g. the condition is zero.
[RUSTSEC-2024-0344](https://rustsec.org/advisories/RUSTSEC-2024-0344.html)
is one such example.
Adding a `black_box` in this position should hopefully help hint to the
compiler that we do not want such an "optimization" performed.
Note that the only thing we're actually relying on from `black_box` for
program correctness is that it behaves as an identity function, so this
will not have deleterious effects. Whether it actually helps avoid
problems like RUSTSEC-2024-0344 is something that can only be seen in
practice, unfortunately, as we don't have any way to get actual
guarantees out of the Rust compiler in cases where we can't use `asm!`.black_box in portable impl (#1255)1 parent 3f2d622 commit e24cfe8
1 file changed
+2
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
| 103 | + | |
104 | 104 | | |
0 commit comments