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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1115 - (view) (download)
Original Path: trunk/src/compiler/c-target/runtime-names.sml

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

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