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/ppc/backpatch/ppcJumps.sml
ViewVC logotype

Annotation of /sml/trunk/src/MLRISC/ppc/backpatch/ppcJumps.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1334 - (view) (download)

1 : monnier 247 functor PPCJumps
2 :     (structure Instr: PPCINSTR
3 :     structure Shuffle : PPCSHUFFLE where I = Instr
4 : george 984 structure MLTreeEval : MLTREE_EVAL where T = Instr.T
5 : monnier 247 ) : SDI_JUMPS =
6 :     struct
7 :     structure I = Instr
8 :     structure C = I.C
9 :     structure Const = I.Constant
10 : george 1009 structure CB = CellsBasis
11 : monnier 247
12 : monnier 411 fun error msg = MLRiscErrorMsg.error("PPCJumps",msg)
13 : monnier 247
14 :     val branchDelayedArch = false
15 :    
16 : george 1003 fun isSdi(I.ANNOTATION{i,...}) =isSdi i
17 :     | isSdi(I.LIVE _) = true
18 :     | isSdi(I.KILL _) = true
19 : george 1009 | isSdi(I.COPY _) = true
20 : george 1003 | isSdi(I.INSTR instr) = let
21 :     fun operand(I.LabelOp _) = true
22 :     | operand _ = false
23 :     in
24 :     case instr
25 :     of I.L{d, ...} => operand d
26 :     | I.LF{d, ...} => operand d
27 :     | I.ST{d, ...} => operand d
28 :     | I.STF{d, ...} => operand d
29 :     | I.ARITHI{im, ...} => operand im
30 :     | I.ROTATEI{sh, ...} => operand sh
31 :     | I.COMPARE{rb, ...} => operand rb
32 :     | I.TW{si, ...} => operand si
33 :     | I.TD{si, ...} => operand si
34 :     | I.BC{addr, ...} => operand addr
35 :     | _ => false
36 :     end
37 : monnier 247
38 :    
39 :     (* max Size is not used for the PPC span dependency analysis. *)
40 :     fun maxSize _ = error "maxSize"
41 :    
42 : george 1009 fun minSize(I.LIVE _) = 0
43 : george 1003 | minSize(I.KILL _) = 0
44 : george 1009 | minSize(I.COPY _) = 0
45 : monnier 411 | minSize(I.ANNOTATION{i,...}) = minSize i
46 : monnier 247 | minSize _ = 4
47 :    
48 : george 1003 fun sdiSize(I.ANNOTATION{i, ...}, labmap, loc) = sdiSize(i, labmap, loc)
49 :     | sdiSize(I.LIVE _, _, _) = 0
50 :     | sdiSize(I.KILL _, _, _) = 0
51 : george 1009 | sdiSize(I.COPY{k=CB.GP, src, dst, tmp, ...}, _, _) =
52 :     4 * length(Shuffle.shuffle{tmp=tmp, dst=dst, src=src})
53 :     | sdiSize(I.COPY{k=CB.FP, src, dst, tmp, ...}, _, _) =
54 :     4 * length(Shuffle.shufflefp{src=src, dst=dst, tmp=tmp})
55 : george 1003 | sdiSize(I.INSTR instr, labmap, loc) = let
56 :     fun signed16 n = ~32768 <= n andalso n < 32768
57 :     fun signed12 n = ~2048 <= n andalso n < 2048
58 :     fun signed14 n = ~8192 <= n andalso n < 8192
59 :     fun unsigned16 n = 0 <= n andalso n < 65536
60 :     fun unsigned5 n = 0 <=n andalso n < 32
61 :    
62 :     fun operand(I.LabelOp le, inRange, lo, hi) =
63 :     if inRange(MLTreeEval.valueOf le) then lo else hi
64 :     | operand _ = error "sdiSize:operand"
65 :     in
66 :     case instr
67 :     of I.L{ld=(I.LBZ | I.LHZ | I.LHA | I.LWZ),d,...} =>
68 :     operand(d, signed16, 4, 8)
69 :     | I.L{d,...} => operand(d, signed12, 4, 8)
70 :     | I.LF{ld=(I.LFS | I.LFD), d, ...} => operand(d, signed16, 4, 8)
71 :     | I.LF{d, ...} => operand(d, signed12, 4, 8)
72 :     | I.ST{st=(I.STB | I.STH | I.STW), d, ...} => operand(d, signed16, 4, 8)
73 :     | I.ST{d, ...} => operand(d, signed12, 4, 8)
74 :     | I.STF{st=(I.STFS | I.STFD), d, ...} => operand(d, signed16, 4, 8)
75 :     | I.STF{d, ...} => operand(d, signed12, 4, 8)
76 :     | I.ARITHI{oper, im, ...} =>
77 :     (case oper
78 :     of I.ADDI => operand(im, signed16, 4, 8)
79 :     | (I.ADDIS | I.SUBFIC | I.MULLI) => operand(im, signed16, 4, 12)
80 :     | (I.ANDI_Rc | I.ANDIS_Rc | I.ORI | I.ORIS | I.XORI | I.XORIS) =>
81 :     operand(im, unsigned16, 4, 12)
82 :     | (I.SRAWI | I.SRADI) => operand(im, unsigned5, 4, 12)
83 :     (*esac*))
84 :     | I.ROTATEI{sh, ...} => error "sdiSize:ROTATE"
85 :     | I.COMPARE{cmp, rb, ...} =>
86 :     (case cmp
87 :     of I.CMP => operand(rb, signed16, 4, 12)
88 :     | I.CMPL => operand(rb, unsigned16, 4, 12)
89 :     (*esac*))
90 :     | I.BC{addr=I.LabelOp lexp, ...} =>
91 :     if signed14((MLTreeEval.valueOf lexp - loc) div 4) then 4 else 8
92 :     | _ => error "sdiSize"
93 : monnier 247 end
94 : george 1003 | sdiSize _ = error "sdiSize"
95 : monnier 247
96 : george 984 fun valueOf(I.LabelOp lexp) = MLTreeEval.valueOf lexp
97 : monnier 247 | valueOf _ = error "valueOf"
98 :    
99 :     fun split opnd = let
100 :     val i = valueOf opnd
101 :     val w = Word.fromInt i
102 :     val hi = Word.~>>(w, 0w16)
103 :     val lo = Word.andb(w, 0w65535)
104 :     val (high,low) =
105 :     if lo < 0w32768 then (hi, lo) else (hi+0w1, lo-0w65536)
106 :     in (Word.toIntX high, Word.toIntX low)
107 :     end
108 :    
109 : monnier 411 fun cnv I.ADDI = I.ADD
110 :     | cnv I.SUBFIC = I.SUBF
111 :     | cnv I.MULLI = I.MULLW
112 :     | cnv I.ANDI_Rc = I.AND
113 :     | cnv I.ORI = I.OR
114 :     | cnv I.XORI = I.XOR
115 :     | cnv I.SRAWI = I.SRAW
116 :     | cnv I.SRADI = I.SRAD
117 :     | cnv _ = error "cnv"
118 :    
119 : george 1003 fun expand(I.ANNOTATION{i, ...}, size, pos) = expand(i, size, pos)
120 :     | expand(I.LIVE _, _, _) = []
121 :     | expand(I.KILL _, _, _) = []
122 : george 1009 | expand(I.COPY{k=CB.GP, src, tmp, dst, ...}, _, _) =
123 :     Shuffle.shuffle{src=src, dst=dst, tmp=tmp}
124 :     | expand(I.COPY{k=CB.FP, src, tmp, dst, ...}, _, _) =
125 :     Shuffle.shufflefp{src=src, dst=dst, tmp=tmp}
126 : george 1003 | expand(instr as I.INSTR i, size, pos) =
127 :     (case i
128 :     of I.L{ld, rt, ra, d, mem} =>
129 :     (case size
130 :     of 4 => [I.l{ld=ld, rt=rt, ra=ra, d=I.ImmedOp(valueOf d), mem=mem}]
131 :     | 8 => let
132 :     val (hi,lo) = split d
133 :     in
134 :     [I.arithi{oper=I.ADDIS, rt=C.asmTmpR, ra=ra, im=I.ImmedOp hi},
135 :     I.l{ld=ld, rt=rt, ra=C.asmTmpR, d=I.ImmedOp lo, mem=mem}]
136 :     end
137 :     | _ => error "expand:L"
138 :     (*esac*))
139 :     | I.LF{ld, ft, ra, d, mem} =>
140 :     (case size
141 :     of 4 => [I.lf{ld=ld, ft=ft, ra=ra, d=I.ImmedOp(valueOf d), mem=mem}]
142 :     | 8 => let
143 :     val (hi,lo) = split d
144 :     in
145 :     [I.arithi{oper=I.ADDIS, rt=C.asmTmpR, ra=ra, im=I.ImmedOp hi},
146 :     I.lf{ld=ld, ft=ft, ra=C.asmTmpR, d=I.ImmedOp lo, mem=mem}]
147 :     end
148 :     | _ => error "expand:LF"
149 :     (*esac*))
150 :     | I.ST{st, rs, ra, d, mem} =>
151 :     (case size
152 :     of 4 => [I.st{st=st, rs=rs, ra=ra, d=I.ImmedOp(valueOf d), mem=mem}]
153 :     | 8 => let
154 :     val (hi,lo) = split d
155 :     in
156 :     [I.arithi{oper=I.ADDIS, rt=C.asmTmpR, ra=ra, im=I.ImmedOp hi},
157 :     I.st{st=st, rs=rs, ra=C.asmTmpR, d=I.ImmedOp lo, mem=mem}]
158 :     end
159 :     | _ => error "expand:ST"
160 :     (*esac*))
161 :     | I.STF{st, fs, ra, d, mem} =>
162 :     (case size
163 :     of 4 => [I.stf{st=st, fs=fs, ra=ra, d=I.ImmedOp(valueOf d), mem=mem}]
164 :     | 8 => let
165 :     val (hi,lo) = split d
166 :     in
167 :     [I.arithi{oper=I.ADDIS, rt=C.asmTmpR, ra=ra, im=I.ImmedOp hi},
168 :     I.stf{st=st, fs=fs, ra=C.asmTmpR, d=I.ImmedOp lo, mem=mem}]
169 :     end
170 :     | _ => error "expand:STF"
171 :     (*esac*))
172 :     | I.ARITHI{oper, rt, ra, im} =>
173 :     (case size
174 :     of 4 => [I.arithi{oper=oper, rt=rt, ra=ra, im=I.ImmedOp(valueOf im)}]
175 :     | 8 => let val (hi, lo) = split im (* must be ADDI *)
176 :     in [I.arithi{oper=I.ADDIS, rt=rt, ra=ra, im=I.ImmedOp hi},
177 :     I.arithi{oper=I.ADDI, rt=rt, ra=rt, im=I.ImmedOp lo}]
178 :     end
179 :     | 12 =>
180 :     let val (hi,lo) = split im
181 :     in [I.arithi{oper=I.ADDIS, rt=C.asmTmpR, ra=C.Reg CellsBasis.GP 0,
182 :     im=I.ImmedOp hi},
183 :     I.arithi{oper=I.ADDI,rt=C.asmTmpR,ra=C.asmTmpR,im=I.ImmedOp lo},
184 :     I.arith{oper=cnv oper, rt=rt, ra=ra, rb=C.asmTmpR, OE=false,
185 :     Rc=(oper = I.ANDI_Rc)}]
186 :     end
187 : mblume 1334 | _ => error "ARITHI"
188 : george 1003 (*esac*))
189 :     | I.BC{bo, bf, bit, fall, addr, LK} =>
190 :     (case size
191 :     of 4 => [instr]
192 :     | 8 => let
193 :     val newBO =
194 :     (case bo
195 :     of I.TRUE => I.FALSE
196 :     | I.FALSE => I.TRUE
197 :     | I.ALWAYS => error "expand:newBO:BC"
198 :     | I.COUNTER{eqZero, cond} => error "expand:newBO:COUNTER"
199 :     (*esac*))
200 :     in
201 :     print("emiting long form of branch" ^ "\n");
202 :     [I.bc{bo=newBO, bf=bf, bit=bit, addr=fall, fall=fall, LK=false},
203 :     I.b{addr=addr, LK=LK}]
204 :     end
205 :     | _ => error "expand:BC"
206 :     (*esac*))
207 :     (* The other span dependent instructions are not generated *)
208 :     | I.COMPARE _ => error "expand:COMPARE"
209 :     | _ => error "expand"
210 :     (*esac*))
211 :     | expand _ = error "expand"
212 : monnier 247 end

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