Home My Page Projects Code Snippets Project Openings diderot

# SCM Repository

[diderot] View of /branches/vis15/src/compiler/tree-ir/vector-layout.sml
 [diderot] / branches / vis15 / src / compiler / tree-ir / vector-layout.sml

# View of /branches/vis15/src/compiler/tree-ir/vector-layout.sml

Thu May 5 19:55:46 2016 UTC (3 years, 4 months ago) by jhr
Original Path: branches/vis15/src/compiler/low-to-tree/default-layout.sml
File size: 1261 byte(s)
```  Working on merge
```
```(* 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
*)

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