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 810 - (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 :     structure F = Format
12 :     in
13 :    
14 : jhr 551 (* globals that specify the target characteristics. These should be initialized
15 :     * when the program object is created.
16 :     *)
17 :     val gVectorWid = ref 4
18 :     val gIntTy = ref CLang.int32
19 :     val gRealTy = ref CLang.float
20 :     val gRealSuffix = ref "?"
21 :     val gIntSuffix = ref "?"
22 : jhr 654 val gIntFormat = ref "?"
23 : jhr 551
24 :     (* initialize globals based on target precision *)
25 :     fun initTargetSpec () = if !Controls.doublePrecision
26 :     then (
27 :     gVectorWid := 2;
28 :     gIntTy := CLang.int64;
29 :     gRealTy := CLang.double;
30 :     gRealSuffix := "d";
31 : jhr 654 gIntSuffix := "l";
32 :     gIntFormat := "%ld")
33 : jhr 551 else (
34 :     gVectorWid := 4;
35 :     gIntTy := CLang.int32;
36 :     gRealTy := CLang.float;
37 :     gRealSuffix := "f";
38 : jhr 654 gIntSuffix := "i";
39 :     gIntFormat := "%d")
40 : jhr 551
41 :     fun addVecSuffix stem n = concat[stem, Int.toString n, !gRealSuffix]
42 :     fun addIVecSuffix stem n = concat[stem, Int.toString n, !gIntSuffix]
43 :    
44 :     fun addTySuffix (stem, TargetTy.T_Real) = stem ^ !gRealSuffix
45 :     | addTySuffix (stem, TargetTy.T_Vec n) = addVecSuffix stem n
46 :     | addTySuffix (stem, ty) = raise Fail(concat["invalid type ", TargetTy.toString ty, " for ", stem])
47 :    
48 : jhr 561 fun vecTy n = concat["vec", Int.toString n, !gRealSuffix, "_t"]
49 :     fun ivecTy n = concat["vec", Int.toString n, !gIntSuffix, "_t"]
50 : jhr 551 fun imageTy n = concat["Diderot_image", Int.toString n, "D_t"]
51 : jhr 683 fun matTy (n, m) = concat["Diderot_Mat", Int.toString n, "x", Int.toString m, "_t"]
52 : jhr 551
53 : jhr 623 (* names of generated tyes, functions, and globals *)
54 : jhr 551 val initGlobals = "Diderot_InitGlobals" (* function for initializing program globals *)
55 : jhr 618 val initially = "Diderot_Initially" (* function for creating initial strands *)
56 : jhr 551 fun strandInit strand = strand ^ "_InitState"
57 : jhr 552 fun strandTy strand = concat["Strand_", strand, "_t"]
58 : jhr 623 fun strandDesc strand = concat["Strand_", strand]
59 :     val numStrands = "Diderot_NumStrands"
60 :     val strands = "Diderot_Strands"
61 : jhr 551
62 : jhr 561 (* scalar math functions *)
63 :     fun max ty = addTySuffix ("max", ty)
64 :     fun min ty = addTySuffix ("min", ty)
65 :    
66 : jhr 754 (* lerp *)
67 :     fun lerp 0 = "lerp" ^ !gRealSuffix
68 :     | lerp n = concat["lerp", Int.toString n, !gRealSuffix]
69 :    
70 : jhr 551 (* vector math functions *)
71 : jhr 553 val mkVec = addVecSuffix "vec"
72 : jhr 551 val scale = addVecSuffix "scale"
73 :     val truncToInt = addVecSuffix "truncToInt"
74 :     val dot = addVecSuffix "dot"
75 : jhr 810 fun mulVecMat (m, n) = F.format "mulVec%dMat%dx%d%s"
76 :     [F.INT m, F.INT m, F.INT n, F.STR(!gRealSuffix)]
77 :     fun mulMatVec (m, n) = F.format "mulMat%dx%dVec%d%s"
78 :     [F.INT n, F.INT m, F.INT n, F.STR(!gRealSuffix)]
79 :     fun mulMatMat (m, n, p) = F.format "mulMat%dx%dMat%dx%d%s"
80 :     [F.INT m, F.INT n, F.INT n, F.INT p, F.STR(!gRealSuffix)]
81 : jhr 551 fun cross () = addVecSuffix "cross" 3
82 :     val length = addVecSuffix "length"
83 :     val normalize = addVecSuffix "normalize"
84 : jhr 584 fun vecitof n = concat["vec", Int.toString n, "ito", !gRealSuffix]
85 :     fun vecftoi n = concat["vec", Int.toString n, !gRealSuffix, "toi"]
86 : jhr 551
87 : jhr 683 (* matrix operations *)
88 :     fun trace n = concat["trace", Int.toString n, "x", Int.toString n, !gRealSuffix]
89 : jhr 806 fun copyMat (n, m) = concat["copy", Int.toString n, "x", Int.toString m, !gRealSuffix]
90 : jhr 683
91 : jhr 562 (* Status_t symbols *)
92 :     val kActive = "DIDEROT_ACTIVE"
93 :     val kDie = "DIDEROT_DIE"
94 :     val kStabilize = "DIDEROT_STABILIZE"
95 :    
96 : jhr 551 (* Diderot runtime system hooks *)
97 : jhr 552 val statusTy = "Status_t"
98 : jhr 551 val toImageSpace = addVecSuffix "Diderot_ToImageSpace"
99 :     val inside = addVecSuffix "Diderot_Inside"
100 :     fun loadImage dim = concat["Diderot_LoadImage", Int.toString dim, "D"]
101 : jhr 573 val strandDescTy = "Strand_t"
102 : jhr 623 val worldTy = "Diderot_World_t"
103 :     val allocInitially = "Diderot_AllocInitially"
104 :     val inState = "Diderot_InState"
105 : jhr 551
106 :     fun input ty = (case ty
107 :     of TargetTy.T_String => "Diderot_InputString"
108 :     | TargetTy.T_Real => "Diderot_Input" ^ !gRealSuffix
109 :     | TargetTy.T_Vec 3 => "Diderot_InputVec3" ^ !gRealSuffix
110 :     | ty => raise Fail("unsupported input type " ^ TargetTy.toString ty)
111 :     (* end case *))
112 :    
113 : jhr 810 end (* local *)
114 : jhr 551 end

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