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

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