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/branches/blume-private-devel/src/MLRISC/ppc/backpatch/ppcJumps.sml
ViewVC logotype

Annotation of /sml/branches/blume-private-devel/src/MLRISC/ppc/backpatch/ppcJumps.sml

Parent Directory Parent Directory | Revision Log Revision Log


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

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