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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1372, Wed Jun 22 21:24:17 2011 UTC revision 1373, Wed Jun 22 21:36:18 2011 UTC
# Line 2  Line 2 
2   *   *
3   * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)   * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4   * All rights reserved.   * All rights reserved.
5     *
6     * These are names that are used in the common parts of the runtime system.
7   *)   *)
8    
9  structure RuntimeNames =  structure RuntimeNames =
# Line 9  Line 11 
11    
12      local      local
13        structure Ty = TreeIL.Ty        structure Ty = TreeIL.Ty
       structure F = Format  
14      in      in
15    
16    (* globals that specify the target characteristics.  These should be initialized    (* names of generated types, functions, and globals *)
    * when the program object is created.  
    *)  
     val doublePrecision = ref false  
     val gVectorWid = ref 4  
     val gIntTy = ref CLang.int32  
     val gRealTy = ref CLang.float  
     val gRealSuffix = ref "?"  
     val gIntSuffix = ref "?"  
     val gIntFormat = ref "?"  
   
   (* initialize globals based on target precision *)  
     fun initTargetSpec double = (  
           doublePrecision := double;  
           if double  
             then (  
               gVectorWid := 2;  
               gIntTy := CLang.int64;  
               gRealTy := CLang.double;  
               gRealSuffix := "d";  
               gIntSuffix := "l";  
               gIntFormat := "%ld")  
             else (  
               gVectorWid := 4;  
               gIntTy := CLang.int32;  
               gRealTy := CLang.float;  
               gRealSuffix := "f";  
               gIntSuffix := "i";  
               gIntFormat := "%d"))  
   
     fun addRealSuffix stem = stem ^ !gRealSuffix  
     fun addVecSuffix stem n = concat[stem, Int.toString n, !gRealSuffix]  
     fun addIVecSuffix stem n = concat[stem, Int.toString n, !gIntSuffix]  
   
     fun addTySuffix (stem, 1) = stem ^ !gRealSuffix  
       | addTySuffix (stem, n) = addVecSuffix stem n  
   
     fun vecTy n = concat["vec", Int.toString n, !gRealSuffix, "_t"]  
     fun ivecTy n = concat["vec", Int.toString n, !gIntSuffix, "_t"]  
     fun imageTy n = concat["Diderot_image", Int.toString n, "D_t"]  
     fun matTy (n, m) = concat["Diderot_Mat", Int.toString n, "x", Int.toString m, "_t"]  
   
   (* names of generated tyes, functions, and globals *)  
