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

SCM Repository

[diderot] Diff of /branches/pure-cfg/src/compiler/high-to-mid/high-to-mid.sml
ViewVC logotype

Diff of /branches/pure-cfg/src/compiler/high-to-mid/high-to-mid.sml

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

revision 823, Thu Apr 14 14:28:33 2011 UTC revision 824, Thu Apr 14 15:54:24 2011 UTC
# Line 64  Line 64 
64    
65      fun renameList (env, xs) = List.map (fn x => rename(env, x)) xs      fun renameList (env, xs) = List.map (fn x => rename(env, x)) xs
66    
67      (* expand raising a real to an integer power.  When we know the exponent, we can inline
68       * multiplications.
69       *)
70        fun expandPower (env, y, [x, n]) = let
71              fun getConst x = (case SrcIL.Var.binding x
72                     of SrcIL.VB_RHS(SrcIL.VAR x') => getConst x'
73                      | SrcIL.VB_RHS(SrcIL.LIT(Literal.Int n)) => SOME n
74                      | vb => NONE
75                    (* end case *))
76              val x = rename(env, x)
77              fun pow () = let
78                    val t = DstIL.Var.new("n", DstTy.realTy)
79                    in [
80                      (t, DstIL.OP(DstOp.IntToReal, [rename(env, n)])),
81                      (y, DstIL.APPLY(ILBasis.pow, [x, t]))
82                    ] end
83              in
84                case getConst n
85                 of SOME 0 => [(y, DstIL.LIT(Literal.Float(FloatLit.one)))]
86                  | SOME 1 => [(y, DstIL.VAR x)]
87                  | SOME ~1 => let
88                      val t = DstIL.Var.new("one", DstTy.realTy)
89                      in [
90                        (t, DstIL.LIT(Literal.Float(FloatLit.one))),
91                        (y, DstIL.OP(DstOp.Div DstTy.realTy, [t, x]))
92                      ] end
93    (* FIXME: expand into multiplications
94                  | SOME n =>
95    *) | SOME _ => pow()
96                  | NONE => pow()
97              end
98    
99    (* expand the field Inside operator into a image-space test *)    (* expand the field Inside operator into a image-space test *)
100      fun expandInside (env, result, pos, fld) = (case getRHS fld      fun expandInside (env, result, pos, fld) = (case getRHS fld
101             of (SrcOp.Field d, [img, h]) => (case (getRHS img, getRHS h)             of (SrcOp.Field d, [img, h]) => (case (getRHS img, getRHS h)
# Line 160  Line 192 
192                | SrcOp.NEQ ty => assign (DstOp.NEQ(cvtTy ty))                | SrcOp.NEQ ty => assign (DstOp.NEQ(cvtTy ty))
193                | SrcOp.GT ty => assign (DstOp.GT(cvtTy ty))                | SrcOp.GT ty => assign (DstOp.GT(cvtTy ty))
194                | SrcOp.GTE ty => assign (DstOp.GTE(cvtTy ty))                | SrcOp.GTE ty => assign (DstOp.GTE(cvtTy ty))
195                  | SrcOp.Power => expandPower(env, y, args)
196                | SrcOp.Not => assign DstOp.Not                | SrcOp.Not => assign DstOp.Not
197                | SrcOp.Max => assign DstOp.Max                | SrcOp.Max => assign DstOp.Max
198                | SrcOp.Min => assign DstOp.Min                | SrcOp.Min => assign DstOp.Min
# Line 175  Line 208 
208                    in                    in
209                      expandOuter (env, y, d1, d2, v1, v2)                      expandOuter (env, y, d1, d2, v1, v2)
210                    end                    end
211    (* FIXME: extend Norm to arbitrary tensor types == sqrt(sum of squares) *)
212                | SrcOp.Norm ty => assign (DstOp.Norm(arity ty))                | SrcOp.Norm ty => assign (DstOp.Norm(arity ty))
213                | SrcOp.Normalize ty => assign (DstOp.Normalize(arity ty))                | SrcOp.Normalize ty => assign (DstOp.Normalize(arity ty))
214    (* FIXME: extend scaling to work on any tensor type *)
215                | SrcOp.Scale ty => assign (DstOp.Scale(arity ty))                | SrcOp.Scale ty => assign (DstOp.Scale(arity ty))
216                | SrcOp.InvScale ty => assign (DstOp.InvScale(arity ty))                | SrcOp.InvScale ty => assign (DstOp.InvScale(arity ty))
217                | SrcOp.CL => assign DstOp.CL                | SrcOp.CL => assign DstOp.CL

Legend:
Removed from v.823  
changed lines
  Added in v.824

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