Home My Page Projects Code Snippets Project Openings SML/NJ
 Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

# SCM Repository

[smlnj] Diff of /sml/trunk/src/MLRISC/mltree/mltree-mult.sml
 [smlnj] / sml / trunk / src / MLRISC / mltree / mltree-mult.sml

# Diff of /sml/trunk/src/MLRISC/mltree/mltree-mult.sml

revision 544, Tue Feb 22 22:56:38 2000 UTC revision 545, Thu Feb 24 13:56:44 2000 UTC
# Line 110  Line 110
110         else mult(r,itow i,!multCost,d)         else mult(r,itow i,!multCost,d)
111     end     end
112
113       (* The semantics of roundToZero{r,i,d} is:
114        *   if r >= 0 then d <- r
115        *   else d <- r + i
116        *)
117       fun roundToZero stm {ty,r,i,d} =
118           let val reg = T.REG(ty,r)
119           in  stm(T.MV(ty,d,
120                        T.COND(ty,T.CMP(ty,T.GE,reg,T.LI 0),reg,
122           end
123
124
125     (*     (*
126      * Simulate rounding towards zero for signed division      * Simulate rounding towards zero for signed division
127      *)      *)
128     fun roundDiv{mode=T.TO_NEGINF,r,...} = ([],r) (* no rounding necessary *)     fun roundDiv{mode=T.TO_NEGINF,r,...} = ([],r) (* no rounding necessary *)
129       | roundDiv{mode=T.TO_ZERO,roundToZero,r,i} =       | roundDiv{mode=T.TO_ZERO,stm,r,i} =
130            if signed then            if signed then
131            let val d = C.newReg()            let val d = C.newReg()
132            in  if i = 2 then (* special case for division by 2 *)            in  if i = 2 then (* special case for division by 2 *)
# Line 123  Line 135
135                   end                   end
136                else                else
137                       (* invoke rounding callback *)                       (* invoke rounding callback *)
138                   let val () = roundToZero{ty=intTy,r=r,i=i-1,d=d}                   let val () = roundToZero stm {ty=intTy,r=r,i=i-1,d=d}
139                   in ([],d) end                   in ([],d) end
140            end            end
141            else ([],r) (* no rounding for unsigned division *)            else ([],r) (* no rounding for unsigned division *)
142       | roundDiv{mode,...} =       | roundDiv{mode,...} =
143            error("Integer rounding mode "^            error("Integer rounding mode "^
144                  T.Util.roundingModeToString mode^" is not supported")                  T.Basis.roundingModeToString mode^" is not supported")
145
146     fun divideNonTrap{mode,roundToZero}{r,i,d} =     fun divideNonTrap{mode,stm}{r,i,d} =
147         if i > 0 andalso isPowerOf2(itow i)         if i > 0 andalso isPowerOf2(itow i)
148         then         then
149         let val (code,r) = roundDiv{mode=mode,roundToZero=roundToZero,r=r,i=i}         let val (code,r) = roundDiv{mode=mode,stm=stm,r=r,i=i}
150         in  code@shiftri{r=r,i=log2(itow i),d=d} end (* won't overflow *)         in  code@shiftri{r=r,i=log2(itow i),d=d} end (* won't overflow *)
151         else raise TooComplex         else raise TooComplex
152
# Line 175  Line 187
187         else mult(r,itow i,!multCost,d)         else mult(r,itow i,!multCost,d)
188     end     end
189
190     fun divideTrap{mode,roundToZero}{r,i,d} =     fun divideTrap{mode,stm}{r,i,d} =
191         if i > 0 andalso isPowerOf2(itow i)         if i > 0 andalso isPowerOf2(itow i)
192         then         then
193         let val (code,r) = roundDiv{mode=mode,roundToZero=roundToZero,r=r,i=i}         let val (code,r) = roundDiv{mode=mode,stm=stm,r=r,i=i}
194         in  code@shiftri{r=r,i=log2(itow i),d=d} end (* won't overflow *)         in  code@shiftri{r=r,i=log2(itow i),d=d} end (* won't overflow *)
195         else raise TooComplex         else raise TooComplex
196
197     val multiply = if trapping then multiplyTrap else multiplyNonTrap     fun multiply x = if trapping then multiplyTrap x else multiplyNonTrap x
198     val divide   = if trapping then divideTrap else divideNonTrap     fun divide   x = if trapping then divideTrap x else divideNonTrap x
199
200  end  end

Legend:
 Removed from v.544 changed lines Added in v.545