1 | 2 | srem_mod.sa 3.1 12/10/90 3 | 4 | The entry point sMOD computes the float 5 | input values X and Y. The entry point s 6 | point (IEEE) REM of the input values X 7 | 8 | INPUT 9 | ----- 10 | Double-extended value Y is pointed to b 11 | A0. Double-extended value X is located 12 | of X and Y are both nonzero and finite; 13 | of them can be denormalized. The specia 14 | and infinities are handled elsewhere. 15 | 16 | OUTPUT 17 | ------ 18 | FREM(X,Y) or FMOD(X,Y), depending on en 19 | 20 | ALGORITHM 21 | --------- 22 | 23 | Step 1. Save and strip signs of X and 24 | signY := sign(Y), X := |X|, Y 25 | signQ := signX EOR signY. Rec 26 | is requested. 27 | 28 | Step 2. Set L := expo(X)-expo(Y), k : 29 | If (L < 0) then 30 | R := X, go to Step 4. 31 | else 32 | R := 2^(-L)X, j := L. 33 | endif 34 | 35 | Step 3. Perform MOD(X,Y) 36 | 3.1 If R = Y, go to Step 9. 37 | 3.2 If R > Y, then { R := R - Y, 38 | 3.3 If j = 0, go to Step 4. 39 | 3.4 k := k + 1, j := j - 1, Q := 40 | Step 3.1. 41 | 42 | Step 4. At this point, R = X - QY = M 43 | Last_Subtract := false (used 44 | MOD is requested, go to Step 45 | 46 | Step 5. R = MOD(X,Y), but REM(X,Y) is 47 | 5.1 If R < Y/2, then R = MOD(X,Y) 48 | Step 6. 49 | 5.2 If R > Y/2, then { set Last_S 50 | Q := Q + 1, Y := signY*Y }. G 51 | 5.3 This is the tricky case of R 52 | then { Q := Q + 1, signX := - 53 | 54 | Step 6. R := signX*R. 55 | 56 | Step 7. If Last_Subtract = true, R := 57 | 58 | Step 8. Return signQ, last 7 bits of 59 | 60 | Step 9. At this point, R = 2^(-j)*X - 61 | X = 2^(j)*(Q+1)Y. set Q := 2^ 62 | R := 0. Return signQ, last 7 63 | 64 | 65 66 | Copyright (C) Motorola, Inc. 1 67 | All Rights Reserved 68 | 69 | For details on the license for this fi 70 | file, README, in this same directory. 71 72 SREM_MOD: |idnt 2,1 | Motorola 040 Float 73 74 |section 8 75 76 #include "fpsp.h" 77 78 .set Mod_Flag,L_SCR3 79 .set SignY,FP_SCR3+4 80 .set SignX,FP_SCR3+8 81 .set SignQ,FP_SCR3+12 82 .set Sc_Flag,FP_SCR4 83 84 .set Y,FP_SCR1 85 .set Y_Hi,Y+4 86 .set Y_Lo,Y+8 87 88 .set R,FP_SCR2 89 .set R_Hi,R+4 90 .set R_Lo,R+8 91 92 93 Scale: .long 0x00010000,0x80000000, 94 95 |xref t_avoid_unsupp 96 97 .global smod 98 smod: 99 100 movel #0,Mod_Flag(%a6) 101 bras Mod_Rem 102 103 .global srem 104 srem: 105 106 movel #1,Mod_Flag(%a6) 107 108 Mod_Rem: 109 |..Save sign of X and Y 110 moveml %d2-%d7,-(%a7) | .. 111 movew (%a0),%d3 112 movew %d3,SignY(%a6) 113 andil #0x00007FFF,%d3 | ... 114 115 | 116 movel 4(%a0),%d4 117 movel 8(%a0),%d5 | ... 118 119 tstl %d3 120 bnes Y_Normal 121 122 movel #0x00003FFE,%d3 | ...$ 123 tstl %d4 124 bnes HiY_not0 125 126 HiY_0: 127 movel %d5,%d4 128 clrl %d5 129 subil #32,%d3 130 clrl %d6 131 bfffo %d4{#0:#32},%d6 132 lsll %d6,%d4 133 subl %d6,%d3 | ... 134 | ...wit 135 bras Chk_X 136 137 HiY_not0: 138 clrl %d6 139 bfffo %d4{#0:#32},%d6 140 subl %d6,%d3 141 lsll %d6,%d4 142 movel %d5,%d7 | ... 143 lsll %d6,%d5 144 negl %d6 145 addil #32,%d6 146 lsrl %d6,%d7 147 orl %d7,%d4 | ... 148 | ...wit 149 bras Chk_X 150 151 Y_Normal: 152 addil #0x00003FFE,%d3 | ... 153 | ...wit 154 155 Chk_X: 156 movew -12(%a0),%d0 157 movew %d0,SignX(%a6) 158 movew SignY(%a6),%d1 159 eorl %d0,%d1 160 andil #0x00008000,%d1 161 movew %d1,SignQ(%a6) | ...s 162 andil #0x00007FFF,%d0 163 movel -8(%a0),%d1 164 movel -4(%a0),%d2 | ... 165 tstl %d0 166 bnes X_Normal 167 movel #0x00003FFE,%d0 168 tstl %d1 169 bnes HiX_not0 170 171 HiX_0: 172 movel %d2,%d1 173 clrl %d2 174 subil #32,%d0 175 clrl %d6 176 bfffo %d1{#0:#32},%d6 177 lsll %d6,%d1 178 subl %d6,%d0 | ... 179 | ...wit 180 bras Init 181 182 HiX_not0: 183 clrl %d6 184 bfffo %d1{#0:#32},%d6 185 subl %d6,%d0 186 lsll %d6,%d1 187 movel %d2,%d7 | ... 188 lsll %d6,%d2 189 negl %d6 190 addil #32,%d6 191 lsrl %d6,%d7 192 orl %d7,%d1 | ... 193 | ...wit 194 bras Init 195 196 X_Normal: 197 addil #0x00003FFE,%d0 | ... 198 | ...wit 199 200 Init: 201 | 202 movel %d3,L_SCR1(%a6) | ... 203 movel %d0,L_SCR2(%a6) |save 204 subl %d3,%d0 | ... 205 | Move.L D0,L ...D0 206 clrl %d6 | ...D 207 clrl %d3 | ...D 208 moveal #0,%a1 | ...A 209 210 |..(Carry,D1,D2) is R 211 tstl %d0 212 bges Mod_Loop 213 214 |..expo(X) < expo(Y). Thus X = mod(X,Y) 215 | 216 movel L_SCR2(%a6),%d0 |resto 217 bra Get_Mod 218 219 |..At this point R = 2^(-L)X; Q = 0; k = 0; a 220 221 222 Mod_Loop: 223 tstl %d6 | ...t 224 bgts R_GT_Y 225 226 |..At this point carry = 0, R = (D1,D2), Y = ( 227 cmpl %d4,%d1 | ... 228 bnes R_NE_Y 229 cmpl %d5,%d2 | ... 230 bnes R_NE_Y 231 232 |..At this point, R = Y 233 bra Rem_is_0 234 235 R_NE_Y: 236 |..use the borrow of the previous compare 237 bcss R_LT_Y | ...bo 238 239 R_GT_Y: 240 |..If Carry is set, then Y < (Carry,D1,D2) < 2 241 |..and Y < (D1,D2) < 2Y. Either way, perform R 242 subl %d5,%d2 | ... 243 subxl %d4,%d1 | ... 244 clrl %d6 | ...c 245 addql #1,%d3 | ...Q 246 247 R_LT_Y: 248 |..At this point, Carry=0, R < Y. R = 2^(k-L)X 249 tstl %d0 | ...s 250 beqs PostLoop 251 252 addl %d3,%d3 | ... 253 addl %d2,%d2 | ... 254 roxll #1,%d1 | ...h 255 scs %d6 | ... 256 addql #1,%a1 | ...k 257 subql #1,%d0 | ...j 258 |..At this point, R=(Carry,D1,D2) = 2^(k-L)X - 259 260 bras Mod_Loop 261 262 PostLoop: 263 |..k = L, j = 0, Carry = 0, R = (D1,D2) = X - 264 265 |..normalize R. 266 movel L_SCR1(%a6),%d0 267 tstl %d1 268 bnes HiR_not0 269 270 HiR_0: 271 movel %d2,%d1 272 clrl %d2 273 subil #32,%d0 274 clrl %d6 275 bfffo %d1{#0:#32},%d6 276 lsll %d6,%d1 277 subl %d6,%d0 | ... 278 | ...wit 279 bras Get_Mod 280 281 HiR_not0: 282 clrl %d6 283 bfffo %d1{#0:#32},%d6 284 bmis Get_Mod | ...al 285 subl %d6,%d0 286 lsll %d6,%d1 287 movel %d2,%d7 | ... 288 lsll %d6,%d2 289 negl %d6 290 addil #32,%d6 291 lsrl %d6,%d7 292 orl %d7,%d1 | ... 293 294 | 295 Get_Mod: 296 cmpil #0x000041FE,%d0 297 bges No_Scale 298 Do_Scale: 299 movew %d0,R(%a6) 300 clrw R+2(%a6) 301 movel %d1,R_Hi(%a6) 302 movel %d2,R_Lo(%a6) 303 movel L_SCR1(%a6),%d6 304 movew %d6,Y(%a6) 305 clrw Y+2(%a6) 306 movel %d4,Y_Hi(%a6) 307 movel %d5,Y_Lo(%a6) 308 fmovex R(%a6),%fp0 309 movel #1,Sc_Flag(%a6) 310 bras ModOrRem 311 No_Scale: 312 movel %d1,R_Hi(%a6) 313 movel %d2,R_Lo(%a6) 314 subil #0x3FFE,%d0 315 movew %d0,R(%a6) 316 clrw R+2(%a6) 317 movel L_SCR1(%a6),%d6 318 subil #0x3FFE,%d6 319 movel %d6,L_SCR1(%a6) 320 fmovex R(%a6),%fp0 321 movew %d6,Y(%a6) 322 movel %d4,Y_Hi(%a6) 323 movel %d5,Y_Lo(%a6) 324 movel #0,Sc_Flag(%a6) 325 326 | 327 328 329 ModOrRem: 330 movel Mod_Flag(%a6),%d6 331 beqs Fix_Sign 332 333 movel L_SCR1(%a6),%d6 334 subql #1,%d6 | ...b 335 cmpl %d6,%d0 336 blts Fix_Sign 337 bgts Last_Sub 338 339 cmpl %d4,%d1 340 bnes Not_EQ 341 cmpl %d5,%d2 342 bnes Not_EQ 343 bra Tie_Case 344 345 Not_EQ: 346 bcss Fix_Sign 347 348 Last_Sub: 349 | 350 fsubx Y(%a6),%fp0 351 addql #1,%d3 | ...Q 352 353 | 354 355 Fix_Sign: 356 |..Get sign of X 357 movew SignX(%a6),%d6 358 bges Get_Q 359 fnegx %fp0 360 361 |..Get Q 362 | 363 Get_Q: 364 clrl %d6 365 movew SignQ(%a6),%d6 | 366 movel #8,%d7 367 lsrl %d7,%d6 368 andil #0x0000007F,%d3 | ... 369 orl %d6,%d3 | ... 370 swap %d3 371 fmovel %fpsr,%d6 372 andil #0xFF00FFFF,%d6 373 orl %d3,%d6 374 fmovel %d6,%fpsr | ... 375 376 | 377 Restore: 378 moveml (%a7)+,%d2-%d7 379 fmovel USER_FPCR(%a6),%fpcr 380 movel Sc_Flag(%a6),%d0 381 beqs Finish 382 fmulx Scale(%pc),%fp0 | ...m 383 bra t_avoid_unsupp |check 384 | ;resul 385 386 Finish: 387 fmovex %fp0,%fp0 388 rts 389 390 Rem_is_0: 391 |..R = 2^(-j)X - Q Y = Y, thus R = 0 and quoti 392 addql #1,%d3 393 cmpil #8,%d0 | ...D 394 bges Q_Big 395 396 lsll %d0,%d3 397 bras Set_R_0 398 399 Q_Big: 400 clrl %d3 401 402 Set_R_0: 403 fmoves #0x00000000,%fp0 404 movel #0,Sc_Flag(%a6) 405 bra Fix_Sign 406 407 Tie_Case: 408 |..Check parity of Q 409 movel %d3,%d6 410 andil #0x00000001,%d6 411 tstl %d6 412 beq Fix_Sign | ...Q is even 413 414 |..Q is odd, Q := Q + 1, signX := -signX 415 addql #1,%d3 416 movew SignX(%a6),%d6 417 eoril #0x00008000,%d6 418 movew %d6,SignX(%a6) 419 bra Fix_Sign 420 421 |end
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.