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

SCM Repository

[diderot] View of /branches/charisee/src/compiler/mid-to-low/sample.sml
ViewVC logotype

View of /branches/charisee/src/compiler/mid-to-low/sample.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2615 - (download) (annotate)
Wed May 14 00:22:49 2014 UTC (5 years, 4 months ago) by cchiw
File size: 2900 byte(s)
added tree-il expressions and types
(**This version returns list*)
structure  Sample = struct

    local
    structure IL = LowIL
    structure DstTy = LowILTypes
    structure DstOp = LowOps
    in

(*fun isHWVec _ = false*)
(*SSE:HWVec-4*)
fun isHWVec width=if(width>4) then false else true
fun isVecTy 1 =true
  | isVecTy 2 =true
  | isVecTy 4 =true
  | isVecTy 8 =true
  | isVecTy 16 =true
  | isVecTy _= false

(*Convert to binary*)
fun toBin n = let
    fun f 0=[]
    | f num=num mod 2::f(num div 2)
    in
        rev(f n)
    end


(*binary to int list*)
fun toList ([],_)=[]
  | toList (0::es,n)= toList(es,n-1)
  | toList (_::es,n)= let
    val p=IntInf.pow(2,n)
    in
        [IntInf.toInt p] @ toList(es,n-1)
    end

(*binary to int list*)
fun toListIndex ([],_,_)=[]
  | toListIndex (0::es,n,from)= toListIndex(es,n-1,from)
  | toListIndex (_::es,n,from)= let
        val p=IntInf.pow(2,n)
        val p'=IntInf.toInt p
        in
            [(p',from)] @ toListIndex(es,n-1,from+p')
        end


(*Return list of vector lengths*)
fun findPieces n=let
    val bin=toBin n
    in
        toList(bin,(length bin-1))
    end 
    

(*List of lengths with index information*)
fun findPiecesIndex n=let
    val bin=toBin n
    in
        toListIndex(bin,(length bin-1),0)
    end


(*Use Next largest isVecTy*)
fun findNextLargestVec n =(case (isVecTy n)
    of true => n
    | false => findNextLargestVec(n+1)
    (*end case*))


(*Returns vector length into pieces*)
fun getPieces n=let
    val pieces=(case isVecTy n
        of true=> [n] (*Done*)
        | false=>(case isHWVec n
            of true=> [findNextLargestVec (n+1)](*use next largest*)
            | false=> findPieces n     (*use pieces*)
            (*end case*))
        (*end case*))
    in
        pieces
    end

(*Returns vector length into pieces with Index info*)
fun getPiecesIndex n=let
    val pieces=(case isVecTy n
    of true=> [(n,0)] (*Done*)
    | false=>(case isHWVec n
        of true=> [(findNextLargestVec (n+1),0)](*use next largest*)
        | false=> findPiecesIndex n     (*use pieces*)
        (*end case*))
(*end case*))
in
pieces
end


(*Returns flag for vector strategy*)
fun getFlag n=let
    val flag=(case isVecTy n
        of true=> 0         (*Done*)
        | false=>(case isHWVec n
            of true=> 1     (*use next largest*)
            | false=> 2     (*use pieces*)
            (*end case*))
        (*end case *))
    in
        flag
    end


fun tester n= let
    fun q e1=Int.toString(e1)
    val m = getPieces n
    val mm= String.concatWith "," (List.map q m)
    val f=getFlag n
    val i=getPiecesIndex n
    val ii = String.concatWith ","
        (List.map (fn (n,from) => String.concat[q n,"[",q from,"]"]) i)


    val str=String.concat(["\n --",q n,":Flag:",q f,
        "(", mm,")-",ii])
    in print str
    end 

fun ss _=List.map tester [6,2,7,8,9,4,1,3,12]



end; (* local *)

end (* local *)

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