Module Tolk.Decomp_op

Operation decompositions matching tinygrad codegen/decomp/op.py.

This module owns the non-dtype operation rewrite families: Threefry, floor div/mod lowering, integer division by constants, late algebraic rewrites, and backend capability flags.

threefry2x32 x key is the software Threefry2x32 expansion of the 64-bit counter x and 64-bit key.

val magicgu : int -> int -> int * int

magicgu vmax d is (m, s) such that unsigned x / d is (x * m) >> s for all 0 <= x <= vmax.

Raises Invalid_argument if d <= 0 or no multiplier exists in the host integer range.

type supported_ops = {
  1. has_exp2 : bool;
  2. has_log2 : bool;
  3. has_sin : bool;
  4. has_sqrt : bool;
  5. has_neg : bool;
  6. has_sub : bool;
  7. has_max : bool;
  8. has_shl : bool;
  9. has_shr : bool;
  10. has_and : bool;
  11. has_or : bool;
  12. has_cmplt : bool;
  13. has_cmpeq : bool;
  14. has_fdiv : bool;
  15. has_threefry : bool;
  16. has_mulacc : bool;
  17. is_metal : bool;
  18. supports_dtype : Tolk_uop.Dtype.t -> bool;
  19. disable_fast_idiv : bool;
  20. force_transcendental : bool;
}

The type for backend operation capabilities used by decomp rewrites.

val get_simplifying_rewrite_patterns : supported_ops -> Tolk_uop.Uop.t -> Tolk_uop.Uop.t option

get_simplifying_rewrite_patterns ops u is the early rewrite for u, if one applies under ops.

val get_late_rewrite_patterns : supported_ops -> Tolk_uop.Uop.t -> Tolk_uop.Uop.t option

get_late_rewrite_patterns ops u is the late non-dtype rewrite for u, if one applies under ops.