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 2870 - (download) (annotate)
Wed Feb 25 21:47:43 2015 UTC (4 years, 5 months ago) by cchiw
File size: 5369 byte(s)
added sqrt,pow, and examples
(* c-names.sml
 * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.

structure CNames =

      structure Ty = TreeIL.Ty
      structure F = Format

    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 normMat (n, m) = concat["norm", Int.toString n, "x", Int.toString m]
    fun normTen3 (n, m, p) = concat["normTen", Int.toString n, "x", Int.toString m, "x", Int.toString p]
    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 length = addVecSuffix "length"
    val mkReal= "Diderot_real_t"
    val mkVec = addVecSuffix "vec"
    val mkIVec = addVecSuffix "ivec"
    val truncToInt = addVecSuffix "truncToInt"
    fun vecitof n = concat["vec", Int.toString n, "itor"]
    fun vecftoi n = concat["vec", Int.toString n, "rtoi"]
    val mkRealArr= "Diderot_real_t"
    fun normalize n =concat["normalize",Int.toString n]

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

    (*-------------- Helpers--------------*)
    fun isAligned true = "Aligned"
    | isAligned _ = ""
    fun size n=foldl (fn (a,b) => b*a) 1 n 
    fun iTos e=Int.toString e

    (*-------------- Types --------------*)
    (*Name for tensors in load and store*)

    (*type for generated functions*)
    fun cfnTy  [1] = mkReal
    | cfnTy  [n] = concat["Diderot_vec", iTos n, "_t"]
    | cfnTy  [n,m] = concat["Diderot_Mat", Int.toString n,"x",iTos m, "_t"]

    fun LocalTy alpha=cfnTy alpha
    fun LocalTy  [1] = mkReal
      | LocalTy  [n] = (*concat["Diderot_vec", iTos n, "_t"]*)
        concat["vec",iTos n,"f_t"]
      | LocalTy  [n,m] = concat["Diderot_Mat", Int.toString n,"x",iTos m, "_t"]
    fun unionTy d= String.concat["Diderot_union",iTos d,"_t"]

    (*--------------val name --------------*)
    val NameFloor= "FLOOR"
    val NameSqrt ="SQRT"
    val NamePowInt ="pow"
    val NamePowReal ="pow"
    (*-------------- Store and load---------------*)
     *removed support for storeAligned
     * everything is supported as a regular store
    fun NameStoreVec(A,nSize,oSize)=
        if (nSize>oSize)
        then String.concat["store",iTos nSize,"to",iTos oSize]
        else String.concat["store",(*isAligned A,*)iTos nSize]
    fun NameLdArr(A,nSize,oSize)=
        if (nSize>oSize)
        then String.concat["load",isAligned A,iTos oSize,"to",iTos nSize]
        else String.concat["load",isAligned A,iTos nSize]

(* -------------- Vector function names:String --------------- *)
    fun NameConsArray d=String.concat["V_ConsArr",iTos d]
    fun NameConsVec d=String.concat["V_ConsVec",iTos d]
    fun NameMux d= String.concat["V_Mux",iTos d]
    fun NameSumV d= String.concat["V_SumVec" ,iTos d]
    fun NameFloorV d= String.concat["V_FloorVec" ,iTos d]
    fun NameScaV d=String.concat["V_Scale",iTos d]
    fun NameProj d = String.concat["V_Proj", iTos d]
    fun NameClampV d = String.concat["V_Clamp", iTos d]
    fun NameLerpV d = String.concat["V_Lerp", iTos d]
    fun NameZeroV ty = concat["V_Zero",  iTos (size ty)]
    fun NameCopyTensor ty = concat["V_CopyArr", iTos(size ty )]

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

    val inside = addVecSuffix "Inside"

    end (* local *)

ViewVC Help
Powered by ViewVC 1.0.0