~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/m68k/fpsp040/decbin.S

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /arch/m68k/fpsp040/decbin.S (Version linux-6.12-rc7) and /arch/i386/fpsp040/decbin.S (Version linux-6.10.14)


  1 |                                                 
  2 |       decbin.sa 3.3 12/19/90                    
  3 |                                                 
  4 |       Description: Converts normalized packe    
  5 |       register A6 to extended-precision valu    
  6 |                                                 
  7 |       Input: Normalized packed bcd value in     
  8 |                                                 
  9 |       Output: Exact floating-point represent    
 10 |                                                 
 11 |       Saves and Modifies: D2-D5                 
 12 |                                                 
 13 |       Speed: The program decbin takes ??? cy    
 14 |                                                 
 15 |       Object Size:                              
 16 |                                                 
 17 |       External Reference(s): None.              
 18 |                                                 
 19 |       Algorithm:                                
 20 |       Expected is a normal bcd (i.e. non-exc    
 21 |       and NaN operands are dispatched withou    
 22 |       value in 68881/882 format at location     
 23 |                                                 
 24 |       A1.     Convert the bcd exponent to bi    
 25 |       Set the sign according to SE. Subtract    
 26 |       for the mantissa which is to be interp    
 27 |       digits, rather than 1 integer and 16 f    
 28 |       Note: this operation can never overflo    
 29 |                                                 
 30 |       A2. Convert the bcd mantissa to binary    
 31 |       adds and muls in FP0. Set the sign acc    
 32 |       The mantissa digits will be converted     
 33 |       assumed following the least-significan    
 34 |       Note: this operation can never overflo    
 35 |                                                 
 36 |       A3. Count the number of leading/traili    
 37 |       bcd string.  If SE is positive, count     
 38 |       if negative, count the trailing zeros.    
 39 |       exponent equal to the exponent from A1    
 40 |       added if SM = 1 and subtracted if SM =    
 41 |       mantissa the equivalent of forcing in     
 42 |                                                 
 43 |       SM = 0  a non-zero digit in the intege    
 44 |       SM = 1  a non-zero digit in Mant0, lsd    
 45 |                                                 
 46 |       this will insure that any value, regar    
 47 |       representation (ex. 0.1E2, 1E1, 10E0,     
 48 |       consistently.                             
 49 |                                                 
 50 |       A4. Calculate the factor 10^exp in FP1    
 51 |       10^(2^n) values.  To reduce the error     
 52 |       greater than 10^27, a directed roundin    
 53 |       tables rounded to RN, RM, and RP, acco    
 54 |       in the comments of the pwrten section.    
 55 |                                                 
 56 |       A5. Form the final binary number by sc    
 57 |       the exponent factor.  This is done by     
 58 |       mantissa in FP0 by the factor in FP1 i    
 59 |       exponent sign is positive, and dividin    
 60 |       it is negative.                           
 61 |                                                 
 62 |       Clean up and return.  Check if the fin    
 63 |       in an inex2 exception.  If so, set ine    
 64 |       check if the inex1 exception is enable    
 65 |       word to $0100.  This will signal unimp    
 66 |       exception occurred.  Unimp will fix th    
 67 |                                                 
 68                                                   
 69 |               Copyright (C) Motorola, Inc. 1    
 70 |                       All Rights Reserved       
 71 |                                                 
 72 |       For details on the license for this fi    
 73 |       file, README, in this same directory.     
 74                                                   
 75 |DECBIN    idnt    2,1 | Motorola 040 Floating    
 76                                                   
 77         |section        8                         
 78                                                   
 79 #include "fpsp.h"                                 
 80                                                   
 81 |                                                 
 82 |       PTENRN, PTENRM, and PTENRP are arrays     
 83 |       to nearest, minus, and plus, respectiv    
 84 |       10**{1,2,4,8,16,32,64,128,256,512,1024    
 85 |       is required until the power is greater    
 86 |       tables include the first 5 for ease of    
 87 |                                                 
 88         |xref   PTENRN                            
 89         |xref   PTENRM                            
 90         |xref   PTENRP                            
 91                                                   
 92 RTABLE: .byte   0,0,0,0                           
 93         .byte   2,3,2,3                           
 94         .byte   2,3,3,2                           
 95         .byte   3,2,2,3                           
 96                                                   
 97         .global decbin                            
 98         .global calc_e                            
 99         .global pwrten                            
100         .global calc_m                            
101         .global norm                              
102         .global ap_st_z                           
103         .global ap_st_n                           
104 |                                                 
105         .set    FNIBS,7                           
106         .set    FSTRT,0                           
107 |                                                 
108         .set    ESTRT,4                           
109         .set    EDIGITS,2       |                 
110 |                                                 
111 | Constants in single precision                   
112 FZERO:  .long   0x00000000                        
113 FONE:   .long   0x3F800000                        
114 FTEN:   .long   0x41200000                        
115                                                   
116         .set    TEN,10                            
117                                                   
118 |                                                 
119 decbin:                                           
120         | fmovel        #0,FPCR         ;clr r    
121         moveml  %d2-%d5,-(%a7)                    
122 |                                                 
123 | Calculate exponent:                             
124 |  1. Copy bcd value in memory for use as a wo    
125 |  2. Calculate absolute value of exponent in     
126 |  3. Correct for exponent sign.                  
127 |  4. Subtract 16 to compensate for interpreti    
128 |     (i.e., all digits assumed left of the de    
129 |                                                 
130 | Register usage:                                 
131 |                                                 
132 |  calc_e:                                        
133 |       (*)  d0: temp digit storage               
134 |       (*)  d1: accumulator for binary expone    
135 |       (*)  d2: digit count                      
136 |       (*)  d3: offset pointer                   
137 |       ( )  d4: first word of bcd                
138 |       ( )  a0: pointer to working bcd value     
139 |       ( )  a6: pointer to original bcd value    
140 |       (*)  FP_SCR1: working copy of original    
141 |       (*)  L_SCR1: copy of original exponent    
142 |                                                 
143 calc_e:                                           
144         movel   #EDIGITS,%d2    |# of nibbles     
145         moveql  #ESTRT,%d3      |counter to pi    
146         leal    FP_SCR1(%a6),%a0        |load     
147         movel   ETEMP(%a6),(%a0)        |save     
148         movel   ETEMP_HI(%a6),4(%a0) |save wor    
149         movel   ETEMP_LO(%a6),8(%a0) |and work    
150         movel   (%a0),%d4       |get first wor    
151         clrl    %d1             |zero d1 for a    
152 e_gd:                                             
153         mulul   #TEN,%d1        |mul partial p    
154         bfextu  %d4{%d3:#4},%d0 |get the digit    
155         addl    %d0,%d1         |d1 = d1 + d0     
156         addqb   #4,%d3          |advance d3 to    
157         dbf     %d2,e_gd        |if we have us    
158         btst    #30,%d4         |get SE           
159         beqs    e_pos           |don't negate     
160         negl    %d1             |negate before    
161 e_pos:                                            
162         subl    #16,%d1         |sub to compen    
163         bges    e_save          |if still pos,    
164         negl    %d1             |now negative,    
165         orl     #0x40000000,%d4 |set SE in d4,    
166         orl     #0x40000000,(%a0)       |and i    
167 e_save:                                           
168         movel   %d1,L_SCR1(%a6) |save exp in m    
169 |                                                 
170 |                                                 
171 | Calculate mantissa:                             
172 |  1. Calculate absolute value of mantissa in     
173 |  2. Correct for mantissa sign.                  
174 |     (i.e., all digits assumed left of the de    
175 |                                                 
176 | Register usage:                                 
177 |                                                 
178 |  calc_m:                                        
179 |       (*)  d0: temp digit storage               
180 |       (*)  d1: lword counter                    
181 |       (*)  d2: digit count                      
182 |       (*)  d3: offset pointer                   
183 |       ( )  d4: words 2 and 3 of bcd             
184 |       ( )  a0: pointer to working bcd value     
185 |       ( )  a6: pointer to original bcd value    
186 |       (*) fp0: mantissa accumulator             
187 |       ( )  FP_SCR1: working copy of original    
188 |       ( )  L_SCR1: copy of original exponent    
189 |                                                 
190 calc_m:                                           
191         moveql  #1,%d1          |word counter,    
192         fmoves  FZERO,%fp0      |accumulator      
193 |                                                 
194 |                                                 
195 |  Since the packed number has a long word bet    
196 |  get the integer digit then skip down & get     
197 |  mantissa.  We will unroll the loop once.       
198 |                                                 
199         bfextu  (%a0){#28:#4},%d0       |integ    
200         faddb   %d0,%fp0                |add d    
201 |                                                 
202 |                                                 
203 |  Get the rest of the mantissa.                  
204 |                                                 
205 loadlw:                                           
206         movel   (%a0,%d1.L*4),%d4       |load     
207         moveql  #FSTRT,%d3      |counter to pi    
208         moveql  #FNIBS,%d2      |reset number     
209 md2b:                                             
210         fmuls   FTEN,%fp0       |fp0 = fp0 * 1    
211         bfextu  %d4{%d3:#4},%d0 |get the digit    
212         faddb   %d0,%fp0        |fp0 = fp0 + d    
213 |                                                 
214 |                                                 
215 |  If all the digits (8) in that long word hav    
216 |  then inc d1 (=2) to point to the next long     
217 |  to initialize the digit offset, and set d2     
218 |  else continue with this long word.             
219 |                                                 
220         addqb   #4,%d3          |advance d3 to    
221         dbf     %d2,md2b                |check    
222 nextlw:                                           
223         addql   #1,%d1          |inc lw pointe    
224         cmpl    #2,%d1          |test for last    
225         ble     loadlw          |if not, get l    
226                                                   
227 |                                                 
228 |  Check the sign of the mant and make the val    
229 |                                                 
230 m_sign:                                           
231         btst    #31,(%a0)       |test sign of     
232         beq     ap_st_z         |if clear, go     
233         fnegx   %fp0            |if set, negat    
234                                                   
235 |                                                 
236 | Append/strip zeros:                             
237 |                                                 
238 |  For adjusted exponents which have an absolu    
239 |  this routine calculates the amount needed t    
240 |  for the adjusted exponent.  That number is     
241 |  if the exp was positive, and added if it wa    
242 |  of this is to reduce the value of the expon    
243 |  of error in calculation of pwrten.             
244 |                                                 
245 |  1. Branch on the sign of the adjusted expon    
246 |  2p.(positive exp)                              
247 |   2. Check M16 and the digits in lwords 2 an    
248 |   3. Add one for each zero encountered until    
249 |   4. Subtract the count from the exp.           
250 |   5. Check if the exp has crossed zero in #3    
251 |          and set SE.                            
252 |       6. Multiply the mantissa by 10**count.    
253 |  2n.(negative exp)                              
254 |   2. Check the digits in lwords 3 and 2 in d    
255 |   3. Add one for each zero encountered until    
256 |   4. Add the count to the exp.                  
257 |   5. Check if the exp has crossed zero in #3    
258 |   6. Divide the mantissa by 10**count.          
259 |                                                 
260 |  *Why 27?  If the adjusted exponent is withi    
261 |   any adjustment due to append/strip zeros w    
262 |   exponent towards zero.  Since all pwrten c    
263 |   of 27 or less are exact, there is no need     
264 |   attempt to lessen the resultant exponent.     
265 |                                                 
266 | Register usage:                                 
267 |                                                 
268 |  ap_st_z:                                       
269 |       (*)  d0: temp digit storage               
270 |       (*)  d1: zero count                       
271 |       (*)  d2: digit count                      
272 |       (*)  d3: offset pointer                   
273 |       ( )  d4: first word of bcd                
274 |       (*)  d5: lword counter                    
275 |       ( )  a0: pointer to working bcd value     
276 |       ( )  FP_SCR1: working copy of original    
277 |       ( )  L_SCR1: copy of original exponent    
278 |                                                 
279 |                                                 
280 | First check the absolute value of the expone    
281 | routine is necessary.  If so, then check the    
282 | and do append (+) or strip (-) zeros accordi    
283 | This section handles a positive adjusted exp    
284 |                                                 
285 ap_st_z:                                          
286         movel   L_SCR1(%a6),%d1 |load expA for    
287         cmpl    #27,%d1         |test is with     
288         ble     pwrten          |if abs(expA)     
289         btst    #30,(%a0)       |check sign of    
290         bne     ap_st_n         |if neg, go to    
291         clrl    %d1             |zero count re    
292         movel   (%a0),%d4               |load     
293         bfextu  %d4{#28:#4},%d0 |get M16 in d0    
294         bnes    ap_p_fx         |if M16 is non    
295         addql   #1,%d1          |inc zero coun    
296         moveql  #1,%d5          |init lword co    
297         movel   (%a0,%d5.L*4),%d4       |get l    
298         bnes    ap_p_cl         |if lw 2 is ze    
299         addql   #8,%d1          |and inc count    
300         addql   #1,%d5          |inc lword cou    
301         movel   (%a0,%d5.L*4),%d4       |get l    
302 ap_p_cl:                                          
303         clrl    %d3             |init offset r    
304         moveql  #7,%d2          |init digit co    
305 ap_p_gd:                                          
306         bfextu  %d4{%d3:#4},%d0 |get digit        
307         bnes    ap_p_fx         |if non-zero,     
308         addql   #4,%d3          |point to next    
309         addql   #1,%d1          |inc digit cou    
310         dbf     %d2,ap_p_gd     |get next digi    
311 ap_p_fx:                                          
312         movel   %d1,%d0         |copy counter     
313         movel   L_SCR1(%a6),%d1 |get adjusted     
314         subl    %d0,%d1         |subtract coun    
315         bges    ap_p_fm         |if still pos,    
316         negl    %d1             |now its neg;     
317         movel   (%a0),%d4               |load     
318         orl     #0x40000000,%d4 | and set SE i    
319         orl     #0x40000000,(%a0)       | and     
320 |                                                 
321 | Calculate the mantissa multiplier to compens    
322 | zeros from the mantissa.                        
323 |                                                 
324 ap_p_fm:                                          
325         movel   #PTENRN,%a1     |get address o    
326         clrl    %d3             |init table in    
327         fmoves  FONE,%fp1       |init fp1 to 1    
328         moveql  #3,%d2          |init d2 to co    
329 ap_p_el:                                          
330         asrl    #1,%d0          |shift lsb int    
331         bccs    ap_p_en         |if 1, mul fp1    
332         fmulx   (%a1,%d3),%fp1  |mul by 10**(d    
333 ap_p_en:                                          
334         addl    #12,%d3         |inc d3 to nex    
335         tstl    %d0             |check if d0 i    
336         bnes    ap_p_el         |if not, get n    
337         fmulx   %fp1,%fp0               |mul m    
338         bra     pwrten          |go calc pwrte    
339 |                                                 
340 | This section handles a negative adjusted exp    
341 |                                                 
342 ap_st_n:                                          
343         clrl    %d1             |clr counter      
344         moveql  #2,%d5          |set up d5 to     
345         movel   (%a0,%d5.L*4),%d4       |get l    
346         bnes    ap_n_cl         |if not zero,     
347         subl    #1,%d5          |dec d5 to poi    
348         addql   #8,%d1          |inc counter b    
349         movel   (%a0,%d5.L*4),%d4       |get l    
350 ap_n_cl:                                          
351         movel   #28,%d3         |point to last    
352         moveql  #7,%d2          |init digit co    
353 ap_n_gd:                                          
354         bfextu  %d4{%d3:#4},%d0 |get digit        
355         bnes    ap_n_fx         |if non-zero,     
356         subql   #4,%d3          |point to prev    
357         addql   #1,%d1          |inc digit cou    
358         dbf     %d2,ap_n_gd     |get next digi    
359 ap_n_fx:                                          
360         movel   %d1,%d0         |copy counter     
361         movel   L_SCR1(%a6),%d1 |get adjusted     
362         subl    %d0,%d1         |subtract coun    
363         bgts    ap_n_fm         |if still pos,    
364         negl    %d1             |take abs of e    
365         movel   (%a0),%d4               |load     
366         andl    #0xbfffffff,%d4 | and clr SE i    
367         andl    #0xbfffffff,(%a0)       | and     
368 |                                                 
369 | Calculate the mantissa multiplier to compens    
370 | zeros to the mantissa.                          
371 |                                                 
372 ap_n_fm:                                          
373         movel   #PTENRN,%a1     |get address o    
374         clrl    %d3             |init table in    
375         fmoves  FONE,%fp1       |init fp1 to 1    
376         moveql  #3,%d2          |init d2 to co    
377 ap_n_el:                                          
378         asrl    #1,%d0          |shift lsb int    
379         bccs    ap_n_en         |if 1, mul fp1    
380         fmulx   (%a1,%d3),%fp1  |mul by 10**(d    
381 ap_n_en:                                          
382         addl    #12,%d3         |inc d3 to nex    
383         tstl    %d0             |check if d0 i    
384         bnes    ap_n_el         |if not, get n    
385         fdivx   %fp1,%fp0               |div m    
386 |                                                 
387 |                                                 
388 | Calculate power-of-ten factor from adjusted     
389 |                                                 
390 | Register usage:                                 
391 |                                                 
392 |  pwrten:                                        
393 |       (*)  d0: temp                             
394 |       ( )  d1: exponent                         
395 |       (*)  d2: {FPCR[6:5],SM,SE} as index in    
396 |       (*)  d3: FPCR work copy                   
397 |       ( )  d4: first word of bcd                
398 |       (*)  a1: RTABLE pointer                   
399 |  calc_p:                                        
400 |       (*)  d0: temp                             
401 |       ( )  d1: exponent                         
402 |       (*)  d3: PWRTxx table index               
403 |       ( )  a0: pointer to working copy of bc    
404 |       (*)  a1: PWRTxx pointer                   
405 |       (*) fp1: power-of-ten accumulator         
406 |                                                 
407 | Pwrten calculates the exponent factor in the    
408 | according to the following table:               
409 |                                                 
410 |       Sign of Mant  Sign of Exp  Rounding Mo    
411 |                                                 
412 |       ANY       ANY   RN      RN                
413 |                                                 
414 |        +         +    RP      RP                
415 |        -         +    RP      RM                
416 |        +         -    RP      RM                
417 |        -         -    RP      RP                
418 |                                                 
419 |        +         +    RM      RM                
420 |        -         +    RM      RP                
421 |        +         -    RM      RP                
422 |        -         -    RM      RM                
423 |                                                 
424 |        +         +    RZ      RM                
425 |        -         +    RZ      RM                
426 |        +         -    RZ      RP                
427 |        -         -    RZ      RP                
428 |                                                 
429 |                                                 
430 pwrten:                                           
431         movel   USER_FPCR(%a6),%d3 |get user's    
432         bfextu  %d3{#26:#2},%d2 |isolate round    
433         movel   (%a0),%d4               |reloa    
434         asll    #2,%d2          |format d2 to     
435         bfextu  %d4{#0:#2},%d0  | {FPCR[6],FPC    
436         addl    %d0,%d2         |in d2 as inde    
437         leal    RTABLE,%a1      |load rtable b    
438         moveb   (%a1,%d2),%d0   |load new roun    
439         clrl    %d3                     |clear    
440         bfins   %d0,%d3{#26:#2} |stuff new rou    
441         fmovel  %d3,%FPCR               |write    
442         asrl    #1,%d0          |write correct    
443         bccs    not_rp          |to a1            
444         leal    PTENRP,%a1      |it is RP         
445         bras    calc_p          |go to init se    
446 not_rp:                                           
447         asrl    #1,%d0          |keep checking    
448         bccs    not_rm                            
449         leal    PTENRM,%a1      |it is RM         
450         bras    calc_p          |go to init se    
451 not_rm:                                           
452         leal    PTENRN,%a1      |it is RN         
453 calc_p:                                           
454         movel   %d1,%d0         |copy exp to d    
455         bpls    no_neg          |if exp is neg    
456         negl    %d0             |invert it        
457         orl     #0x40000000,(%a0)       |and s    
458 no_neg:                                           
459         clrl    %d3             |table index      
460         fmoves  FONE,%fp1       |init fp1 to 1    
461 e_loop:                                           
462         asrl    #1,%d0          |shift next bi    
463         bccs    e_next          |if zero, skip    
464         fmulx   (%a1,%d3),%fp1  |mul by 10**(d    
465 e_next:                                           
466         addl    #12,%d3         |inc d3 to nex    
467         tstl    %d0             |check if d0 i    
468         bnes    e_loop          |not zero, con    
469 |                                                 
470 |                                                 
471 |  Check the sign of the adjusted exp and make    
472 |  same sign. If the exp was pos then multiply    
473 |  else divide fp0/fp1.                           
474 |                                                 
475 | Register Usage:                                 
476 |  norm:                                          
477 |       ( )  a0: pointer to working bcd value     
478 |       (*) fp0: mantissa accumulator             
479 |       ( ) fp1: scaling factor - 10**(abs(exp    
480 |                                                 
481 norm:                                             
482         btst    #30,(%a0)       |test the sign    
483         beqs    mul             |if clear, go     
484 div:                                              
485         fdivx   %fp1,%fp0               |exp i    
486         bras    end_dec                           
487 mul:                                              
488         fmulx   %fp1,%fp0               |exp i    
489 |                                                 
490 |                                                 
491 | Clean up and return with result in fp0.         
492 |                                                 
493 | If the final mul/div in decbin incurred an i    
494 | it will be inex2, but will be reported as in    
495 |                                                 
496 end_dec:                                          
497         fmovel  %FPSR,%d0               |get s    
498         bclrl   #inex2_bit+8,%d0        |test     
499         fmovel  %d0,%FPSR               |retur    
500         beqs    no_exc          |skip this if     
501         orl     #inx1a_mask,USER_FPSR(%a6) |se    
502 no_exc:                                           
503         moveml  (%a7)+,%d2-%d5                    
504         rts                                       
505         |end                                      
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php