Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/vis15/src/compiler/mid-to-low/mk-low-ir.sml
ViewVC logotype

Diff of /branches/vis15/src/compiler/mid-to-low/mk-low-ir.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3664, Fri Feb 5 15:38:30 2016 UTC revision 3665, Sat Feb 6 16:18:59 2016 UTC
# Line 31  Line 31 
31      val realDiv : AvailRHS.t * LowIR.var * LowIR.var -> LowIR.var      val realDiv : AvailRHS.t * LowIR.var * LowIR.var -> LowIR.var
32      val realNeg : AvailRHS.t * LowIR.var -> LowIR.var      val realNeg : AvailRHS.t * LowIR.var -> LowIR.var
33    
34      (* vector arithmetic *)
35        val vecAdd   : AvailRHS.t * int * LowIR.var * LowIR.var -> LowIR.var
36        val vecSub   : AvailRHS.t * int * LowIR.var * LowIR.var -> LowIR.var
37        val vecScale : AvailRHS.t * int * LowIR.var * LowIR.var -> LowIR.var
38        val vecMul   : AvailRHS.t * int * LowIR.var * LowIR.var -> LowIR.var
39        val vecNeg   : AvailRHS.t * int * LowIR.var -> LowIR.var
40        val vecSum   : AvailRHS.t * int * LowIR.var -> LowIR.var
41        val vecProj  : AvailRHS.t * int * LowIR.var * int -> LowIR.var
42    
43      (* tensor operations *)
44        val tensorIndex : AvailRHS.t * index_env * LowIR.var * Ein.alpha -> LowIR.var
45    
46    (* make "x := [args]" *)    (* make "x := [args]" *)
47      val cons : AvailRHS.t * int list * LowIR.var list -> LowIR.var      val cons : AvailRHS.t * int list * LowIR.var list -> LowIR.var
48    (* code for δ_{i,j} *)    (* code for δ_{i,j} *)
# Line 52  Line 64 
64      structure E = Ein      structure E = Ein
65      structure IMap = IntRedBlackMap      structure IMap = IntRedBlackMap
66    
67      (* pick the n'th elements from a pair of lists *)
68        fun nthPair (x::_, y::_, 0) = (x, y)
69          | nthPair (_::xs, _::ys, n) = nthPair (xs, ys, n-1)
70          | nthPair _ = raise Subscript
71    
72       fun lookupMu (mapp, E.V id) = (case IMap.find (mapp, id)
73              of SOME n => n
74               | NONE => raise Fail(concat["lookupMu(_, V ", Int.toString id, "): out of bounds"])
75             (* end case *))
76         | lookupMu (_, E.C i) = i
77    
78       fun lookupIdx (mapp, id) = (case IMap.find(mapp, id)
79              of SOME x => x
80               | NONE => raise Fail(concat["lookupIdx(_, V ", Int.toString id, "): out of bounds"])
81             (* end case *))
82    
83    (* an environment that maps De Bruijn indices to their iteration-index value *)    (* an environment that maps De Bruijn indices to their iteration-index value *)
84      type index_env = int IMap.map      type index_env = int IMap.map
85    
# Line 61  Line 89 
89      fun realLit (avail, r) = add (avail, "realLit", Ty.realTy, IR.LIT(Literal.Real r))      fun realLit (avail, r) = add (avail, "realLit", Ty.realTy, IR.LIT(Literal.Real r))
90      fun intToRealLit (avail, n) = realLit (avail, RealLit.fromInt(IntInf.fromInt n))      fun intToRealLit (avail, n) = realLit (avail, RealLit.fromInt(IntInf.fromInt n))
91    
92      fun cons (avail, shp, args) = add (avail, "tensor", Ty.TensorTy shp, IR.CONS(args, Ty.TensorTy shp))      fun cons (avail, shp, args) =
93              add (avail, "tensor", Ty.TensorTy shp, IR.CONS(args, Ty.TensorTy shp))
94    
95        fun reduce (avail, rator, []) = raise Fail "reduction with no arguments"
96          | reduce (avail, rator, arg::args) = let
97              fun gen (acc, []) = acc
98                | gen (acc, x::xs) = gen (rator (avail, acc, x), xs)
99              in
100                gen (arg, args)
101              end
102    
103    (* scalar arithmetic *)    (* scalar arithmetic *)
104      local      local
# Line 74  Line 111 
111      fun realNeg (avail, x) = add (avail, "r", Ty.realTy, IR.OP(Op.RNeg, [x]))      fun realNeg (avail, x) = add (avail, "r", Ty.realTy, IR.OP(Op.RNeg, [x]))
112      end (* local *)      end (* local *)
113    
114      fun reduce (avail, rator, []) = raise Fail "reduction with no arguments"    (* vector arithmetic *)
       | reduce (avail, rator, arg::args) = let  
           fun gen (acc, []) = acc  
             | gen (acc, x::xs) = gen (rator (avail, acc, x), xs)  
           in  
             gen (arg, args)  
           end  
   
115      local      local
116        fun lookupMu (mapp, E.V id) = (case IMap.find (mapp, id)        fun vecOp1 rator (avail, dim, x) =
117               of SOME n => n              add (avail, "v", Ty.TensorTy[dim], IR.OP(rator dim, [x]))
118                | NONE => raise Fail(concat["lookupMu(_, V ", Int.toString id, "): out of bounds"])        fun vecOp2 rator (avail, dim, x, y) =
119              (* end case *))              add (avail, "v", Ty.TensorTy[dim], IR.OP(rator dim, [x, y]))
120          | lookupMu (_, E.C i) = i      in
121        fun lookupIdx (mapp, id) = (case IMap.find(mapp, id)      val vecAdd = vecOp2 Op.VAdd
122               of SOME x => x      val vecSub = vecOp2 Op.VSub
123                | NONE => raise Fail(concat["lookupIdx(_, V ", Int.toString id, "): out of bounds"])      val vecScale = vecOp2 Op.VScale
124              (* end case *))      val vecMul = vecOp2 Op.VMul
125      in      val vecNeg = vecOp1 Op.VNeg
126        val vecSum = vecOp1 Op.VSum
127        fun vecProj (avail, dim, x, i) =
128              add (avail, "v", Ty.TensorTy[dim], IR.OP(Op.VProj(dim, i), [x]))
129        end (* local *)
130    
131        fun tensorIndex (avail, mapp, arg, []) = arg
132          | tensorIndex (avail, mapp, arg, ix) =
133              add (
134                avail, "r", Ty.realTy,
135                IR.OP(Op.TensorIndex(V.ty arg, List.map (fn id => lookupMu(mapp, id)) ix), [arg]))
136    
137      fun evalDelta (mapp, i, j) = let      fun evalDelta (mapp, i, j) = let
138            val i' = lookupMu (mapp, i)            val i' = lookupMu (mapp, i)
139            val j' = lookupMu (mapp, j)            val j' = lookupMu (mapp, j)
# Line 129  Line 170 
170                else intToRealLit (avail, ~1)                else intToRealLit (avail, ~1)
171            end            end
172    
     end (* local *)  
   
173    end    end

Legend:
Removed from v.3664  
changed lines
  Added in v.3665

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0