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/SMLNJ/src/MLRISC/hppa/hppaJumps.sml
ViewVC logotype

Annotation of /sml/branches/SMLNJ/src/MLRISC/hppa/hppaJumps.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 16 - (view) (download)
Original Path: sml/trunk/src/MLRISC/hppa/hppaJumps.sml

1 : monnier 16 (* hppaJumps.sml --- information to resolve jumps.
2 :     *
3 :     * COPYRIGHT (c) 1996 Bell Laboratories.
4 :     *
5 :     *)
6 :     functor HppaJumps
7 :     (structure Instr:HPPAINSTR
8 :     structure Shuffle:HPPASHUFFLE
9 :     sharing Shuffle.I = Instr) : SDI_JUMPS =
10 :     struct
11 :     structure I = Instr
12 :     structure C = Instr.C
13 :     structure LE = LabelExp
14 :     structure Const = I.Constant
15 :    
16 :     fun error msg = MLRiscErrorMsg.impossible ("HppaJumps." ^ msg)
17 :    
18 :     val branchDelayedArch = false
19 :    
20 :     fun minSize(I.COPY _) = 0
21 :     | minSize(I.FCOPY _) = 0
22 :     | minSize _ = 4
23 :    
24 :     fun maxSize (I.BCOND _) = 20
25 :     | maxSize (I.BCONDI _) = 20
26 :     | maxSize (I.B _) = 16
27 :     | maxSize (I.FBCC _) = 16
28 :     | maxSize (I.COPY _) = error "maxSize:COPY"
29 :     | maxSize (I.FCOPY _) = error "maxSize:FCOPY"
30 :     | maxSize _ = 4
31 :    
32 :     fun mayNeedNops _ = 0
33 :     fun needsNop _ = 0
34 :    
35 :     fun isSdi instr = let
36 :     fun opnd (I.LabExp _) = true
37 :     | opnd (I.ConstOp _) = true
38 :     | opnd _ = false
39 :     in
40 :     case instr
41 :     of I.BCOND _ => true
42 :     | I.BCONDI _ => true
43 :     | I.B _ => true
44 :     | I.FBCC _ => true
45 :     | I.LDO{i, ...} => opnd i
46 :     | I.STORE{d, ...} => opnd d
47 :     | I.ARITHI{i, ...} => opnd i
48 :     | I.LOADI{i, ...} => opnd i
49 :     | I.FCOPY _ => true
50 :     | I.COPY _ => true
51 :     | _ => false
52 :     end
53 :    
54 :     fun im11 n = ~1024 <= n andalso n < 1024
55 :     fun im12 n = ~2048 <= n andalso n < 2048
56 :     fun im14 n = ~8192 <= n andalso n < 8192
57 :     fun im17 n = ~65536 <= n andalso n < 65536
58 :    
59 :     fun sdiSize(instr, regmap, labMap, loc) = let
60 :     fun branchOffset lab = ((labMap lab) - loc - 8) div 4
61 :     fun branch lab = let
62 :     val offset = branchOffset lab
63 :     in
64 :     if im12 offset then 4 else if im17 offset then 8 else 20
65 :     end
66 :     fun memDisp(c, short, long) = if im14(c) then short else long
67 :     val lookup = Intmap.map regmap
68 :     in
69 :     case instr
70 :     of I.LDO{i=I.LabExp(lexp, _), ...} => memDisp(LE.valueOf lexp, 4, 12)
71 :     | I.LDO{i=I.ConstOp c, ...} => memDisp(Const.valueOf c, 4, 8)
72 :     | I.LOADI{i=I.ConstOp c, ...} => memDisp(Const.valueOf c, 4, 12)
73 :     | I.LOADI{i=I.LabExp(lexp, _), ...} => memDisp(LE.valueOf lexp, 4, 12)
74 :     | I.STORE{d=I.ConstOp c, ...} => memDisp(Const.valueOf c, 4, 12)
75 :     | I.ARITHI{ai, i=I.ConstOp c, ...} => let
76 :     fun arithImmed() = if im11(Const.valueOf c) then 4 else 12
77 :     in
78 :     case ai
79 :     of I.ADDI => arithImmed()
80 :     | I.ADDIO => arithImmed()
81 :     | I.SUBI => arithImmed()
82 :     | I.SUBIO => arithImmed()
83 :     | _ => error "sdiSize: ARITHI LabelExp"
84 :     (*esac*)
85 :     end
86 :     | I.ARITHI{ai, i=I.LabExp(lexp,_), ...} => let
87 :     fun arithImmed() = if im11(LabelExp.valueOf lexp) then 4 else 12
88 :     in
89 :     case ai
90 :     of I.ADDI => arithImmed()
91 :     | I.ADDIO => arithImmed()
92 :     | I.SUBI => arithImmed()
93 :     | I.SUBIO => arithImmed()
94 :     | _ => error "sdiSize: ARITHI LabelExp"
95 :     (*esac*)
96 :     end
97 :     | I.BCOND{t, ...} => branch t
98 :     | I.BCONDI{t, ...} => branch t
99 :     | I.B{lab, ...} => if im17 (branchOffset lab) then 4 else 16
100 :     | I.FBCC{t, ...} => if im17 (branchOffset t) then 4 else 16
101 :     | I.COPY{impl=ref(SOME l), ...} => 4 * length l
102 :     | I.FCOPY{impl=ref(SOME l), ...} => 4 * length l
103 :     | I.COPY{dst, src, impl, tmp} => let
104 :     val instrs = Shuffle.shuffle {regMap=lookup, temp=tmp, dst=dst, src=src}
105 :     in impl := SOME(instrs); 4 * length instrs
106 :     end
107 :     | I.FCOPY{dst, src, impl, tmp} => let
108 :     val instrs = Shuffle.shufflefp {regMap=lookup, temp=tmp, dst=dst, src=src}
109 :     in impl := SOME instrs; 4 * length instrs
110 :     end
111 :     | _ => error "sdiSize"
112 :     end
113 :    
114 :     fun longJump{lab, n} = let
115 :     val baseDisp = LE.MINUS(LE.LABEL lab, LE.CONST 8192)
116 :     val labOpnd = (baseDisp, I.T)
117 :     val baseptrR = 8
118 :     in
119 :     (* Note: A better sequence would be to use ADDIL, however
120 :     * the expansion is done after register allocation and
121 :     * ADDIL defines %r1.
122 :     *)
123 :     [I.LDIL{i=I.HILabExp labOpnd, t=C.asmTmpR},
124 :     I.LDO{i=I.LOLabExp labOpnd, b=C.asmTmpR, t=C.asmTmpR},
125 :     I.ARITH{a=I.ADD, r1=baseptrR, r2=C.asmTmpR, t=C.asmTmpR},
126 :     I.BV{x=0, labs=[lab], b=C.asmTmpR, n=n}]
127 :     end
128 :    
129 :     fun split11 n = let
130 :     val w = Word.fromInt(n)
131 :     in (Word.toIntX(Word.~>>(w, 0w11)), Word.toIntX(Word.andb(w, 0wx7ff)))
132 :     end
133 :    
134 :     fun split11X n = let
135 :     val w = Word.fromInt(n)
136 :     val hi' = Word.~>>(w, 0w11)
137 :     val lo' = Word.andb(w, 0wx7ff)
138 :     val (hi,lo) =
139 :     if Word.<=(lo', 0wx3ff) then (hi', lo') else (hi'+0w1, lo'-0wx800)
140 :     in (Word.toIntX hi, Word.toIntX lo)
141 :     end
142 :    
143 :     fun loadIndexed I.LDW = I.LDWX
144 :     | loadIndexed I.LDH = I.LDHX
145 :     | loadIndexed I.LDB = I.LDBX
146 :    
147 :     fun expand(I.LDO{i=I.LabExp lexp, t, b}, size) =
148 :     (case size
149 :     of 4 => [I.LDO{i=I.LabExp lexp, b=b, t=t}]
150 :     | 12 => [I.LDIL{i=I.HILabExp lexp, t=C.asmTmpR},
151 :     I.LDO{i=I.LOLabExp lexp, b=C.asmTmpR, t=C.asmTmpR},
152 :     I.ARITH{a=I.ADD, r1=C.asmTmpR, r2=b, t=t}]
153 :     (*esac*))
154 :     | expand(I.LDO{i=I.ConstOp c, t, b}, size) =
155 :     (case size
156 :     of 4 => [I.LDO{i=I.IMMED(Const.valueOf c), t=t, b=b}]
157 :     | 8 => let
158 :     val (hi, lo) = split11(Const.valueOf c)
159 :     in
160 :     [I.LDIL{i=I.IMMED hi, t=C.asmTmpR},
161 :     I.LDO{i=I.IMMED lo, b=C.asmTmpR, t=t}]
162 :     end
163 :     (*esac*))
164 :     | expand(I.STORE{st, d=I.ConstOp c, b, r, mem}, size) =
165 :     (case size
166 :     of 4 => [I.STORE{st=st, d=I.IMMED(Const.valueOf c), b=b, r=r, mem=mem}]
167 :     | 12 => let
168 :     val (hi, lo) = split11(Const.valueOf c)
169 :     in
170 :     [I.LDIL{i=I.IMMED hi, t=C.asmTmpR},
171 :     I.ARITH{a=I.ADD, r1=C.asmTmpR, r2=b, t=C.asmTmpR},
172 :     I.STORE{st=st, b=C.asmTmpR, d=I.IMMED lo, r=r, mem=mem}]
173 :     end
174 :     (*esac*))
175 :     | expand(I.STORE _, _) = error "expand:STORE"
176 :     | expand(I.ARITHI{ai, r, i=I.ConstOp c, t}, size) =
177 :     (case size
178 :     of 4 => [I.ARITHI{ai=ai, r=r, i=I.IMMED(Const.valueOf c), t=t}]
179 :     | 12 => let
180 :     val (hi, lo) =
181 :     (case ai
182 :     of I.ADDI => split11X(Const.valueOf c)
183 :     | I.ADDIO => split11X(Const.valueOf c)
184 :     | I.SUBI => split11X(Const.valueOf c)
185 :     | I.SUBIO => split11X(Const.valueOf c)
186 :     | _ => error "expandd: ARITHI"
187 :     (*esac*))
188 :     in
189 :     [I.LDIL{i=I.IMMED hi, t=C.asmTmpR},
190 :     I.ARITH{a=I.ADD, r1=C.asmTmpR, r2=r, t=C.asmTmpR},
191 :     I.ARITHI{ai=ai, r=C.asmTmpR, i=I.IMMED lo, t=t}]
192 :     end
193 :     (*esac*))
194 :     | expand(instr as I.LOADI{li, r, i=I.ConstOp c, t, mem} , size) =
195 :     (case size
196 :     of 4 => [I.LOADI{li=li, r=r, i=I.IMMED(Const.valueOf c), t=t, mem=mem}]
197 :     | 12 => let
198 :     val (hi, lo) = split11(Const.valueOf c)
199 :     in
200 :     [I.LDIL{i=I.IMMED hi, t=C.asmTmpR},
201 :     I.ARITH{a=I.ADD, r1=C.asmTmpR, r2=r, t=C.asmTmpR},
202 :     I.LOADI{li=li, r=C.asmTmpR, i=I.IMMED lo, t=t, mem=mem}]
203 :     end
204 :     (*esac*))
205 :     | expand(instr as I.LOADI{li, r, i=I.LabExp lexp, t, mem} , size) =
206 :     (case size
207 :     of 4 => [instr]
208 :     | 12 => [I.LDIL{i=I.HILabExp lexp, t=C.asmTmpR},
209 :     I.ARITH{a=I.ADD, r1=C.asmTmpR, r2=r, t=C.asmTmpR},
210 :     I.LOADI{li=li, r=C.asmTmpR, i=I.LOLabExp lexp, t=t, mem=mem}]
211 :     (*esac*))
212 :     | expand(instr as I.ARITHI{ai, r, i=I.LabExp lexp, t} , size) =
213 :     (case size
214 :     of 4 => [instr]
215 :     | 12 =>
216 :     (* Note: A better sequence would be to use ADDIL, however
217 :     * the expansion is done after register allocation and
218 :     * ADDIL defines %r1.
219 :     *)
220 :     [I.LDIL{i=I.HILabExp lexp, t=C.asmTmpR},
221 :     I.LDO{i=I.LOLabExp lexp, b=C.asmTmpR, t=C.asmTmpR},
222 :     I.ARITH{
223 :     a = case ai of I.ADDI => I.ADD | I.ADDIO => I.ADDO
224 :     | I.SUBI => I.SUB | I.SUBIO => I.SUBO
225 :     | _ => error "expand: I.ARITHI LabExp",
226 :     t=t,
227 :     r1=C.asmTmpR,
228 :     r2=r}]
229 :     (*esac*))
230 :     | expand(instr as I.BCOND{cmp,bc, t, f, r1, r2, n}, size) = let
231 :     fun rev I.COMBT=I.BCOND{cmp=I.COMBF,bc=bc,t=f,f=f,r1=r1,r2=r2,n=true}
232 :     | rev I.COMBF=I.BCOND{cmp=I.COMBT,bc=bc,t=f,f=f,r1=r1,r2=r2,n=true}
233 :     in
234 :     case size
235 :     of 4 => [instr]
236 :     | 8 => [rev cmp, I.B{lab=t, n=n}]
237 :     | 20 => rev cmp :: longJump{lab=t, n=n}
238 :     (*esac*)
239 :     end
240 :     | expand(instr as I.BCONDI{cmpi, bc, t, f, i, r2, n}, size) = let
241 :     fun rev I.COMIBT=I.BCONDI{cmpi=I.COMIBF,bc=bc,i=i,r2=r2,t=f,f=f,n=true}
242 :     | rev I.COMIBF=I.BCONDI{cmpi=I.COMIBT,bc=bc,i=i,r2=r2,t=f,f=f,n=true}
243 :     in
244 :     (case size
245 :     of 4 => [instr]
246 :     | 8 => [rev cmpi, I.B{lab=t, n=n}]
247 :     | 20 => rev cmpi :: longJump{lab=t, n=n}
248 :     (*esac*))
249 :     end
250 :     | expand(instr as I.B{lab=lab, n=n}, size) =
251 :     (case size
252 :     of 4 => [instr]
253 :     | 16 => longJump{lab=lab, n=n}
254 :     (*esac*))
255 :     | expand(instr as I.FBCC{t, f, n}, size) =
256 :     (case size
257 :     of 4 => [I.B{lab=t, n=n}]
258 :     | 16 =>
259 :     (* lets hope this sequence never gets generated sequence:
260 :     FTEST
261 :     allways trapping instruction
262 :     B (f)
263 :     longJmp
264 :     *)
265 :     error "FBCC"
266 :     (*esac*))
267 :     | expand(I.COPY{impl=ref(SOME instrs),...}, _) = instrs
268 :     | expand(I.FCOPY{impl=ref(SOME instrs),...}, _) = instrs
269 :     | expand _ = error "expand"
270 :    
271 :     end
272 :    
273 :     (*
274 :     * $Log: hppaJumps.sml,v $
275 :     * Revision 1.9 1998/02/17 02:51:05 george
276 :     * Added the nullify bit to all branch instructions -- leunga
277 :     *
278 :     * Revision 1.8 1998/02/16 13:58:14 george
279 :     * A register allocated temp is now associated with parallel COPYs
280 :     * instead of a dedicated register. The temp is used to break cycles.
281 :     *
282 :     * Revision 1.7 1998/01/30 14:21:47 george
283 :     * missing case for expansion of span dependent loads
284 :     *
285 :     * Revision 1.6 1997/09/29 20:58:33 george
286 :     * Propagate region information through instruction set
287 :     *
288 :     # Revision 1.4 1997/07/17 12:27:35 george
289 :     # The regmap is now represented as an int map rather than using arrays.
290 :     #
291 :     # Revision 1.3 1997/07/03 13:54:29 george
292 :     # Added support for FCOPY.
293 :     #
294 :     # Revision 1.2 1997/04/19 18:39:10 george
295 :     # Version 109.27
296 :     #
297 :     # Revision 1.1.1.1 1997/04/19 18:14:22 george
298 :     # Version 109.27
299 :     #
300 :     *)

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