(* default-layout.sml
*
* Functions for splitting LowIR vectors into TreeIR composite vectors.
*
* This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
*
* COPYRIGHT (c) 2016 The University of Chicago
* All rights reserved.
*)
structure DefaultLayout =
struct
(* given a list of native vector sizes in ascending order, return a function for
* mapping vector widths to TreeTypes.VecTy values.
*)
fun layout (sizes : int list) = let
(* find smallest supported vector width that is >= n; return the largest
* size if n is bigger than the largest supported vector.
*)
fun find (n, []) = raise Fail "impossible"
| find (n, [sz]) = sz
| find (sz::szs) = if (n <= sz) then sz else find(n, szs)
(* split n into pieces *)
fun split (n, pieces) = let
val sz = find (n, sizes)
val pieces = sz :: pieces
val m = n - sz
in
if (m = 0)
then (false, rev pieces)
else if (m < 0)
then (true, rev pieces)
else split (m, pieces)
end
in
fn n => let
val (padded, pieces) = split (n, [])
in
TreeTypes.VecTy(n, padded, pieces)
end
end
(* layout for a scalar target *)
fun scalar w = TreeTypes.VecTy(w, false, List.tabulate(w, fn _ => 1))
end