source: rtems/c/src/lib/libcpu/m68k/m68040/fpsp/srem_mod.S @ 9b4422a2

4.115
Last change on this file since 9b4422a2 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

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