17      val initGlobals = "Diderot_InitGlobals"     (* function for initializing program globals *)      val initGlobals = "Diderot_InitGlobals"     (* function for initializing program globals *)
18      val registerOpts = "Diderot_RegisterGlobalOpts" (* function for registering command-line options *)      val registerOpts = "Diderot_RegisterGlobalOpts" (* function for registering command-line options *)
19      val shutdown = "Diderot_Shutdown"           (* function that gets called at the end *)      val shutdown = "Diderot_Shutdown"           (* function that gets called at the end *)
# Line 65  Line 24 
24      val numStrands = "Diderot_NumStrands"      val numStrands = "Diderot_NumStrands"
25      val strands = "Diderot_Strands"      val strands = "Diderot_Strands"
26    
   (* scalar math functions *)  
     fun max () = addRealSuffix "max"  
     fun min () = addRealSuffix "min"  
     fun fabs () = addRealSuffix "fabs"  
   
   (* clamp and lerp *)  
     fun clamp n = addTySuffix("clamp", n)  
     fun lerp n = addTySuffix("lerp", n)  
   
   (* vector math functions *)  
     val mkVec = addVecSuffix "vec"  
     val scale = addVecSuffix "scale"  
     val truncToInt = addVecSuffix "truncToInt"  
     val dot = addVecSuffix "dot"  
     fun cross () = addVecSuffix "cross" 3  
     val length = addVecSuffix "length"  
     val normalize = addVecSuffix "normalize"  
     fun vecitof n = concat["vec", Int.toString n, "ito", !gRealSuffix]  
     fun vecftoi n = concat["vec", Int.toString n, !gRealSuffix, "toi"]  
   
   (* matrix operations *)  
     fun zeroMat (n, m) = concat["zero", Int.toString n, "x", Int.toString m, !gRealSuffix]  
     fun identityMat n = concat["identity", Int.toString n, "x", Int.toString n, !gRealSuffix]  
     fun trace n = concat["trace", Int.toString n, "x", Int.toString n, !gRealSuffix]  
     fun norm (n, m) = concat["norm", Int.toString n, "x", Int.toString m, !gRealSuffix]  
     fun copyMat (n, m) = concat["copy", Int.toString n, "x", Int.toString m, !gRealSuffix]  
     fun scaleMat (n, m) = concat["scale", Int.toString n, "x", Int.toString m, !gRealSuffix]  
     fun addMat (n, m) = concat["add", Int.toString n, "x", Int.toString m, !gRealSuffix]  
     fun subMat (n, m) = concat["sub", Int.toString n, "x", Int.toString m, !gRealSuffix]  
     fun mulVecMat (m, n) = F.format "mulVec%dMat%dx%d%s"  
           [F.INT m, F.INT m, F.INT n, F.STR(!gRealSuffix)]  
     fun mulMatVec (m, n) = F.format "mulMat%dx%dVec%d%s"  
           [F.INT n, F.INT m, F.INT n, F.STR(!gRealSuffix)]  
     fun mulMatMat (m, n, p) = F.format "mulMat%dx%dMat%dx%d%s"  
           [F.INT m, F.INT n, F.INT n, F.INT p, F.STR(!gRealSuffix)]  
   
   (* Status_t symbols *)  
     val kActive = "DIDEROT_ACTIVE"  
     val kDie = "DIDEROT_DIE"  
     val kStabilize = "DIDEROT_STABILIZE"  
   
27    (* Diderot runtime system hooks *)    (* Diderot runtime system hooks *)
28      val statusTy = "Status_t"      val statusTy = "Status_t"
     val toImageSpace = addVecSuffix "ToImageSpace"  
     fun toWorldSpace ty = let  
           val suffix = (case ty  
                  of Ty.TensorTy[d] => [Int.toString d, !gRealSuffix]  
                   | Ty.TensorTy[m,n] => [Int.toString n, "x", Int.toString n, !gRealSuffix]  
                 (* end case *))  
           in  
             concat("ToWorldSpace" :: suffix)  
           end  
     val inside = addVecSuffix "Inside"  
29      fun loadImage dim = concat["Diderot_LoadImage", Int.toString dim, "D"]      fun loadImage dim = concat["Diderot_LoadImage", Int.toString dim, "D"]
30      val strandDescTy = "Strand_t"      val strandDescTy = "Strand_t"
31      val worldTy = "Diderot_World_t"      val worldTy = "Diderot_World_t"
# Line 125  Line 33 
33      val allocInitially = "Diderot_AllocInitially"      val allocInitially = "Diderot_AllocInitially"
34      val inState = "Diderot_InState"      val inState = "Diderot_InState"
35    
36      (* functions for defining program inputs *)
37      fun input ty = (case ty      fun input ty = (case ty
38             of Ty.StringTy => "Diderot_InputString"             of Ty.StringTy => "Diderot_OptAddString"
39              | Ty.TensorTy[] => "Diderot_InputReal"              | Ty.BoolTy => "Diderot_OptAddBool"
40              | Ty.TensorTy[2] => "Diderot_InputVec2"              | Ty.IVecTy 1 => "Diderot_OptAddInt"
41              | Ty.TensorTy[3] => "Diderot_InputVec3"              | Ty.TensorTy[] => "Diderot_OptAddReal"
42                | Ty.TensorTy[2] => "Diderot_OptAddReal2"
43                | Ty.TensorTy[3] => "Diderot_OptAddReal3"
44                | Ty.TensorTy[4] => "Diderot_OptAddReal4"
45              | ty => raise Fail("unsupported input type " ^ Ty.toString ty)              | ty => raise Fail("unsupported input type " ^ Ty.toString ty)
46            (* end case *))            (* end case *))
47    

Legend:
Removed from v.1372  
changed lines
  Added in v.1373

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