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 /sml/trunk/src/MLRISC/instructions/shuffle.sml
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 651 - (view) (download)

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 : leunga 579 fun equal (r1 : int, r2 : int) = r1 = r2
23 : monnier 247
24 : monnier 411 fun shuffle{mvInstr, ea} {regmap, tmp, dst, src} = let
25 : leunga 579 fun mv{dst, src, instrs} = List.revAppend(mvInstr{dst=dst,src=src}, instrs)
26 :     val TEMP = ~1
27 : leunga 641 fun valOf(SOME x) = x
28 :     | valOf NONE = raise Option
29 :     fun opnd dst = if dst = TEMP then valOf tmp else ea dst
30 : monnier 247
31 :     (* perform unconstrained moves *)
32 :     fun loop((p as (rd,rs))::rest, changed, used, done, instrs) =
33 :     if List.exists (fn r => equal(r, rd)) used then
34 :     loop(rest, changed, used, p::done, instrs)
35 : monnier 411 else loop(rest, true, used, done,
36 : leunga 579 mv{dst=opnd rd, src=opnd rs, instrs=instrs})
37 : monnier 247 | loop([], changed, _, done, instrs) = (changed, done, instrs)
38 :    
39 :     fun cycle([], instrs) = instrs
40 :     | cycle(moves, instrs) =
41 :     (case loop(moves, false, map #2 moves, [], instrs)
42 :     of (_, [], instrs) => instrs
43 :     | (true, acc, instrs) => cycle(acc, instrs)
44 :     | (false, (rd,rs)::acc, instrs) => let
45 :     fun rename(p as (a,b)) = if equal(rd, b) then (a, TEMP) else p
46 :     val acc' = (rd, rs) :: map rename acc
47 : leunga 641 val instrs' = mv{dst=valOf tmp,src=opnd rd,instrs=instrs}
48 : monnier 247 val (_, acc'', instrs'') =
49 :     loop(acc', false, map #2 acc', [], instrs')
50 :     in cycle(acc'', instrs'')
51 :     end
52 :     (*esac*))
53 :    
54 :     (* remove moves that have been coalesced. *)
55 : leunga 579 fun rmvCoalesced(rd::rds, rs::rss, mvs) = let
56 : monnier 411 val dst = regmap rd
57 :     val src = regmap rs
58 : monnier 247 in
59 : leunga 579 if dst = src then rmvCoalesced(rds, rss, mvs)
60 :     else rmvCoalesced(rds, rss, (dst, src)::mvs)
61 : monnier 247 end
62 : leunga 579 | rmvCoalesced([], [], mvs) = mvs
63 :     in rev (cycle (rmvCoalesced(dst, src, []), []))
64 : monnier 247 end
65 :     end
66 :    

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