alloy-rs / alloy-rs/ruint

`algorithms/div/knuth`: Can we re-use `r` here somehow? The problem is we

Ouverte
#631 0 commentaires 0 réactions 1 personne assignée Réclamée par @decofe Voir sur GitHub
optimize tracker
Langage dominant
Rust
Étoiles
225
Forks
70
Merge moyen
16 h 54 min
PR mergées (30 j)
8

Description

*On 2026-08-31 @decofe wrote in [`a9450b4`](https://github.com/alloy-rs/ruint/commit/a9450b499c03f259238c2955b9512de873a77e12) “chore: apply latest nightly rustfmt (#627)”:*

Can we re-use `r` here somehow? The problem is we
can not just shift the `r` or
borrow` because we need to accurately reproduce
the remainder and carry in the middle of a limb.
SAFETY: both slices have length `n`.

```rust
let (r, borrow) = r.overflowing_sub(u128::from(borrow));
numerator[j + n - 2] = DW::low(r);
numerator[j + n - 1] = DW::high(r);
borrow
} else {
// OPT: Can we re-use `r` here somehow? The problem is we
// can not just shift the `r` or
// `borrow` because we need to accurately reproduce
// the remainder and carry in the middle of a limb.
// SAFETY: both slices have length `n`.
let borrow = unsafe { submul_nx1(&mut numerator[j..j + n], divisor, q) };
let n2 = numerator.get(j + n).copied().unwrap_or_default();
borrow != n2
};

```
*From [`src/algorithms/div/knuth.rs:178`](https://github.com/alloy-rs/ruint/blob/a9450b499c03f259238c2955b9512de873a77e12/src/algorithms/div/knuth.rs#L178)*

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

Start in src/algorithms/div/knuth.rs around line 178 and read the surrounding Knuth division logic, including submul_nx1 and the handling of r, borrow, and n2. Determine whether r can be reused in the else branch without changing the accurately reproduced remainder or carry; done means the optimization is justified and preserves the existing division behavior.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
rust
Domaine
backend
Type d'issue
Refactorisation
Difficulté
4/5
Temps estimé
3-5 jours
Activité
Active
Clarté
Clairement spécifiée
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.