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

SCM Repository

[diderot] View of /branches/charisee/src/compiler/c-util/c-names.sml
ViewVC logotype

View of /branches/charisee/src/compiler/c-util/c-names.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2688 - (download) (annotate)
Thu Aug 28 02:21:14 2014 UTC (5 years ago) by cchiw
File size: 4505 byte(s)
lift Save(tmp)=>store statement
(* c-names.sml
 *WQE
 * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *)

structure CNames =
  struct

    local
      structure Ty = TreeIL.Ty
      structure F = Format
    in

    open RuntimeNames

  (* globals that specify the target characteristics.  These should be initialized
   * when the program object is created.
   *)
    val doublePrecision = ref false
    val longInt = 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, long} = (
	  doublePrecision := double;
          longInt := long;
	  if double
	    then (
	      gVectorWid := 2;
	      gRealTy := CLang.double;
	      gRealSuffix := "d")
	    else (
	      gVectorWid := 4;
	      gRealTy := CLang.float;
	      gRealSuffix := "f");
          if long
            then (
              gIntTy := CLang.int64;
              gIntSuffix := "l";
	      gIntFormat := "%ld")
            else (
	      gIntTy := CLang.int32;
              gIntSuffix := "i";
	      gIntFormat := "%d"))

    fun addVecSuffix stem n = concat[stem, Int.toString n]
    fun addIVecSuffix stem n = concat[stem, Int.toString n]

    fun addTySuffix (stem, 1) = stem
      | addTySuffix (stem, n) = addVecSuffix stem n

    fun coords [i]=Int.toString i
    | coords (e1::es)= concat[Int.toString e1, "x", coords es]


    fun ivecTy n = concat["vec", Int.toString n, !gIntSuffix, "_t"]

    fun unionTy n = concat["union", Int.toString n, !gRealSuffix, "_t"]
    fun iunionTy n = concat["union", 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"]
    fun ten3Ty (n, m, l) = concat["Diderot_Ten", Int.toString n, "x", Int.toString m, "x", Int.toString l, "_t"]
    fun tenTy e = concat["Diderot_Ten", coords e , "_t"]

    val dynSeqTy = "Diderot_DynSeq_t"

  (* scalar math functions *)
    fun max () = "max"
    fun min () = "min"
    fun fabs () = "fabs"

  (* clamp and lerp *)
    fun clamp n = addTySuffix("clamp", n)
    fun lerp n = addTySuffix("lerp", n)

  (* vector math functions *)
    val mkReal= "Diderot_real_t"
    val mkVec = addVecSuffix "vec"
    val mkIVec = addVecSuffix "ivec"
    val scale = addVecSuffix "scale"
    val truncToInt = addVecSuffix "truncToInt"
    val dot = addVecSuffix "dot"
    val prod = addVecSuffix "prod"
    fun vecitof n = concat["vec", Int.toString n, "itor"]
    fun vecftoi n = concat["vec", Int.toString n, "rtoi"]
     val mkRealArr= "Diderot_real_t"
    
  (* matrix operations *)
    fun zeroVec n = concat["zero", Int.toString n]
    fun zeroMat (n, m) = concat["zero", Int.toString n, "x", Int.toString m]
    fun copyMat (n, m) = concat["copy", Int.toString n, "x", Int.toString m]
  


  (* 3rd-order tensor operations *)
    fun copyTen3 (n, m, l) = F.format "copyTen%dx%dx%d" [F.INT n, F.INT m, F.INT l]
    (*Vector operators *)
    fun q e=Int.toString e 


    (*Name for Tensors elsewhere*)
    (*For program use*)
    val  tprog = mkReal



    (*Name for tensors in load and store*)
    fun OvecTy  n = concat["Diderot_vec", Int.toString n, "_t"]

    (*For internal use*)



    (*-------------- Function Names:String ---------------*)
    fun NameConsArray [i]="consArr"^q i
      | NameConsArray [i,j]=String.concat["consArr",q i,"x",q j]
    fun NameConsVec d="consVec"^q d

    fun isAligned true = "Aligned"
      | isAligned _ = ""

    fun isArr true ="Arr"
      | isArr _ ="Vec"

    fun NameMkVec(A,nSize,oSize,Arr)=
        if (nSize>oSize)
        then String.concat["storeTo",isArr Arr ,isAligned A,q nSize,"to",q oSize]
        else String.concat["storeTo",isArr Arr ,isAligned A,q nSize]


    fun NameLd(A,tyN,tyO,Arr)= String.concat["load",isArr Arr, isAligned A,q tyN]
    val NameMux = String.concat["Mux"]
    fun NameSumV d= String.concat["sumVec" ,q d]
    fun NameFloorV d= String.concat["floorVec" ,q d]
    fun NameScaV d="E"^scale d
    fun NameDotV d= String.concat["dotVec" ,q d]
    fun unionTy d= String.concat["Diderot_union",q d,"_t"]

  (* Status_t symbols *)
    val kActive = "DIDEROT_ACTIVE"
    val kDie = "DIDEROT_DIE"
    val kStabilize = "DIDEROT_STABILIZE"

    val inside = addVecSuffix "Inside"

    end (* local *)
  end

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