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

SCM Repository

[diderot] Annotation of /trunk/src/compiler/c-util/c-names.sml
ViewVC logotype

Annotation of /trunk/src/compiler/c-util/c-names.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3349 - (view) (download)

1 : jhr 1372 (* c-names.sml
2 :     *
3 : jhr 3349 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     *
5 :     * COPYRIGHT (c) 2015 The University of Chicago
6 : jhr 1372 * All rights reserved.
7 :     *)
8 :    
9 :     structure CNames =
10 :     struct
11 :    
12 :     local
13 :     structure Ty = TreeIL.Ty
14 :     structure F = Format
15 :     in
16 :    
17 :     open RuntimeNames
18 :    
19 :     (* globals that specify the target characteristics. These should be initialized
20 :     * when the program object is created.
21 :     *)
22 :     val doublePrecision = ref false
23 : jhr 1923 val longInt = ref false
24 : jhr 1372 val gVectorWid = ref 4
25 :     val gIntTy = ref CLang.int32
26 :     val gRealTy = ref CLang.float
27 :     val gRealSuffix = ref "?"
28 :     val gIntSuffix = ref "?"
29 :     val gIntFormat = ref "?"
30 :    
31 :     (* initialize globals based on target precision *)
32 : jhr 1640 fun initTargetSpec {double, long} = (
33 : jhr 1372 doublePrecision := double;
34 : jhr 1923 longInt := long;
35 : jhr 1372 if double
36 :     then (
37 :     gVectorWid := 2;
38 :     gRealTy := CLang.double;
39 : jhr 1640 gRealSuffix := "d")
40 : jhr 1372 else (
41 :     gVectorWid := 4;
42 : jhr 1640 gRealTy := CLang.float;
43 :     gRealSuffix := "f");
44 :     if long
45 :     then (
46 :     gIntTy := CLang.int64;
47 :     gIntSuffix := "l";
48 :     gIntFormat := "%ld")
49 :     else (
50 : jhr 1372 gIntTy := CLang.int32;
51 : jhr 1640 gIntSuffix := "i";
52 : jhr 1372 gIntFormat := "%d"))
53 :    
54 : jhr 1640 fun addVecSuffix stem n = concat[stem, Int.toString n]
55 :     fun addIVecSuffix stem n = concat[stem, Int.toString n]
56 : jhr 1372
57 : jhr 1640 fun addTySuffix (stem, 1) = stem
58 : jhr 1372 | addTySuffix (stem, n) = addVecSuffix stem n
59 :    
60 :     fun vecTy n = concat["vec", Int.toString n, !gRealSuffix, "_t"]
61 :     fun ivecTy n = concat["vec", Int.toString n, !gIntSuffix, "_t"]
62 : jhr 2356 fun unionTy n = concat["union", Int.toString n, !gRealSuffix, "_t"]
63 :     fun iunionTy n = concat["union", Int.toString n, !gIntSuffix, "_t"]
64 : jhr 1372 fun imageTy n = concat["Diderot_image", Int.toString n, "D_t"]
65 :     fun matTy (n, m) = concat["Diderot_Mat", Int.toString n, "x", Int.toString m, "_t"]
66 : jhr 2356 fun ten3Ty (n, m, l) = concat["Diderot_Ten", Int.toString n, "x", Int.toString m, "x", Int.toString l, "_t"]
67 : jhr 1372
68 : jhr 2356 val dynSeqTy = "Diderot_DynSeq_t"
69 :    
70 : jhr 1372 (* scalar math functions *)
71 : jhr 1640 fun max () = "max"
72 :     fun min () = "min"
73 :     fun fabs () = "fabs"
74 : jhr 1372
75 :     (* clamp and lerp *)
76 :     fun clamp n = addTySuffix("clamp", n)
77 :     fun lerp n = addTySuffix("lerp", n)
78 :    
79 :     (* vector math functions *)
80 : jhr 2636 val loadVec = addVecSuffix "loadVec"
81 : jhr 1372 val mkVec = addVecSuffix "vec"
82 : jhr 2356 val mkIVec = addVecSuffix "ivec"
83 : jhr 1372 val scale = addVecSuffix "scale"
84 :     val truncToInt = addVecSuffix "truncToInt"
85 :     val dot = addVecSuffix "dot"
86 :     fun cross () = addVecSuffix "cross" 3
87 :     val length = addVecSuffix "length"
88 :     val normalize = addVecSuffix "normalize"
89 : jhr 1640 fun vecitof n = concat["vec", Int.toString n, "itor"]
90 :     fun vecftoi n = concat["vec", Int.toString n, "rtoi"]
91 : jhr 1372
92 :     (* matrix operations *)
93 : jhr 1640 fun zeroMat (n, m) = concat["zero", Int.toString n, "x", Int.toString m]
94 :     fun identityMat n = concat["identity", Int.toString n, "x", Int.toString n]
95 :     fun trace n = concat["trace", Int.toString n, "x", Int.toString n]
96 : jhr 2356 fun normMat (n, m) = concat["norm", Int.toString n, "x", Int.toString m]
97 : jhr 1640 fun copyMat (n, m) = concat["copy", Int.toString n, "x", Int.toString m]
98 :     fun scaleMat (n, m) = concat["scale", Int.toString n, "x", Int.toString m]
99 :     fun addMat (n, m) = concat["add", Int.toString n, "x", Int.toString m]
100 :     fun subMat (n, m) = concat["sub", Int.toString n, "x", Int.toString m]
101 :     fun mulVecMat (m, n) = F.format "mulVec%dMat%dx%d" [F.INT m, F.INT m, F.INT n]
102 :     fun mulMatVec (m, n) = F.format "mulMat%dx%dVec%d" [F.INT n, F.INT m, F.INT n]
103 :     fun mulMatMat (m, n, p) = F.format "mulMat%dx%dMat%dx%d" [F.INT m, F.INT n, F.INT n, F.INT p]
104 : jhr 2356 fun transposeMat (n, m) = concat["transpose", Int.toString n, "x", Int.toString m]
105 : jhr 1372
106 : jhr 2356 (* 3rd-order tensor operations *)
107 :     fun copyTen3 (n, m, l) = F.format "copyTen%dx%dx%d" [F.INT n, F.INT m, F.INT l]
108 :     fun normTen3 (n, m, p) = concat["normTen", Int.toString n, "x", Int.toString m, "x", Int.toString p]
109 :     fun mulVecTen3 (m, n, p) = F.format "mulVec%dTen%dx%dx%d" [F.INT m, F.INT m, F.INT n, F.INT p]
110 :     fun mulTen3Vec (m, n, p) = F.format "mulTen%dx%dx%dVec%d" [F.INT m, F.INT n, F.INT p, F.INT p]
111 :    
112 :     (* colon-product operators *)
113 :     local
114 :     fun chkDim (d1 : int, d2 : int, d1', d2') =
115 :     if (d1 = d1') andalso (d2 = d2')
116 :     then ()
117 :     else raise Fail "mismatched dimensions for \":\" operator"
118 :     fun fmtName (fmt, l) = F.format fmt (List.map F.INT l)
119 :     in
120 :     fun colonMul ([d1, d2], [d1', d2']) = (
121 :     chkDim (d1, d2, d1', d2');
122 :     fmtName ("colonProdMat%dx%dMat%dx%d", [d1, d2, d1', d2']))
123 :     | colonMul ([d1, d2], [d1', d2', d3']) = (
124 :     chkDim (d1, d2, d1', d2');
125 :     fmtName ("colonProdMat%dx%dTen%dx%dx%d", [d1, d2, d1', d2', d3']))
126 :     | colonMul ([d1, d2, d3], [d2', d3']) = (
127 :     chkDim (d2, d3, d2', d3');
128 :     fmtName ("colonProdTen%dx%dx%dMat%dx%d", [d1, d2, d3, d2', d3']))
129 :     | colonMul ([d1, d2, d3], [d2', d3', d4']) = (
130 :     chkDim (d2, d3, d2', d3');
131 :     fmtName ("colonProdTen%dx%dx%dTen%dx%dx%d", [d1, d2, d3, d2', d3', d4']))
132 :     | colonMul _ = raise Fail "unsupported type for \":\" operator"
133 :     end
134 :    
135 : jhr 1372 (* Status_t symbols *)
136 :     val kActive = "DIDEROT_ACTIVE"
137 :     val kDie = "DIDEROT_DIE"
138 :     val kStabilize = "DIDEROT_STABILIZE"
139 :    
140 :     val toImageSpace = addVecSuffix "ToImageSpace"
141 :     fun toWorldSpace ty = let
142 :     val suffix = (case ty
143 : jhr 1640 of Ty.TensorTy[d] => [Int.toString d]
144 :     | Ty.TensorTy[m,n] => [Int.toString n, "x", Int.toString n]
145 : jhr 2356 | Ty.TensorTy[m,n,p] => [Int.toString n, "x", Int.toString n, "x", Int.toString p]
146 : jhr 1372 (* end case *))
147 :     in
148 :     concat("ToWorldSpace" :: suffix)
149 :     end
150 :     val inside = addVecSuffix "Inside"
151 :    
152 :     end (* local *)
153 :     end

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