alloy-rs / alloy-rs/ruint

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

Đang mở
#631 0 bình luận 0 reaction 1 người được giao Được @decofe nhận Xem trên GitHub
optimize tracker
Ngôn ngữ chính
Rust
Star
225
Fork
70
Merge trung bình
16 giờ 54 phút
Pull request đã merge (30 ngày)
8

Mô tả

*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)*

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
rust
Lĩnh vực
backend
Loại issue
Tái cấu trúc
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Sôi nổi
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.