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/sparc/sparcJumps.sml
ViewVC logotype

Annotation of /sml/trunk/src/MLRISC/sparc/sparcJumps.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 168 - (view) (download)

1 : monnier 129 (* sparcJumps.sml --- information to resolve jumps.
2 :     *
3 :     * COPYRIGHT (c) 1996 Bell Laboratories.
4 :     *
5 :     *)
6 :     functor SparcJumps
7 :     (structure Instr:SPARCINSTR
8 :     structure Shuffle:SPARCSHUFFLE
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 ("SparcJumps." ^ msg)
17 :    
18 :     val branchDelayedArch = true
19 :    
20 :     fun minSize(I.COPY _) = 0
21 :     | minSize(I.FCOPY _) = 0
22 :     | minSize(I.Bicc{nop=true,...}) = 8
23 :     | minSize(I.FBfcc{nop=true,...}) = 8
24 :     | minSize(I.JMP{nop=true,...}) = 8
25 :     | minSize(I.JMPL{nop=true,...}) = 8
26 :     | minSize(I.CALL{nop=true,...}) = 8
27 :     | minSize(I.RET{nop=true,...}) = 8
28 : monnier 167 | minSize(I.FCMP{nop=true,...}) = 8
29 : monnier 129 | minSize(I.FPop1{a=(I.FMOVd | I.FNEGd | I.FABSd),...}) = 8
30 :     (*
31 :     | minSize(I.ANNOTATION(i,_)) = minSize i
32 :     *)
33 :     | minSize _ = 4
34 :    
35 :     fun maxSize (I.COPY _) = error "maxSize:COPY"
36 :     | maxSize (I.FCOPY _) = error "maxSize:FCOPY"
37 :     | maxSize(I.FPop1{a=(I.FMOVd | I.FNEGd | I.FABSd),...}) = 8
38 :     (*
39 :     | maxSize (I.ANNOTATION(i,_)) = maxSize i
40 :     *)
41 :     | maxSize _ = 4
42 :    
43 :     fun immed13 n = ~4096 <= n andalso n < 4096
44 :     fun immed22 n = ~0x200000 <= n andalso n < 0x1fffff
45 :     fun immed30 n = ~0x4000000 <= n andalso n < 0x3ffffff
46 :    
47 :     fun isSdi instr =
48 :     let fun oper(I.IMMED n) = false
49 :     | oper(I.REG _) = false
50 :     | oper(I.HI _) = false
51 :     | oper(I.LO _) = false
52 :     | oper(I.LAB _) = true
53 :     | oper(I.CONST _) = true
54 :     in case instr of
55 :     I.ARITH{i,...} => oper i
56 :     | I.SHIFT{i,...} => oper i
57 :     | I.LOAD{i,...} => oper i
58 :     | I.STORE{i,...} => oper i
59 :     | I.FLOAD{i,...} => oper i
60 :     | I.FSTORE{i,...} => oper i
61 :     | I.JMPL{i,...} => oper i
62 :     | I.JMP{i,...} => oper i
63 :     | I.CALL _ => true
64 :     | I.Bicc _ => true
65 :     | I.FBfcc _ => true
66 :     | I.Ticc{i,...} => oper i
67 :     | I.WRY{i,...} => oper i
68 :     | I.COPY _ => true
69 :     | I.FCOPY _ => true
70 :     | I.SAVE{i,...} => oper i
71 :     | I.RESTORE{i,...} => oper i
72 :     (*
73 :     | I.ANNOTATION(i,_) => isSdi i
74 :     *)
75 :     | _ => false
76 :     end
77 :    
78 :     fun instrLength([],n) = n
79 :     | instrLength(I.FPop1{a=(I.FMOVd | I.FNEGd | I.FABSd),...}::is,n) =
80 :     instrLength(is,n+8)
81 :     | instrLength(_::is,n) = instrLength(is,n+4)
82 :    
83 :     fun sdiSize(instr, regmap, labMap, loc) =
84 :     let fun oper(I.IMMED n,_) = 4
85 :     | oper(I.REG _,_) = 4
86 :     | oper(I.HI _,_) = 4
87 :     | oper(I.LO _,_) = 4
88 :     | oper(I.LAB lexp,hi) = if immed13(LE.valueOf lexp) then 4 else hi
89 :     | oper(I.CONST c,hi) = if immed13(Const.valueOf c) then 4 else hi
90 :     fun displacement lab = ((labMap lab) - loc) div 4
91 :     fun branch lab = if immed22(displacement lab) then 4 else 16
92 :     fun call lab = if immed30(displacement lab) then 4 else 20
93 :     fun delaySlot false = 0
94 :     | delaySlot true = 4
95 :     fun size instr =
96 :     case instr of
97 :     I.ARITH{a=I.OR,r=0,i,...} => oper(i,8)
98 :     | I.ARITH{i,...} => oper(i,12)
99 :     | I.SHIFT{i,...} => oper(i,12)
100 :     | I.LOAD{i,...} => oper(i,12)
101 :     | I.STORE{i,...} => oper(i,12)
102 :     | I.FLOAD{i,...} => oper(i,12)
103 :     | I.FSTORE{i,...} => oper(i,12)
104 :     | I.Ticc{i,...} => oper(i,12)
105 :     | I.SAVE{i,...} => oper(i,12)
106 :     | I.RESTORE{i,...} => oper(i,12)
107 :     | I.JMPL{i,nop,...} => oper(i,12) + delaySlot nop
108 :     | I.JMP{i,nop,...} => oper(i,12) + delaySlot nop
109 :     | I.Bicc{label,nop,...} => branch label + delaySlot nop
110 :     | I.FBfcc{label,nop,...} => branch label + delaySlot nop
111 :     | I.CALL{label,...} => call label
112 :     | I.WRY{i,...} => oper(i,12)
113 :     | I.COPY{impl=ref(SOME l), ...} => 4 * length l
114 :     | I.FCOPY{impl=ref(SOME l), ...} => instrLength(l,0)
115 :     | I.COPY{dst, src, impl, tmp} =>
116 :     let val instrs =
117 :     Shuffle.shuffle{regMap=Intmap.map regmap,temp=tmp,dst=dst,src=src}
118 :     in impl := SOME(instrs); 4 * length instrs
119 :     end
120 :     | I.FCOPY{dst, src, impl, tmp} =>
121 :     let val instrs =
122 :     Shuffle.shufflefp{regMap=Intmap.map regmap,temp=tmp,dst=dst,src=src}
123 :     in impl := SOME instrs; instrLength(instrs,0)
124 :     end
125 :     (*
126 :     | I.ANNOTATION(i,_) => size i
127 :     *)
128 :     | _ => error "sdiSize"
129 :     in size instr
130 :     end
131 :    
132 :     fun split22_10 n =
133 :     let val w = Word32.fromInt n
134 :     in {hi=Word32.toInt(Word32.>>(w,0w10)),
135 :     lo=Word32.toInt(Word32.andb(w,0wx3ff))
136 :     }
137 :     end
138 :    
139 :     fun split(I.CONST c) = split22_10(Const.valueOf c)
140 :     | split(I.LAB lexp) = split22_10(LE.valueOf lexp)
141 :     | split _ = error "split"
142 :    
143 :     (* Expand the immediate constant into two instructions *)
144 :     fun expandImm(immed,instr) =
145 :     let val {lo,hi} = split immed
146 :     in [I.SETHI{i=hi,d=C.asmTmpR},
147 :     I.ARITH{a=I.OR,cc=false,r=C.asmTmpR,i=I.IMMED lo,d=C.asmTmpR},
148 :     instr
149 :     ]
150 :     end
151 :    
152 :     (* Expand a span dependent instruction *)
153 :     fun expand(I.COPY{impl=ref(SOME instrs),...},_) = instrs
154 :     | expand(I.FCOPY{impl=ref(SOME instrs),...},_) = instrs
155 :     | expand(instr,4) = [instr]
156 :     | expand(I.ARITH{a=I.OR,r=0,i,d,cc},8) =
157 :     let val {lo,hi} = split i
158 :     in [I.SETHI{i=hi,d=C.asmTmpR},
159 :     I.ARITH{a=I.OR,cc=cc,r=C.asmTmpR,i=I.IMMED lo,d=d}
160 :     ]
161 :     end
162 :     | expand(I.ARITH{a,r,i,d,cc},12) =
163 :     expandImm(i,I.ARITH{a=a,r=r,i=I.REG C.asmTmpR,d=d,cc=cc})
164 :     | expand(I.SHIFT{s,r,i,d},12) =
165 :     expandImm(i,I.SHIFT{s=s,r=r,i=I.REG C.asmTmpR,d=d})
166 :     | expand(I.SAVE{r,i,d},12) =
167 :     expandImm(i,I.SAVE{r=r,i=I.REG C.asmTmpR,d=d})
168 :     | expand(I.RESTORE{r,i,d},12) =
169 :     expandImm(i,I.RESTORE{r=r,i=I.REG C.asmTmpR,d=d})
170 :     | expand(I.LOAD{l,r,i,d,mem},12) =
171 :     expandImm(i,I.LOAD{l=l,r=r,i=I.REG C.asmTmpR,d=d,mem=mem})
172 :     | expand(I.STORE{s,r,i,d,mem},12) =
173 :     expandImm(i,I.STORE{s=s,r=r,i=I.REG C.asmTmpR,d=d,mem=mem})
174 :     | expand(I.FLOAD{l,r,i,d,mem},12) =
175 :     expandImm(i,I.FLOAD{l=l,r=r,i=I.REG C.asmTmpR,d=d,mem=mem})
176 :     | expand(I.FSTORE{s,r,i,d,mem},12) =
177 :     expandImm(i,I.FSTORE{s=s,r=r,i=I.REG C.asmTmpR,d=d,mem=mem})
178 :     | expand(i as I.JMPL _,8) = [i]
179 :     | expand(i as I.JMP _,8) = [i]
180 :     | expand(i as I.Bicc _,8) = [i]
181 :     | expand(i as I.FBfcc _,8) = [i]
182 :     | expand(I.JMPL{r,i,d,defs,uses,nop},(12 | 16)) =
183 :     expandImm(i,I.JMPL{r=r,i=I.REG C.asmTmpR,d=d,defs=defs,uses=uses,
184 :     nop=nop})
185 :     | expand(I.JMP{r,i,labs,nop},(12 | 16)) =
186 :     expandImm(i,I.JMP{r=r,i=I.REG C.asmTmpR,labs=labs,nop=nop})
187 :     | expand(I.Ticc{t,r,i},12) =
188 :     expandImm(i,I.Ticc{t=t,r=r,i=I.REG C.asmTmpR})
189 :     (*
190 :     * The sparc uses 22bits signed extended displacement offsets
191 :     * Let's hope it's enough
192 :     *)
193 :     | expand(I.Bicc{b,a,label,nop},_) = error "Bicc"
194 :     | expand(I.FBfcc{b,a,label,nop},_) = error "FBfcc"
195 :     | expand(I.WRY{r,i},12) = expandImm(i,I.WRY{r=r,i=I.REG C.asmTmpR})
196 :     (*
197 :     | expand(I.ANNOTATION(i,a),size) = expand(i,size)
198 :     *)
199 :     | expand _ = error "expand"
200 :    
201 :     end
202 :    
203 :     (*
204 : monnier 167 * $Log: sparcJumps.sml,v $
205 :     * Revision 1.1.1.1 1998/08/05 19:38:49 george
206 :     * Release 110.7.4
207 :     *
208 : monnier 129 *)

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