makepad/libs/relax/compiler/tests/mul_overflow.rs
Admin b22a714840 makepad run: the Rust JIT (libs/relax) and makepad-remote
The JIT that runs makepad apps from source: lexer, front end, type checker,
lazy borrow checker (Gandalf; `--check-first` opts in), codegen, session and
warm/cold caches keyed by compiler stamp, provided crates bound late,
startup images, live patching. User-facing name is `makepad run` (binary
`makepad`, MAKEPAD_RUN_* env, ~/.makepad-run); libs/relax stays the internal
library name. `makepad check` reports rustc-style diagnostics with rustc
error codes and checks a whole workspace (`--workspace`). Runs on macOS,
Linux, Windows and Android. makepad-remote: one tool schema for apps and the
WM (app/1): grabs, captures, traces, frame profiles and tweaks.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-13 12:26:21 +02:00

26 lines
1.1 KiB
Rust

// u64/i64/usize/isize overflowing/checked/saturating_mul through intrinsics_int::mul_hi
// (umulh/smulh, mul/imul rdx). rustc prints the same hash: 10587128077786417075
#[test]
fn mul_overflow() {
let us: [u64; 8] = [0, 1, 2, 3, 0xffff_ffff, 0x1_0000_0000, u64::MAX / 3, u64::MAX];
let is: [i64; 10] = [0, 1, -1, 2, -2, 0xffff_ffff, -0x1_0000_0000, i64::MAX, i64::MIN, i64::MIN / 3];
let mut h = 0u64;
for &a in us.iter() {
for &b in us.iter() {
let (r, o) = std::hint::black_box(a).overflowing_mul(b);
h = h.rotate_left(3) ^ r ^ (o as u64);
h ^= a.checked_mul(b).unwrap_or(7);
h ^= (a as usize).saturating_mul(b as usize) as u64;
}
}
for &a in is.iter() {
for &b in is.iter() {
let (r, o) = std::hint::black_box(a).overflowing_mul(b);
h = h.rotate_left(3) ^ (r as u64) ^ (o as u64);
h ^= a.checked_mul(b).unwrap_or(7) as u64;
h ^= (a as isize).saturating_mul(b as isize) as u64;
}
}
println!("mulhi hash {}", h);
}