Script.fast_divmod¶
- Script.fast_divmod(a, b)¶
Fast integer division and modulo using precomputed magic multiplier.
Computes
(a // b, a % b)fora >= 0andb > 0using the FastDivmod algorithm. The divisorbmust be a grid-constant expression (known at kernel launch time). A Hidet IR pass will lower this to__umulhi(a, magic) >> shiftwith host-side precomputation of(magic, shift)fromb.- Parameters:
a (Expr) – The dividend (int32, must be >= 0).
b (Expr) – The divisor (int32, must be > 0 and grid-constant).
- Returns:
quotient (Expr) – floor(a / b)
remainder (Expr) – a % b (computed as a - quotient * b)
- Return type:
tuple
Notes
Thread group: Can be executed by any sized thread group.