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

# SCM Repository

[diderot] Diff of /trunk/src/compiler/mid-to-low/mid-to-low.sml
 [diderot] / trunk / src / compiler / mid-to-low / mid-to-low.sml

# Diff of /trunk/src/compiler/mid-to-low/mid-to-low.sml

revision 460, Wed Oct 27 16:11:13 2010 UTC revision 463, Wed Oct 27 22:48:59 2010 UTC
# Line 17  Line 17
17      structure SrcOp = MidOps      structure SrcOp = MidOps
18      structure VTbl = SrcIL.Var.Tbl      structure VTbl = SrcIL.Var.Tbl
19      structure DstIL = LowIL      structure DstIL = LowIL
20        structure DstTy = LowTypes
21      structure DstOp = LowOps      structure DstOp = LowOps
22
23      type var_env = DstIL.var VTbl.hash_table      type var_env = DstIL.var VTbl.hash_table
# Line 32  Line 33
33            (* end case *))            (* end case *))
34      fun renameList (env, xs) = List.map (fn x => rename(env, x)) xs      fun renameList (env, xs) = List.map (fn x => rename(env, x)) xs
35
36      (* convert a rational to a FloatLit.float value.  We do this by long division
37       * with a cutoff when we get to 12 digits.
38       *)
39        fun ratToFloat r = (case Rational.explode r
40               of {sign=0, ...} => FloatList.zero
41                | {sign, num, denom=1} => FloatLit.fromInt(sign * IntInf.toInt num)
42                | {sign, num, denom} => let
43                  (* normalize so that num <= denom *)
44                    val (denom, exp) = let
45                          fun lp (n, denom) = if (denom < num)
46                                then lp(n+1, denom*10)
47                                else (n, denom)
48                          in
49                            lp (0, denom)
50                          end
51                  (* normalize so that num <= denom < 10*num *)
52    (* FIXME *)
53                  (* divide num/denom, computing the resulting digits *)
54                    fun divLp (n, a) = let
55                          val (q, r) = IntInf.divMod(a, denom)
56                          in
57                            if (r = 0) then (q, [])
58                            else if (n < 12) then let
59                              val (d, dd) = divLp(n+1, 10*r)
60                              in
61                                if (d < 10) then (q, d::dd) else (q+1, 0::dd)
62                              end
63                            else if (IntInf.div(10*r, denom) < 5)
64                              then (q, [])
65                              else (q+1, []) (* round up *)
66                          end
67                    val digits = divLp (0, a)
68                    in
69    (* FIXME *)
70                    end
71
72      (* variable names for kernel coefficients *)
73    (* expand the EvalKernel operations into vector operations.  The parameters are    (* expand the EvalKernel operations into vector operations.  The parameters are
74     *    result  -- the lhs variable to store the result     *    result  -- the lhs variable to store the result
75     *    d       -- the vector width of the operation, which should be equal to twice the     *    d       -- the vector width of the operation, which should be equal to twice the
# Line 39  Line 77
77     *    h       -- the kernel     *    h       -- the kernel
78     *    k       -- the derivative of the kernel to evaluate     *    k       -- the derivative of the kernel to evaluate
79     *)     *)
80      fun expandEvalKernel (result, d, h, k) = let      fun expandEvalKernel (result, d, h, k, [x]) = let
81            val {isCont, segs} = Kernel.curve (h, k)            val {isCont, segs} = Kernel.curve (h, k)
82              val deg = List.length segs - i
83            (* convert to a vector of vectors to give fast access *)
84              val segs = Vector.fromList (List.map Vector.fromList segs)
85            (* get the kernel coefficient value for the d'th term of the i'th
86             * segment.
87             *)
88              fun coefficient d i = ratToFloat (Vector.sub (Vector.sub(segs, i), d))
89              val ty = DstTy.VecTy d
90              val coeffs = List.tabulate (deg+1,
91                    fn i => DstIL.Var.new(str(chr(ord #"a" + (deg - i)))), ty)
92            (* define coefficient vectors *)
93              val coeffVecs = ???
94            (* build the evaluation of the polynomials in reverse order *)
95              fun eval [coeff] = (coeff, coeffVecs)
96                | eval (coeff::r) = let
97                    val (t1, stms) = eval r
98                    val t2 = DstIL.Var.new ("_t", ty)
99                    val t3 = DstIL.Var.new ("_s", ty)
100                    val stms =
101                          (t3, DstIL.OP(DstOp.Add ty, [coeff, t2])) ::
102                          (t2, DstIL.OP(DstOp.Mul ty, [x, t1])) ::
103                          stms
104                    in
105                      (t3, stms)
106                    end
107            in            in
108  raise Fail "unimplemented"              List.rev (eval coeffs)
109            end            end
110
111    (* compute the load address for a given set of voxels indices *)    (* compute the load address for a given set of voxels indices *)

Legend:
 Removed from v.460 changed lines Added in v.463

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