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

SCM Repository

[diderot] Diff of /branches/charisee/src/compiler/tree-il/lowOp-to-treeOp.sml
ViewVC logotype

Diff of /branches/charisee/src/compiler/tree-il/lowOp-to-treeOp.sml

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

revision 2837, Wed Nov 19 23:42:17 2014 UTC revision 2838, Tue Nov 25 03:40:24 2014 UTC
# Line 9  Line 9 
9      structure DstOp = TreeOps      structure DstOp = TreeOps
10      structure DstTy = TreeILTypes      structure DstTy = TreeILTypes
11      structure Dst = TreeIL      structure Dst = TreeIL
12        structure DstSV=Dst.StateVar
13      structure DstV = Dst.Var      structure DstV = Dst.Var
14      structure Ty=TreeIL.Ty      structure Ty=TreeIL.Ty
15    
# Line 32  Line 33 
33      and addSca [e1]=e1      and addSca [e1]=e1
34      | addSca(e1::e2::es)= addSca([Dst.E_Op(DstOp.addSca,[e1,e2])]@es)      | addSca(e1::e2::es)= addSca([Dst.E_Op(DstOp.addSca,[e1,e2])]@es)
35    
36    
37    
38        (*can't use storeAligned when argument is broken into pieces*)
39        (*Decides if LoadAligned function is used*)
40        (*can't use loadAligned when argument is a matrix'*)
41        fun isAlignedLoad(isFill,Ty.TensorTy [_]) =(case isFill
42            of true => false
43            | _     => true
44            (*end case*))
45        |isAlignedLoad _ =false
46    
47      (**************************************)      (**************************************)
48      (*creates a load when it is not a local variable *)      (*creates a load when it is not a local variable *)
49      fun getArg(lhsKind,t,count,aligned, nSize, oSize,offset)=let      fun getArg(isFill,lhsKind,t,count, nSize, oSize,offset)=let
50          fun getExp (Dst.E_Var a) =(case (DstV.kind a)          fun getExp (Dst.E_Var a) =(case (DstV.kind a)
51              of TreeIL.VK_Local =>t              of TreeIL.VK_Local =>t
52              | _  => Dst.E_LoadArr(aligned, nSize,oSize,t, Dst.E_Lit(Literal.Int offset))              | _  => Dst.E_LoadArr(isAlignedLoad(isFill,DstV.ty a) ,nSize,oSize,t, Dst.E_Lit(Literal.Int offset))
53              (*end case*))              (*end case*))
54           | getExp(Dst.E_State _)=t           | getExp(Dst.E_State a)= Dst.E_LoadArr(isAlignedLoad(isFill,DstSV.ty a) ,nSize,oSize,t, Dst.E_Lit(Literal.Int offset))
55          | getExp (Dst.E_Mux(_,_,_,_,ops))= List.nth(ops,count)          | getExp (Dst.E_Mux(_,_,_,_,ops))= List.nth(ops,count)
56          | getExp a1 = raise Fail("Arg to vector op is not Mux or Var. Found: "^Dst.toString a1)          | getExp a1 = raise Fail("Arg to vector op is not Mux or Var. Found: "^Dst.toString a1)
57      in      in
58          getExp t          getExp t
59      end      end
60      and  mkOps(lhsKind,oldrator,rator,oSize,pieces,argScas,argVecs,aligned,indexAt)= let      and  mkOps(isFill,lhsKind,oldrator,rator,oSize,pieces,argScas,argVecs,indexAt)= let
61    
62          fun createOps ([], _,_, code) = code          fun createOps ([], _,_, code) = code
63          | createOps (nSize::es, count,offset, code)=let          | createOps (nSize::es, count,offset, code)=let
64              val argsLd =List.map (fn a =>getArg(lhsKind,a,count, aligned ,nSize, oSize, offset))  argVecs              val argsLd =List.map (fn a =>getArg(isFill,lhsKind,a,count, nSize, oSize, offset))  argVecs
65              val exp = (nSize, argScas@argsLd)              val exp = (nSize, argScas@argsLd)
66              in              in
67                  createOps (es, count+1,offset + IntInf.fromInt nSize, code@[exp])                  createOps (es, count+1,offset + IntInf.fromInt nSize, code@[exp])
68              end              end
69          in (case (oldrator,pieces,argVecs)          in (case (oldrator,pieces,argVecs)
70              of (SrcOp.ProjectTensor(_,_,Ty.indexTy[i],Ty.TensorTy[_,argTyX]),_,[a]) => let              of (SrcOp.ProjectTensor(_,_,indTy,argTy),_,[a]) => let
71                  (*Use Load expression instead of Project Operator *)                  (*Use Load expression instead of Project Operator *)
72                  val j=i*argTyX                  val shift=(case (indTy,argTy)
73                        of (Ty.indexTy[i],Ty.TensorTy[_,argTyX])=> i*argTyX
74                        | (Ty.indexTy[j,i],Ty.TensorTy[_,argTyY,argTyX])=> j*(argTyX*argTyY)+i*argTyX
75                        |  _ =>raise Fail "Project Tensor of a unhandled size"
76                     (*end case *))
77                  fun mkLoad ([], _, code) = code                  fun mkLoad ([], _, code) = code
78                  | mkLoad (nSize::es, offset, code)=let                  | mkLoad (nSize::es, offset, code)=let
79                      val exps=[Dst.E_LoadArr(aligned, nSize,oSize,a, Dst.E_Lit(Literal.Int offset))]  
80                        val A=(case a
81                             of  Dst.E_Var v =>isAlignedLoad(isFill,DstV.ty v)
82                             | Dst.E_State v=>isAlignedLoad(isFill,DstSV.ty v)
83                        (*end case*))
84                        val exps=[Dst.E_LoadArr(A, nSize,oSize,a, Dst.E_Lit(Literal.Int offset))]
85                      in                      in
86                          mkLoad (es, offset + IntInf.fromInt nSize, code@exps)                          mkLoad (es, offset + IntInf.fromInt nSize, code@exps)
87                      end                      end
88                  in                  in
89                      mkLoad (pieces, IntInf.fromInt j, [])                      mkLoad (pieces, IntInf.fromInt shift, [])
90                  end                  end
91              | (SrcOp.sumVec _,[nSize],[a]) =>              | (SrcOp.sumVec _,[nSize],[a]) =>
92                  [Dst.E_Op(DstOp.sumVec(nSize,oSize), [getArg(lhsKind,a,0, aligned, nSize, oSize, 0)])]                  [Dst.E_Op(DstOp.sumVec(nSize,oSize), [getArg(isFill,lhsKind,a,0, nSize, oSize, 0)])]
93              | (SrcOp.sumVec _,_,_) =>let              | (SrcOp.sumVec _,_,_) =>let
94                  val code=createOps (pieces, 0,indexAt, [])                  val code=createOps (pieces, 0,indexAt, [])
95                  in                  in
# Line 82  Line 104 
104          end          end
105      (**************************************)      (**************************************)
106    
107      fun isAligned isFill = (case isFill      fun isAligned(isFill,1) =(case isFill
108          of true => false          of true => false
109          | _     => true          | _     => true
110      (*end case*))      (*end case*))
111        |isAligned _ =false
112    
113    
114    
115          (**************************************)          (**************************************)
116      (*Main functions*)      (*Main functions*)
117      fun vecToTree(lhs,origrator,rator,nSize,oSize,pieces,argScas,argVecs,isFill)= let      fun vecToTree(lhs,origrator,rator,nSize,oSize,pieces,argScas,argVecs,isFill)= let
118          val splitTy=DstTy.vectorLength pieces          val splitTy=DstTy.vectorLength pieces
119          val aligned= isAligned isFill          val aligned= isAligned(isFill,length pieces)
120    
121          val indexAt=IntInf.fromInt 0          val indexAt=IntInf.fromInt 0
122          (*Create Ld Expressions and Tree Ops*)          (*Create Ld Expressions and Tree Ops*)
123          val lhsKind=DstV.kind lhs          val lhsKind=DstV.kind lhs
124          val ops=mkOps(lhsKind,origrator,rator,oSize,pieces,argScas,argVecs,aligned,indexAt)  
125            val ops=mkOps(isFill,lhsKind,origrator,rator,oSize,pieces,argScas,argVecs,indexAt)
126      in      in
127          mkStmt(lhs,lhsKind,origrator,isFill,oSize,aligned,splitTy,ops)          mkStmt(lhs,lhsKind,origrator,isFill,oSize,aligned,splitTy,ops)
128      end      end
# Line 109  Line 135 
135          val n=nSize-nArg          val n=nSize-nArg
136          val newArgs=List.tabulate(n, (fn _=>Dst.E_Lit(Literal.Int 0)))          val newArgs=List.tabulate(n, (fn _=>Dst.E_Lit(Literal.Int 0)))
137          val op1=Dst.E_Cons(nSize, oSize,args@newArgs)          val op1=Dst.E_Cons(nSize, oSize,args@newArgs)
138          val aligned= isAligned true          val aligned= isAligned(true,1)
139          val splitTy=DstTy.vectorLength [nSize]          val splitTy=DstTy.vectorLength [nSize]
140          in          in
141              Dst.E_Mux(aligned,true,oSize,splitTy,[op1])              Dst.E_Mux(aligned,true,oSize,splitTy,[op1])
142          end          end
143      | consVecToTree(_,_,_,_,true)= raise Fail"In ConsVecToTree-isFill with more than 1 piece"      | consVecToTree(_,_,_,_,true)= raise Fail"In ConsVecToTree-isFill with more than 1 piece"
144      | consVecToTree(nSize,oSize,pieces,args,isFill)= let      | consVecToTree(nSize,oSize,pieces,args,isFill)= let
145          val aligned= isAligned isFill          val aligned= isAligned(isFill,length pieces)
146          val splitTy=DstTy.vectorLength pieces          val splitTy=DstTy.vectorLength pieces
147          fun createOps ([], _,_,_) = []          fun createOps ([], _,_,_) = []
148          | createOps (nSize::es, offset,arg, code)=          | createOps (nSize::es, offset,arg, code)=
# Line 151  Line 177 
177          | SrcOp.PrincipleEvec ty =>    DstOp.PrincipleEvec ty          | SrcOp.PrincipleEvec ty =>    DstOp.PrincipleEvec ty
178          | SrcOp.EigenVals2x2 =>    DstOp.EigenVals2x2          | SrcOp.EigenVals2x2 =>    DstOp.EigenVals2x2
179          | SrcOp.EigenVals3x3 =>    DstOp.EigenVals3x3          | SrcOp.EigenVals3x3 =>    DstOp.EigenVals3x3
180    | SrcOp.EigenVecs2x2 =>    DstOp.EigenVecs2x2
181    | SrcOp.EigenVecs3x3 =>    DstOp.EigenVecs3x3
182          | SrcOp.Select(ty as SrcTy.TupleTy tys, i)  =>    DstOp.Select( ty, i)          | SrcOp.Select(ty as SrcTy.TupleTy tys, i)  =>    DstOp.Select( ty, i)
183          | SrcOp.Index (ty, i ) =>    DstOp.Index ( ty, i)          | SrcOp.Index (ty, i ) =>    DstOp.Index ( ty, i)
184          | SrcOp.Subscript ty =>    DstOp.Subscript  ty          | SrcOp.Subscript ty =>    DstOp.Subscript  ty
# Line 171  Line 199 
199          | SrcOp.prodSca=>DstOp.prodSca          | SrcOp.prodSca=>DstOp.prodSca
200          | SrcOp.divSca=>DstOp.divSca          | SrcOp.divSca=>DstOp.divSca
201          | SrcOp.Sqrt =>DstOp.Sqrt          | SrcOp.Sqrt =>DstOp.Sqrt
202            (*| SrcOp.Norm ty =>  (DstOp.Norm ty)*)
203            | SrcOp.Normalize d =>(DstOp.Normalize d)
204          | SrcOp.imgAddr(v,indexAt, dim)=>DstOp.imgAddr(v, indexAt, dim)          | SrcOp.imgAddr(v,indexAt, dim)=>DstOp.imgAddr(v, indexAt, dim)
205          | SrcOp.baseAddr V => DstOp.baseAddr V          | SrcOp.baseAddr V => DstOp.baseAddr V
206          (*EigenVecs,mkDynamic, Append,Prepend, Concat,Length,ImageAddress,LoadVoxel,Inputs, and Pritns*)          (*EigenVecs,mkDynamic, Append,Prepend, Concat,Length,ImageAddress,LoadVoxel,Inputs, and Pritns*)

Legend:
Removed from v.2837  
changed lines
  Added in v.2838

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