Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /MLRISC/trunk/instructions/shuffle.sml
ViewVC logotype

Annotation of /MLRISC/trunk/instructions/shuffle.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 412 - (view) (download)
Original Path: sml/trunk/src/MLRISC/instructions/shuffle.sml

1 : monnier 247 (* shuffle.sml -- implements the parallel copy instruction as a sequence
2 : monnier 411 * of moves.
3 : monnier 247 *
4 :     * COPYRIGHT (c) 1996 Bell Laboratories.
5 :     *
6 :     *)
7 :    
8 :    
9 :     functor Shuffle(I : INSTRUCTIONS) :
10 :     sig
11 :     val shuffle :
12 :     {mvInstr : {dst:I.ea, src:I.ea} -> I.instruction list,
13 :     ea : int -> I.ea}
14 :     ->
15 : monnier 411 {regmap: int -> int,
16 :     tmp : I.ea option,
17 : monnier 247 dst : int list,
18 :     src : int list}
19 :     -> I.instruction list
20 :     end =
21 :     struct
22 :     datatype reg = REG of int | TEMP
23 :     fun equal (REG r1, REG r2) = r1 = r2
24 :     | equal (TEMP, TEMP) = true
25 :     | equal _ = false
26 :    
27 : monnier 411 fun shuffle{mvInstr, ea} {regmap, tmp, dst, src} = let
28 : monnier 247 val mv = rev o mvInstr
29 :     fun opnd (REG dst) = ea dst
30 : monnier 411 | opnd TEMP = Option.valOf tmp
31 : monnier 247
32 :     (* perform unconstrained moves *)
33 :     fun loop((p as (rd,rs))::rest, changed, used, done, instrs) =
34 :     if List.exists (fn r => equal(r, rd)) used then
35 :     loop(rest, changed, used, p::done, instrs)
36 : monnier 411 else loop(rest, true, used, done,
37 :     mv{dst=opnd rd, src=opnd rs}@instrs)
38 : monnier 247 | loop([], changed, _, done, instrs) = (changed, done, instrs)
39 :    
40 :     fun cycle([], instrs) = instrs
41 :     | cycle(moves, instrs) =
42 :     (case loop(moves, false, map #2 moves, [], instrs)
43 :     of (_, [], instrs) => instrs
44 :     | (true, acc, instrs) => cycle(acc, instrs)
45 :     | (false, (rd,rs)::acc, instrs) => let
46 :     fun rename(p as (a,b)) = if equal(rd, b) then (a, TEMP) else p
47 :     val acc' = (rd, rs) :: map rename acc
48 : monnier 411 val instrs' = mv{dst=Option.valOf tmp, src=opnd rd}@instrs
49 : monnier 247 val (_, acc'', instrs'') =
50 :     loop(acc', false, map #2 acc', [], instrs')
51 :     in cycle(acc'', instrs'')
52 :     end
53 :     (*esac*))
54 :    
55 :     (* remove moves that have been coalesced. *)
56 :     fun rmvCoalesced(rd::rds, rs::rss) = let
57 : monnier 411 val dst = regmap rd
58 :     val src = regmap rs
59 : monnier 247 in
60 :     if dst = src then rmvCoalesced(rds, rss)
61 :     else (REG dst, REG src)::rmvCoalesced(rds, rss)
62 :     end
63 :     | rmvCoalesced([], []) = []
64 :     in rev (cycle (rmvCoalesced(dst, src), []))
65 :     end
66 :     end
67 :    

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