alloy-rs / alloy-rs/ruint

`algorithms/mod`: This only black-boxes `acc` so LLVM keeps the subtraction results

Offen
#581 0 Kommentare 0 Reaktionen 1 zugewiesene Person Beansprucht von @prestwich Auf GitHub ansehen
hack tracker
Vorherrschende Sprache
Rust
Sterne
225
Forks
70
Ø Merge
16 Std. 54 Min.
Gemergte PRs (30 T.)
8

Beschreibung

*On 2026-04-30 @prestwich wrote in [`836a44f`](https://github.com/recmo/uint/commit/836a44f22fd30281b354f7a5c54872e8852d2505) “Merge pull request #579 from DaniPopes/cmp-with-sub-revived”:*

This only black-boxes `acc` so LLVM keeps the subtraction results
alive long enough for the backend to recognize the `borrowing_sub` chain
and generate better code: https://github.com/rust-lang/rust/issues/143517
SAFETY: Writing to a local variable through a reference is safe.

```rust
for i in 0..a.len() {
let x;
(x, borrow) = borrowing_sub(a[i], b[i], borrow);
acc |= x;
}
// HACK: This only black-boxes `acc` so LLVM keeps the subtraction results
// alive long enough for the backend to recognize the `borrowing_sub` chain
// and generate better code: https://github.com/rust-lang/rust/issues/143517
// SAFETY: Writing to a local variable through a reference is safe.
unsafe { core::ptr::write_volatile(&mut acc, acc) };
(acc, borrow)
}

#[inline]

```
*From [`src/algorithms/mod.rs:188`](https://github.com/recmo/uint/blob/836a44f22fd30281b354f7a5c54872e8852d2505/src/algorithms/mod.rs#L188)*

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.