Script.fast_divmod

Script.fast_divmod

Script.fast_divmod(a, b)

Fast integer division and modulo using precomputed magic multiplier.

Computes (a // b, a % b) for a >= 0 and b > 0 using the FastDivmod algorithm. The divisor b must be a grid-constant expression (known at kernel launch time). A Hidet IR pass will lower this to __umulhi(a, magic) >> shift with host-side precomputation of (magic, shift) from b.

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.