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

SCM Repository

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

Annotation of /trunk/src/compiler/c-target/runtime-names.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1295 - (view) (download)

1 : jhr 1115 (* runtime-names.sml
2 :     *
3 :     * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *)
6 :    
7 :     structure RuntimeNames =
8 :     struct
9 :    
10 :     local
11 :     structure Ty = TreeIL.Ty
12 :     structure F = Format
13 :     in
14 :    
15 :     (* globals that specify the target characteristics. These should be initialized
16 :     * when the program object is created.
17 :     *)
18 : jhr 1232 val doublePrecision = ref false
19 : jhr 1115 val gVectorWid = ref 4
20 :     val gIntTy = ref CLang.int32
21 :     val gRealTy = ref CLang.float
22 :     val gRealSuffix = ref "?"
23 :     val gIntSuffix = ref "?"
24 :     val gIntFormat = ref "?"
25 :    
26 :     (* initialize globals based on target precision *)
27 : jhr 1232 fun initTargetSpec double = (
28 :     doublePrecision := double;
29 :     if double
30 :     then (
31 :     gVectorWid := 2;
32 :     gIntTy := CLang.int64;
33 :     gRealTy := CLang.double;
34 :     gRealSuffix := "d";
35 :     gIntSuffix := "l";
36 :     gIntFormat := "%ld")
37 :     else (
38 :     gVectorWid := 4;
39 :     gIntTy := CLang.int32;
40 :     gRealTy := CLang.float;
41 :     gRealSuffix := "f";
42 :     gIntSuffix := "i";
43 :     gIntFormat := "%d"))
44 : jhr 1115
45 :     fun addRealSuffix stem = stem ^ !gRealSuffix
46 :     fun addVecSuffix stem n = concat[stem, Int.toString n, !gRealSuffix]
47 :     fun addIVecSuffix stem n = concat[stem, Int.toString n, !gIntSuffix]
48 :    
49 :     fun addTySuffix (stem, 1) = stem ^ !gRealSuffix
50 :     | addTySuffix (stem, n) = addVecSuffix stem n
51 :    
52 :     fun vecTy n = concat["vec", Int.toString n, !gRealSuffix, "_t"]
53 :     fun ivecTy n = concat["vec", Int.toString n, !gIntSuffix, "_t"]
54 :     fun imageTy n = concat["Diderot_image", Int.toString n, "D_t"]
55 :     fun matTy (n, m) = concat["Diderot_Mat", Int.toString n, "x", Int.toString m, "_t"]
56 :    
57 :     (* names of generated tyes, functions, and globals *)
58 :     val initGlobals = "Diderot_InitGlobals" (* function for initializing program globals *)
59 : jhr 1232 val shutdown = "Diderot_Shutdown" (* function that gets called at the end *)
60 : jhr 1115 val initially = "Diderot_Initially" (* function for creating initial strands *)
61 :     fun strandInit strand = strand ^ "_InitState"
62 :     fun strandTy strand = concat["Strand_", strand, "_t"]
63 :     fun strandDesc strand = concat["Strand_", strand]
64 :     val numStrands = "Diderot_NumStrands"
65 :     val strands = "Diderot_Strands"
66 :    
67 :     (* scalar math functions *)
68 :     fun max () = addRealSuffix "max"
69 :     fun min () = addRealSuffix "min"
70 :     fun fabs () = addRealSuffix "fabs"
71 :    
72 : jhr 1295 (* clamp and lerp *)
73 :     fun clamp n = addTySuffix("clamp", n)
74 : jhr 1115 fun lerp n = addTySuffix("lerp", n)
75 :    
76 :     (* vector math functions *)
77 :     val mkVec = addVecSuffix "vec"
78 :     val scale = addVecSuffix "scale"
79 :     val truncToInt = addVecSuffix "truncToInt"
80 :     val dot = addVecSuffix "dot"
81 :     fun cross () = addVecSuffix "cross" 3
82 :     val length = addVecSuffix "length"
83 :     val normalize = addVecSuffix "normalize"
84 :     fun vecitof n = concat["vec", Int.toString n, "ito", !gRealSuffix]
85 :     fun vecftoi n = concat["vec", Int.toString n, !gRealSuffix, "toi"]
86 :    
87 :     (* matrix operations *)
88 :     fun zeroMat (n, m) = concat["zero", Int.toString n, "x", Int.toString m, !gRealSuffix]
89 :     fun identityMat n = concat["identity", Int.toString n, "x", Int.toString n, !gRealSuffix]
90 :     fun trace n = concat["trace", Int.toString n, "x", Int.toString n, !gRealSuffix]
91 :     fun norm (n, m) = concat["norm", Int.toString n, "x", Int.toString m, !gRealSuffix]
92 :     fun copyMat (n, m) = concat["copy", Int.toString n, "x", Int.toString m, !gRealSuffix]
93 :     fun scaleMat (n, m) = concat["scale", Int.toString n, "x", Int.toString m, !gRealSuffix]
94 :     fun addMat (n, m) = concat["add", Int.toString n, "x", Int.toString m, !gRealSuffix]
95 :     fun subMat (n, m) = concat["sub", Int.toString n, "x", Int.toString m, !gRealSuffix]
96 :     fun mulVecMat (m, n) = F.format "mulVec%dMat%dx%d%s"
97 :     [F.INT m, F.INT m, F.INT n, F.STR(!gRealSuffix)]
98 :     fun mulMatVec (m, n) = F.format "mulMat%dx%dVec%d%s"
99 :     [F.INT n, F.INT m, F.INT n, F.STR(!gRealSuffix)]
100 :     fun mulMatMat (m, n, p) = F.format "mulMat%dx%dMat%dx%d%s"
101 :     [F.INT m, F.INT n, F.INT n, F.INT p, F.STR(!gRealSuffix)]
102 :    
103 :     (* Status_t symbols *)
104 :     val kActive = "DIDEROT_ACTIVE"
105 :     val kDie = "DIDEROT_DIE"
106 :     val kStabilize = "DIDEROT_STABILIZE"
107 :    
108 :     (* Diderot runtime system hooks *)
109 :     val statusTy = "Status_t"
110 :     val toImageSpace = addVecSuffix "ToImageSpace"
111 :     fun toWorldSpace ty = let
112 :     val suffix = (case ty
113 :     of Ty.TensorTy[d] => [Int.toString d, !gRealSuffix]
114 :     | Ty.TensorTy[m,n] => [Int.toString n, "x", Int.toString n, !gRealSuffix]
115 :     (* end case *))
116 :     in
117 :     concat("ToWorldSpace" :: suffix)
118 :     end
119 :     val inside = addVecSuffix "Inside"
120 :     fun loadImage dim = concat["Diderot_LoadImage", Int.toString dim, "D"]
121 :     val strandDescTy = "Strand_t"
122 :     val worldTy = "Diderot_World_t"
123 :     val allocInitially = "Diderot_AllocInitially"
124 :     val inState = "Diderot_InState"
125 :    
126 :     fun input ty = (case ty
127 :     of Ty.StringTy => "Diderot_InputString"
128 : jhr 1232 | Ty.TensorTy[] => "Diderot_InputReal"
129 :     | Ty.TensorTy[2] => "Diderot_InputVec2"
130 :     | Ty.TensorTy[3] => "Diderot_InputVec3"
131 : jhr 1115 | ty => raise Fail("unsupported input type " ^ Ty.toString ty)
132 :     (* end case *))
133 :    
134 :     end (* local *)
135 :     end

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