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

SCM Repository

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

Annotation of /branches/pure-cfg/src/compiler/c-target/runtime-names.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1229 - (view) (download)

1 : jhr 551 (* 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 : jhr 810 local
11 : jhr 833 structure Ty = TreeIL.Ty
12 : jhr 810 structure F = Format
13 :     in
14 :    
15 : jhr 551 (* globals that specify the target characteristics. These should be initialized
16 :     * when the program object is created.
17 :     *)
18 : jhr 1172 val doublePrecision = ref false
19 : jhr 551 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 : jhr 654 val gIntFormat = ref "?"
25 : jhr 551
26 :     (* initialize globals based on target precision *)
27 : jhr 1172 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 551
45 : jhr 833 fun addRealSuffix stem = stem ^ !gRealSuffix
46 : jhr 551 fun addVecSuffix stem n = concat[stem, Int.toString n, !gRealSuffix]
47 :     fun addIVecSuffix stem n = concat[stem, Int.toString n, !gIntSuffix]
48 :    
49 : jhr 863 fun addTySuffix (stem, 1) = stem ^ !gRealSuffix
50 : jhr 833 | addTySuffix (stem, n) = addVecSuffix stem n
51 : jhr 551
52 : jhr 561 fun vecTy n = concat["vec", Int.toString n, !gRealSuffix, "_t"]
53 :     fun ivecTy n = concat["vec", Int.toString n, !gIntSuffix, "_t"]
54 : jhr 551 fun imageTy n = concat["Diderot_image", Int.toString n, "D_t"]
55 : jhr 683 fun matTy (n, m) = concat["Diderot_Mat", Int.toString n, "x", Int.toString m, "_t"]
56 : jhr 551
57 : jhr 623 (* names of generated tyes, functions, and globals *)
58 : jhr 551 val initGlobals = "Diderot_InitGlobals" (* function for initializing program globals *)
59 : jhr 1215 val shutdown = "Diderot_Shutdown" (* function that gets called at the end *)
60 : jhr 618 val initially = "Diderot_Initially" (* function for creating initial strands *)
61 : jhr 551 fun strandInit strand = strand ^ "_InitState"
62 : jhr 552 fun strandTy strand = concat["Strand_", strand, "_t"]
63 : jhr 623 fun strandDesc strand = concat["Strand_", strand]
64 :     val numStrands = "Diderot_NumStrands"
65 :     val strands = "Diderot_Strands"
66 : jhr 551
67 : jhr 561 (* scalar math functions *)
68 : jhr 833 fun max () = addRealSuffix "max"
69 :     fun min () = addRealSuffix "min"
70 :     fun fabs () = addRealSuffix "fabs"
71 : jhr 561
72 : jhr 754 (* lerp *)
73 : jhr 833 fun lerp n = addTySuffix("lerp", n)
74 : jhr 754
75 : jhr 551 (* vector math functions *)
76 : jhr 553 val mkVec = addVecSuffix "vec"
77 : jhr 551 val scale = addVecSuffix "scale"
78 :     val truncToInt = addVecSuffix "truncToInt"
79 :     val dot = addVecSuffix "dot"
80 :     fun cross () = addVecSuffix "cross" 3
81 :     val length = addVecSuffix "length"
82 :     val normalize = addVecSuffix "normalize"
83 : jhr 584 fun vecitof n = concat["vec", Int.toString n, "ito", !gRealSuffix]
84 :     fun vecftoi n = concat["vec", Int.toString n, !gRealSuffix, "toi"]
85 : jhr 551
86 : jhr 683 (* matrix operations *)
87 : jhr 845 fun zeroMat (n, m) = concat["zero", Int.toString n, "x", Int.toString m, !gRealSuffix]
88 :     fun identityMat n = concat["identity", Int.toString n, "x", Int.toString n, !gRealSuffix]
89 : jhr 683 fun trace n = concat["trace", Int.toString n, "x", Int.toString n, !gRealSuffix]
90 : jhr 845 fun norm (n, m) = concat["norm", Int.toString n, "x", Int.toString m, !gRealSuffix]
91 : jhr 806 fun copyMat (n, m) = concat["copy", Int.toString n, "x", Int.toString m, !gRealSuffix]
92 : jhr 834 fun scaleMat (n, m) = concat["scale", Int.toString n, "x", Int.toString m, !gRealSuffix]
93 :     fun addMat (n, m) = concat["add", Int.toString n, "x", Int.toString m, !gRealSuffix]
94 : jhr 1091 fun subMat (n, m) = concat["sub", Int.toString n, "x", Int.toString m, !gRealSuffix]
95 : jhr 834 fun mulVecMat (m, n) = F.format "mulVec%dMat%dx%d%s"
96 :     [F.INT m, F.INT m, F.INT n, F.STR(!gRealSuffix)]
97 :     fun mulMatVec (m, n) = F.format "mulMat%dx%dVec%d%s"
98 :     [F.INT n, F.INT m, F.INT n, F.STR(!gRealSuffix)]
99 :     fun mulMatMat (m, n, p) = F.format "mulMat%dx%dMat%dx%d%s"
100 :     [F.INT m, F.INT n, F.INT n, F.INT p, F.STR(!gRealSuffix)]
101 : jhr 683
102 : jhr 562 (* Status_t symbols *)
103 :     val kActive = "DIDEROT_ACTIVE"
104 :     val kDie = "DIDEROT_DIE"
105 :     val kStabilize = "DIDEROT_STABILIZE"
106 :    
107 : jhr 551 (* Diderot runtime system hooks *)
108 : jhr 552 val statusTy = "Status_t"
109 : jhr 983 val toImageSpace = addVecSuffix "ToImageSpace"
110 :     fun toWorldSpace ty = let
111 :     val suffix = (case ty
112 :     of Ty.TensorTy[d] => [Int.toString d, !gRealSuffix]
113 :     | Ty.TensorTy[m,n] => [Int.toString n, "x", Int.toString n, !gRealSuffix]
114 :     (* end case *))
115 :     in
116 :     concat("ToWorldSpace" :: suffix)
117 :     end
118 :     val inside = addVecSuffix "Inside"
119 : jhr 551 fun loadImage dim = concat["Diderot_LoadImage", Int.toString dim, "D"]
120 : jhr 573 val strandDescTy = "Strand_t"
121 : jhr 623 val worldTy = "Diderot_World_t"
122 :     val allocInitially = "Diderot_AllocInitially"
123 :     val inState = "Diderot_InState"
124 : jhr 551
125 :     fun input ty = (case ty
126 : jhr 833 of Ty.StringTy => "Diderot_InputString"
127 : jhr 1229 | Ty.TensorTy[] => "Diderot_InputReal"
128 :     | Ty.TensorTy[3] => "Diderot_InputVec3"
129 : jhr 833 | ty => raise Fail("unsupported input type " ^ Ty.toString ty)
130 : jhr 551 (* end case *))
131 :    
132 : jhr 810 end (* local *)
133 : jhr 551 end

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