11da177e4SLinus Torvalds| 21da177e4SLinus Torvalds| decbin.sa 3.3 12/19/90 31da177e4SLinus Torvalds| 41da177e4SLinus Torvalds| Description: Converts normalized packed bcd value pointed to by 51da177e4SLinus Torvalds| register A6 to extended-precision value in FP0. 61da177e4SLinus Torvalds| 71da177e4SLinus Torvalds| Input: Normalized packed bcd value in ETEMP(a6). 81da177e4SLinus Torvalds| 91da177e4SLinus Torvalds| Output: Exact floating-point representation of the packed bcd value. 101da177e4SLinus Torvalds| 111da177e4SLinus Torvalds| Saves and Modifies: D2-D5 121da177e4SLinus Torvalds| 131da177e4SLinus Torvalds| Speed: The program decbin takes ??? cycles to execute. 141da177e4SLinus Torvalds| 151da177e4SLinus Torvalds| Object Size: 161da177e4SLinus Torvalds| 171da177e4SLinus Torvalds| External Reference(s): None. 181da177e4SLinus Torvalds| 191da177e4SLinus Torvalds| Algorithm: 201da177e4SLinus Torvalds| Expected is a normal bcd (i.e. non-exceptional; all inf, zero, 211da177e4SLinus Torvalds| and NaN operands are dispatched without entering this routine) 221da177e4SLinus Torvalds| value in 68881/882 format at location ETEMP(A6). 231da177e4SLinus Torvalds| 241da177e4SLinus Torvalds| A1. Convert the bcd exponent to binary by successive adds and muls. 251da177e4SLinus Torvalds| Set the sign according to SE. Subtract 16 to compensate 261da177e4SLinus Torvalds| for the mantissa which is to be interpreted as 17 integer 271da177e4SLinus Torvalds| digits, rather than 1 integer and 16 fraction digits. 281da177e4SLinus Torvalds| Note: this operation can never overflow. 291da177e4SLinus Torvalds| 301da177e4SLinus Torvalds| A2. Convert the bcd mantissa to binary by successive 311da177e4SLinus Torvalds| adds and muls in FP0. Set the sign according to SM. 321da177e4SLinus Torvalds| The mantissa digits will be converted with the decimal point 331da177e4SLinus Torvalds| assumed following the least-significant digit. 341da177e4SLinus Torvalds| Note: this operation can never overflow. 351da177e4SLinus Torvalds| 361da177e4SLinus Torvalds| A3. Count the number of leading/trailing zeros in the 371da177e4SLinus Torvalds| bcd string. If SE is positive, count the leading zeros; 381da177e4SLinus Torvalds| if negative, count the trailing zeros. Set the adjusted 391da177e4SLinus Torvalds| exponent equal to the exponent from A1 and the zero count 401da177e4SLinus Torvalds| added if SM = 1 and subtracted if SM = 0. Scale the 411da177e4SLinus Torvalds| mantissa the equivalent of forcing in the bcd value: 421da177e4SLinus Torvalds| 431da177e4SLinus Torvalds| SM = 0 a non-zero digit in the integer position 441da177e4SLinus Torvalds| SM = 1 a non-zero digit in Mant0, lsd of the fraction 451da177e4SLinus Torvalds| 461da177e4SLinus Torvalds| this will insure that any value, regardless of its 471da177e4SLinus Torvalds| representation (ex. 0.1E2, 1E1, 10E0, 100E-1), is converted 481da177e4SLinus Torvalds| consistently. 491da177e4SLinus Torvalds| 501da177e4SLinus Torvalds| A4. Calculate the factor 10^exp in FP1 using a table of 511da177e4SLinus Torvalds| 10^(2^n) values. To reduce the error in forming factors 521da177e4SLinus Torvalds| greater than 10^27, a directed rounding scheme is used with 531da177e4SLinus Torvalds| tables rounded to RN, RM, and RP, according to the table 541da177e4SLinus Torvalds| in the comments of the pwrten section. 551da177e4SLinus Torvalds| 561da177e4SLinus Torvalds| A5. Form the final binary number by scaling the mantissa by 571da177e4SLinus Torvalds| the exponent factor. This is done by multiplying the 581da177e4SLinus Torvalds| mantissa in FP0 by the factor in FP1 if the adjusted 591da177e4SLinus Torvalds| exponent sign is positive, and dividing FP0 by FP1 if 601da177e4SLinus Torvalds| it is negative. 611da177e4SLinus Torvalds| 621da177e4SLinus Torvalds| Clean up and return. Check if the final mul or div resulted 631da177e4SLinus Torvalds| in an inex2 exception. If so, set inex1 in the fpsr and 641da177e4SLinus Torvalds| check if the inex1 exception is enabled. If so, set d7 upper 651da177e4SLinus Torvalds| word to $0100. This will signal unimp.sa that an enabled inex1 661da177e4SLinus Torvalds| exception occurred. Unimp will fix the stack. 671da177e4SLinus Torvalds| 681da177e4SLinus Torvalds 691da177e4SLinus Torvalds| Copyright (C) Motorola, Inc. 1990 701da177e4SLinus Torvalds| All Rights Reserved 711da177e4SLinus Torvalds| 72*e00d82d0SMatt Waddel| For details on the license for this file, please see the 73*e00d82d0SMatt Waddel| file, README, in this same directory. 741da177e4SLinus Torvalds 751da177e4SLinus Torvalds|DECBIN idnt 2,1 | Motorola 040 Floating Point Software Package 761da177e4SLinus Torvalds 771da177e4SLinus Torvalds |section 8 781da177e4SLinus Torvalds 791da177e4SLinus Torvalds#include "fpsp.h" 801da177e4SLinus Torvalds 811da177e4SLinus Torvalds| 821da177e4SLinus Torvalds| PTENRN, PTENRM, and PTENRP are arrays of powers of 10 rounded 831da177e4SLinus Torvalds| to nearest, minus, and plus, respectively. The tables include 841da177e4SLinus Torvalds| 10**{1,2,4,8,16,32,64,128,256,512,1024,2048,4096}. No rounding 851da177e4SLinus Torvalds| is required until the power is greater than 27, however, all 861da177e4SLinus Torvalds| tables include the first 5 for ease of indexing. 871da177e4SLinus Torvalds| 881da177e4SLinus Torvalds |xref PTENRN 891da177e4SLinus Torvalds |xref PTENRM 901da177e4SLinus Torvalds |xref PTENRP 911da177e4SLinus Torvalds 921da177e4SLinus TorvaldsRTABLE: .byte 0,0,0,0 931da177e4SLinus Torvalds .byte 2,3,2,3 941da177e4SLinus Torvalds .byte 2,3,3,2 951da177e4SLinus Torvalds .byte 3,2,2,3 961da177e4SLinus Torvalds 971da177e4SLinus Torvalds .global decbin 981da177e4SLinus Torvalds .global calc_e 991da177e4SLinus Torvalds .global pwrten 1001da177e4SLinus Torvalds .global calc_m 1011da177e4SLinus Torvalds .global norm 1021da177e4SLinus Torvalds .global ap_st_z 1031da177e4SLinus Torvalds .global ap_st_n 1041da177e4SLinus Torvalds| 1051da177e4SLinus Torvalds .set FNIBS,7 1061da177e4SLinus Torvalds .set FSTRT,0 1071da177e4SLinus Torvalds| 1081da177e4SLinus Torvalds .set ESTRT,4 1091da177e4SLinus Torvalds .set EDIGITS,2 | 1101da177e4SLinus Torvalds| 1111da177e4SLinus Torvalds| Constants in single precision 1121da177e4SLinus TorvaldsFZERO: .long 0x00000000 1131da177e4SLinus TorvaldsFONE: .long 0x3F800000 1141da177e4SLinus TorvaldsFTEN: .long 0x41200000 1151da177e4SLinus Torvalds 1161da177e4SLinus Torvalds .set TEN,10 1171da177e4SLinus Torvalds 1181da177e4SLinus Torvalds| 1191da177e4SLinus Torvaldsdecbin: 1201da177e4SLinus Torvalds | fmovel #0,FPCR ;clr real fpcr 1211da177e4SLinus Torvalds moveml %d2-%d5,-(%a7) 1221da177e4SLinus Torvalds| 1231da177e4SLinus Torvalds| Calculate exponent: 1241da177e4SLinus Torvalds| 1. Copy bcd value in memory for use as a working copy. 1251da177e4SLinus Torvalds| 2. Calculate absolute value of exponent in d1 by mul and add. 1261da177e4SLinus Torvalds| 3. Correct for exponent sign. 1271da177e4SLinus Torvalds| 4. Subtract 16 to compensate for interpreting the mant as all integer digits. 1281da177e4SLinus Torvalds| (i.e., all digits assumed left of the decimal point.) 1291da177e4SLinus Torvalds| 1301da177e4SLinus Torvalds| Register usage: 1311da177e4SLinus Torvalds| 1321da177e4SLinus Torvalds| calc_e: 1331da177e4SLinus Torvalds| (*) d0: temp digit storage 1341da177e4SLinus Torvalds| (*) d1: accumulator for binary exponent 1351da177e4SLinus Torvalds| (*) d2: digit count 1361da177e4SLinus Torvalds| (*) d3: offset pointer 1371da177e4SLinus Torvalds| ( ) d4: first word of bcd 1381da177e4SLinus Torvalds| ( ) a0: pointer to working bcd value 1391da177e4SLinus Torvalds| ( ) a6: pointer to original bcd value 1401da177e4SLinus Torvalds| (*) FP_SCR1: working copy of original bcd value 1411da177e4SLinus Torvalds| (*) L_SCR1: copy of original exponent word 1421da177e4SLinus Torvalds| 1431da177e4SLinus Torvaldscalc_e: 1441da177e4SLinus Torvalds movel #EDIGITS,%d2 |# of nibbles (digits) in fraction part 1451da177e4SLinus Torvalds moveql #ESTRT,%d3 |counter to pick up digits 1461da177e4SLinus Torvalds leal FP_SCR1(%a6),%a0 |load tmp bcd storage address 1471da177e4SLinus Torvalds movel ETEMP(%a6),(%a0) |save input bcd value 1481da177e4SLinus Torvalds movel ETEMP_HI(%a6),4(%a0) |save words 2 and 3 1491da177e4SLinus Torvalds movel ETEMP_LO(%a6),8(%a0) |and work with these 1501da177e4SLinus Torvalds movel (%a0),%d4 |get first word of bcd 1511da177e4SLinus Torvalds clrl %d1 |zero d1 for accumulator 1521da177e4SLinus Torvaldse_gd: 1531da177e4SLinus Torvalds mulul #TEN,%d1 |mul partial product by one digit place 1541da177e4SLinus Torvalds bfextu %d4{%d3:#4},%d0 |get the digit and zero extend into d0 1551da177e4SLinus Torvalds addl %d0,%d1 |d1 = d1 + d0 1561da177e4SLinus Torvalds addqb #4,%d3 |advance d3 to the next digit 1571da177e4SLinus Torvalds dbf %d2,e_gd |if we have used all 3 digits, exit loop 1581da177e4SLinus Torvalds btst #30,%d4 |get SE 1591da177e4SLinus Torvalds beqs e_pos |don't negate if pos 1601da177e4SLinus Torvalds negl %d1 |negate before subtracting 1611da177e4SLinus Torvaldse_pos: 1621da177e4SLinus Torvalds subl #16,%d1 |sub to compensate for shift of mant 1631da177e4SLinus Torvalds bges e_save |if still pos, do not neg 1641da177e4SLinus Torvalds negl %d1 |now negative, make pos and set SE 1651da177e4SLinus Torvalds orl #0x40000000,%d4 |set SE in d4, 1661da177e4SLinus Torvalds orl #0x40000000,(%a0) |and in working bcd 1671da177e4SLinus Torvaldse_save: 1681da177e4SLinus Torvalds movel %d1,L_SCR1(%a6) |save exp in memory 1691da177e4SLinus Torvalds| 1701da177e4SLinus Torvalds| 1711da177e4SLinus Torvalds| Calculate mantissa: 1721da177e4SLinus Torvalds| 1. Calculate absolute value of mantissa in fp0 by mul and add. 1731da177e4SLinus Torvalds| 2. Correct for mantissa sign. 1741da177e4SLinus Torvalds| (i.e., all digits assumed left of the decimal point.) 1751da177e4SLinus Torvalds| 1761da177e4SLinus Torvalds| Register usage: 1771da177e4SLinus Torvalds| 1781da177e4SLinus Torvalds| calc_m: 1791da177e4SLinus Torvalds| (*) d0: temp digit storage 1801da177e4SLinus Torvalds| (*) d1: lword counter 1811da177e4SLinus Torvalds| (*) d2: digit count 1821da177e4SLinus Torvalds| (*) d3: offset pointer 1831da177e4SLinus Torvalds| ( ) d4: words 2 and 3 of bcd 1841da177e4SLinus Torvalds| ( ) a0: pointer to working bcd value 1851da177e4SLinus Torvalds| ( ) a6: pointer to original bcd value 1861da177e4SLinus Torvalds| (*) fp0: mantissa accumulator 1871da177e4SLinus Torvalds| ( ) FP_SCR1: working copy of original bcd value 1881da177e4SLinus Torvalds| ( ) L_SCR1: copy of original exponent word 1891da177e4SLinus Torvalds| 1901da177e4SLinus Torvaldscalc_m: 1911da177e4SLinus Torvalds moveql #1,%d1 |word counter, init to 1 1921da177e4SLinus Torvalds fmoves FZERO,%fp0 |accumulator 1931da177e4SLinus Torvalds| 1941da177e4SLinus Torvalds| 1951da177e4SLinus Torvalds| Since the packed number has a long word between the first & second parts, 1961da177e4SLinus Torvalds| get the integer digit then skip down & get the rest of the 1971da177e4SLinus Torvalds| mantissa. We will unroll the loop once. 1981da177e4SLinus Torvalds| 1991da177e4SLinus Torvalds bfextu (%a0){#28:#4},%d0 |integer part is ls digit in long word 2001da177e4SLinus Torvalds faddb %d0,%fp0 |add digit to sum in fp0 2011da177e4SLinus Torvalds| 2021da177e4SLinus Torvalds| 2031da177e4SLinus Torvalds| Get the rest of the mantissa. 2041da177e4SLinus Torvalds| 2051da177e4SLinus Torvaldsloadlw: 2061da177e4SLinus Torvalds movel (%a0,%d1.L*4),%d4 |load mantissa longword into d4 2071da177e4SLinus Torvalds moveql #FSTRT,%d3 |counter to pick up digits 2081da177e4SLinus Torvalds moveql #FNIBS,%d2 |reset number of digits per a0 ptr 2091da177e4SLinus Torvaldsmd2b: 2101da177e4SLinus Torvalds fmuls FTEN,%fp0 |fp0 = fp0 * 10 2111da177e4SLinus Torvalds bfextu %d4{%d3:#4},%d0 |get the digit and zero extend 2121da177e4SLinus Torvalds faddb %d0,%fp0 |fp0 = fp0 + digit 2131da177e4SLinus Torvalds| 2141da177e4SLinus Torvalds| 2151da177e4SLinus Torvalds| If all the digits (8) in that long word have been converted (d2=0), 2161da177e4SLinus Torvalds| then inc d1 (=2) to point to the next long word and reset d3 to 0 2171da177e4SLinus Torvalds| to initialize the digit offset, and set d2 to 7 for the digit count; 2181da177e4SLinus Torvalds| else continue with this long word. 2191da177e4SLinus Torvalds| 2201da177e4SLinus Torvalds addqb #4,%d3 |advance d3 to the next digit 2211da177e4SLinus Torvalds dbf %d2,md2b |check for last digit in this lw 2221da177e4SLinus Torvaldsnextlw: 2231da177e4SLinus Torvalds addql #1,%d1 |inc lw pointer in mantissa 2241da177e4SLinus Torvalds cmpl #2,%d1 |test for last lw 2251da177e4SLinus Torvalds ble loadlw |if not, get last one 2261da177e4SLinus Torvalds 2271da177e4SLinus Torvalds| 2281da177e4SLinus Torvalds| Check the sign of the mant and make the value in fp0 the same sign. 2291da177e4SLinus Torvalds| 2301da177e4SLinus Torvaldsm_sign: 2311da177e4SLinus Torvalds btst #31,(%a0) |test sign of the mantissa 2321da177e4SLinus Torvalds beq ap_st_z |if clear, go to append/strip zeros 2331da177e4SLinus Torvalds fnegx %fp0 |if set, negate fp0 2341da177e4SLinus Torvalds 2351da177e4SLinus Torvalds| 2361da177e4SLinus Torvalds| Append/strip zeros: 2371da177e4SLinus Torvalds| 2381da177e4SLinus Torvalds| For adjusted exponents which have an absolute value greater than 27*, 2391da177e4SLinus Torvalds| this routine calculates the amount needed to normalize the mantissa 2401da177e4SLinus Torvalds| for the adjusted exponent. That number is subtracted from the exp 2411da177e4SLinus Torvalds| if the exp was positive, and added if it was negative. The purpose 2421da177e4SLinus Torvalds| of this is to reduce the value of the exponent and the possibility 2431da177e4SLinus Torvalds| of error in calculation of pwrten. 2441da177e4SLinus Torvalds| 2451da177e4SLinus Torvalds| 1. Branch on the sign of the adjusted exponent. 2461da177e4SLinus Torvalds| 2p.(positive exp) 2471da177e4SLinus Torvalds| 2. Check M16 and the digits in lwords 2 and 3 in descending order. 2481da177e4SLinus Torvalds| 3. Add one for each zero encountered until a non-zero digit. 2491da177e4SLinus Torvalds| 4. Subtract the count from the exp. 2501da177e4SLinus Torvalds| 5. Check if the exp has crossed zero in #3 above; make the exp abs 2511da177e4SLinus Torvalds| and set SE. 2521da177e4SLinus Torvalds| 6. Multiply the mantissa by 10**count. 2531da177e4SLinus Torvalds| 2n.(negative exp) 2541da177e4SLinus Torvalds| 2. Check the digits in lwords 3 and 2 in descending order. 2551da177e4SLinus Torvalds| 3. Add one for each zero encountered until a non-zero digit. 2561da177e4SLinus Torvalds| 4. Add the count to the exp. 2571da177e4SLinus Torvalds| 5. Check if the exp has crossed zero in #3 above; clear SE. 2581da177e4SLinus Torvalds| 6. Divide the mantissa by 10**count. 2591da177e4SLinus Torvalds| 2601da177e4SLinus Torvalds| *Why 27? If the adjusted exponent is within -28 < expA < 28, than 2611da177e4SLinus Torvalds| any adjustment due to append/strip zeros will drive the resultant 2621da177e4SLinus Torvalds| exponent towards zero. Since all pwrten constants with a power 2631da177e4SLinus Torvalds| of 27 or less are exact, there is no need to use this routine to 2641da177e4SLinus Torvalds| attempt to lessen the resultant exponent. 2651da177e4SLinus Torvalds| 2661da177e4SLinus Torvalds| Register usage: 2671da177e4SLinus Torvalds| 2681da177e4SLinus Torvalds| ap_st_z: 2691da177e4SLinus Torvalds| (*) d0: temp digit storage 2701da177e4SLinus Torvalds| (*) d1: zero count 2711da177e4SLinus Torvalds| (*) d2: digit count 2721da177e4SLinus Torvalds| (*) d3: offset pointer 2731da177e4SLinus Torvalds| ( ) d4: first word of bcd 2741da177e4SLinus Torvalds| (*) d5: lword counter 2751da177e4SLinus Torvalds| ( ) a0: pointer to working bcd value 2761da177e4SLinus Torvalds| ( ) FP_SCR1: working copy of original bcd value 2771da177e4SLinus Torvalds| ( ) L_SCR1: copy of original exponent word 2781da177e4SLinus Torvalds| 2791da177e4SLinus Torvalds| 2801da177e4SLinus Torvalds| First check the absolute value of the exponent to see if this 2811da177e4SLinus Torvalds| routine is necessary. If so, then check the sign of the exponent 2821da177e4SLinus Torvalds| and do append (+) or strip (-) zeros accordingly. 2831da177e4SLinus Torvalds| This section handles a positive adjusted exponent. 2841da177e4SLinus Torvalds| 2851da177e4SLinus Torvaldsap_st_z: 2861da177e4SLinus Torvalds movel L_SCR1(%a6),%d1 |load expA for range test 2871da177e4SLinus Torvalds cmpl #27,%d1 |test is with 27 2881da177e4SLinus Torvalds ble pwrten |if abs(expA) <28, skip ap/st zeros 2891da177e4SLinus Torvalds btst #30,(%a0) |check sign of exp 2901da177e4SLinus Torvalds bne ap_st_n |if neg, go to neg side 2911da177e4SLinus Torvalds clrl %d1 |zero count reg 2921da177e4SLinus Torvalds movel (%a0),%d4 |load lword 1 to d4 2931da177e4SLinus Torvalds bfextu %d4{#28:#4},%d0 |get M16 in d0 2941da177e4SLinus Torvalds bnes ap_p_fx |if M16 is non-zero, go fix exp 2951da177e4SLinus Torvalds addql #1,%d1 |inc zero count 2961da177e4SLinus Torvalds moveql #1,%d5 |init lword counter 2971da177e4SLinus Torvalds movel (%a0,%d5.L*4),%d4 |get lword 2 to d4 2981da177e4SLinus Torvalds bnes ap_p_cl |if lw 2 is zero, skip it 2991da177e4SLinus Torvalds addql #8,%d1 |and inc count by 8 3001da177e4SLinus Torvalds addql #1,%d5 |inc lword counter 3011da177e4SLinus Torvalds movel (%a0,%d5.L*4),%d4 |get lword 3 to d4 3021da177e4SLinus Torvaldsap_p_cl: 3031da177e4SLinus Torvalds clrl %d3 |init offset reg 3041da177e4SLinus Torvalds moveql #7,%d2 |init digit counter 3051da177e4SLinus Torvaldsap_p_gd: 3061da177e4SLinus Torvalds bfextu %d4{%d3:#4},%d0 |get digit 3071da177e4SLinus Torvalds bnes ap_p_fx |if non-zero, go to fix exp 3081da177e4SLinus Torvalds addql #4,%d3 |point to next digit 3091da177e4SLinus Torvalds addql #1,%d1 |inc digit counter 3101da177e4SLinus Torvalds dbf %d2,ap_p_gd |get next digit 3111da177e4SLinus Torvaldsap_p_fx: 3121da177e4SLinus Torvalds movel %d1,%d0 |copy counter to d2 3131da177e4SLinus Torvalds movel L_SCR1(%a6),%d1 |get adjusted exp from memory 3141da177e4SLinus Torvalds subl %d0,%d1 |subtract count from exp 3151da177e4SLinus Torvalds bges ap_p_fm |if still pos, go to pwrten 3161da177e4SLinus Torvalds negl %d1 |now its neg; get abs 3171da177e4SLinus Torvalds movel (%a0),%d4 |load lword 1 to d4 3181da177e4SLinus Torvalds orl #0x40000000,%d4 | and set SE in d4 3191da177e4SLinus Torvalds orl #0x40000000,(%a0) | and in memory 3201da177e4SLinus Torvalds| 3211da177e4SLinus Torvalds| Calculate the mantissa multiplier to compensate for the striping of 3221da177e4SLinus Torvalds| zeros from the mantissa. 3231da177e4SLinus Torvalds| 3241da177e4SLinus Torvaldsap_p_fm: 3251da177e4SLinus Torvalds movel #PTENRN,%a1 |get address of power-of-ten table 3261da177e4SLinus Torvalds clrl %d3 |init table index 3271da177e4SLinus Torvalds fmoves FONE,%fp1 |init fp1 to 1 3281da177e4SLinus Torvalds moveql #3,%d2 |init d2 to count bits in counter 3291da177e4SLinus Torvaldsap_p_el: 3301da177e4SLinus Torvalds asrl #1,%d0 |shift lsb into carry 3311da177e4SLinus Torvalds bccs ap_p_en |if 1, mul fp1 by pwrten factor 3321da177e4SLinus Torvalds fmulx (%a1,%d3),%fp1 |mul by 10**(d3_bit_no) 3331da177e4SLinus Torvaldsap_p_en: 3341da177e4SLinus Torvalds addl #12,%d3 |inc d3 to next rtable entry 3351da177e4SLinus Torvalds tstl %d0 |check if d0 is zero 3361da177e4SLinus Torvalds bnes ap_p_el |if not, get next bit 3371da177e4SLinus Torvalds fmulx %fp1,%fp0 |mul mantissa by 10**(no_bits_shifted) 3381da177e4SLinus Torvalds bra pwrten |go calc pwrten 3391da177e4SLinus Torvalds| 3401da177e4SLinus Torvalds| This section handles a negative adjusted exponent. 3411da177e4SLinus Torvalds| 3421da177e4SLinus Torvaldsap_st_n: 3431da177e4SLinus Torvalds clrl %d1 |clr counter 3441da177e4SLinus Torvalds moveql #2,%d5 |set up d5 to point to lword 3 3451da177e4SLinus Torvalds movel (%a0,%d5.L*4),%d4 |get lword 3 3461da177e4SLinus Torvalds bnes ap_n_cl |if not zero, check digits 3471da177e4SLinus Torvalds subl #1,%d5 |dec d5 to point to lword 2 3481da177e4SLinus Torvalds addql #8,%d1 |inc counter by 8 3491da177e4SLinus Torvalds movel (%a0,%d5.L*4),%d4 |get lword 2 3501da177e4SLinus Torvaldsap_n_cl: 3511da177e4SLinus Torvalds movel #28,%d3 |point to last digit 3521da177e4SLinus Torvalds moveql #7,%d2 |init digit counter 3531da177e4SLinus Torvaldsap_n_gd: 3541da177e4SLinus Torvalds bfextu %d4{%d3:#4},%d0 |get digit 3551da177e4SLinus Torvalds bnes ap_n_fx |if non-zero, go to exp fix 3561da177e4SLinus Torvalds subql #4,%d3 |point to previous digit 3571da177e4SLinus Torvalds addql #1,%d1 |inc digit counter 3581da177e4SLinus Torvalds dbf %d2,ap_n_gd |get next digit 3591da177e4SLinus Torvaldsap_n_fx: 3601da177e4SLinus Torvalds movel %d1,%d0 |copy counter to d0 3611da177e4SLinus Torvalds movel L_SCR1(%a6),%d1 |get adjusted exp from memory 3621da177e4SLinus Torvalds subl %d0,%d1 |subtract count from exp 3631da177e4SLinus Torvalds bgts ap_n_fm |if still pos, go fix mantissa 3641da177e4SLinus Torvalds negl %d1 |take abs of exp and clr SE 3651da177e4SLinus Torvalds movel (%a0),%d4 |load lword 1 to d4 3661da177e4SLinus Torvalds andl #0xbfffffff,%d4 | and clr SE in d4 3671da177e4SLinus Torvalds andl #0xbfffffff,(%a0) | and in memory 3681da177e4SLinus Torvalds| 3691da177e4SLinus Torvalds| Calculate the mantissa multiplier to compensate for the appending of 3701da177e4SLinus Torvalds| zeros to the mantissa. 3711da177e4SLinus Torvalds| 3721da177e4SLinus Torvaldsap_n_fm: 3731da177e4SLinus Torvalds movel #PTENRN,%a1 |get address of power-of-ten table 3741da177e4SLinus Torvalds clrl %d3 |init table index 3751da177e4SLinus Torvalds fmoves FONE,%fp1 |init fp1 to 1 3761da177e4SLinus Torvalds moveql #3,%d2 |init d2 to count bits in counter 3771da177e4SLinus Torvaldsap_n_el: 3781da177e4SLinus Torvalds asrl #1,%d0 |shift lsb into carry 3791da177e4SLinus Torvalds bccs ap_n_en |if 1, mul fp1 by pwrten factor 3801da177e4SLinus Torvalds fmulx (%a1,%d3),%fp1 |mul by 10**(d3_bit_no) 3811da177e4SLinus Torvaldsap_n_en: 3821da177e4SLinus Torvalds addl #12,%d3 |inc d3 to next rtable entry 3831da177e4SLinus Torvalds tstl %d0 |check if d0 is zero 3841da177e4SLinus Torvalds bnes ap_n_el |if not, get next bit 3851da177e4SLinus Torvalds fdivx %fp1,%fp0 |div mantissa by 10**(no_bits_shifted) 3861da177e4SLinus Torvalds| 3871da177e4SLinus Torvalds| 3881da177e4SLinus Torvalds| Calculate power-of-ten factor from adjusted and shifted exponent. 3891da177e4SLinus Torvalds| 3901da177e4SLinus Torvalds| Register usage: 3911da177e4SLinus Torvalds| 3921da177e4SLinus Torvalds| pwrten: 3931da177e4SLinus Torvalds| (*) d0: temp 3941da177e4SLinus Torvalds| ( ) d1: exponent 3951da177e4SLinus Torvalds| (*) d2: {FPCR[6:5],SM,SE} as index in RTABLE; temp 3961da177e4SLinus Torvalds| (*) d3: FPCR work copy 3971da177e4SLinus Torvalds| ( ) d4: first word of bcd 3981da177e4SLinus Torvalds| (*) a1: RTABLE pointer 3991da177e4SLinus Torvalds| calc_p: 4001da177e4SLinus Torvalds| (*) d0: temp 4011da177e4SLinus Torvalds| ( ) d1: exponent 4021da177e4SLinus Torvalds| (*) d3: PWRTxx table index 4031da177e4SLinus Torvalds| ( ) a0: pointer to working copy of bcd 4041da177e4SLinus Torvalds| (*) a1: PWRTxx pointer 4051da177e4SLinus Torvalds| (*) fp1: power-of-ten accumulator 4061da177e4SLinus Torvalds| 4071da177e4SLinus Torvalds| Pwrten calculates the exponent factor in the selected rounding mode 4081da177e4SLinus Torvalds| according to the following table: 4091da177e4SLinus Torvalds| 4101da177e4SLinus Torvalds| Sign of Mant Sign of Exp Rounding Mode PWRTEN Rounding Mode 4111da177e4SLinus Torvalds| 4121da177e4SLinus Torvalds| ANY ANY RN RN 4131da177e4SLinus Torvalds| 4141da177e4SLinus Torvalds| + + RP RP 4151da177e4SLinus Torvalds| - + RP RM 4161da177e4SLinus Torvalds| + - RP RM 4171da177e4SLinus Torvalds| - - RP RP 4181da177e4SLinus Torvalds| 4191da177e4SLinus Torvalds| + + RM RM 4201da177e4SLinus Torvalds| - + RM RP 4211da177e4SLinus Torvalds| + - RM RP 4221da177e4SLinus Torvalds| - - RM RM 4231da177e4SLinus Torvalds| 4241da177e4SLinus Torvalds| + + RZ RM 4251da177e4SLinus Torvalds| - + RZ RM 4261da177e4SLinus Torvalds| + - RZ RP 4271da177e4SLinus Torvalds| - - RZ RP 4281da177e4SLinus Torvalds| 4291da177e4SLinus Torvalds| 4301da177e4SLinus Torvaldspwrten: 4311da177e4SLinus Torvalds movel USER_FPCR(%a6),%d3 |get user's FPCR 4321da177e4SLinus Torvalds bfextu %d3{#26:#2},%d2 |isolate rounding mode bits 4331da177e4SLinus Torvalds movel (%a0),%d4 |reload 1st bcd word to d4 4341da177e4SLinus Torvalds asll #2,%d2 |format d2 to be 4351da177e4SLinus Torvalds bfextu %d4{#0:#2},%d0 | {FPCR[6],FPCR[5],SM,SE} 4361da177e4SLinus Torvalds addl %d0,%d2 |in d2 as index into RTABLE 4371da177e4SLinus Torvalds leal RTABLE,%a1 |load rtable base 4381da177e4SLinus Torvalds moveb (%a1,%d2),%d0 |load new rounding bits from table 4391da177e4SLinus Torvalds clrl %d3 |clear d3 to force no exc and extended 4401da177e4SLinus Torvalds bfins %d0,%d3{#26:#2} |stuff new rounding bits in FPCR 4411da177e4SLinus Torvalds fmovel %d3,%FPCR |write new FPCR 4421da177e4SLinus Torvalds asrl #1,%d0 |write correct PTENxx table 4431da177e4SLinus Torvalds bccs not_rp |to a1 4441da177e4SLinus Torvalds leal PTENRP,%a1 |it is RP 4451da177e4SLinus Torvalds bras calc_p |go to init section 4461da177e4SLinus Torvaldsnot_rp: 4471da177e4SLinus Torvalds asrl #1,%d0 |keep checking 4481da177e4SLinus Torvalds bccs not_rm 4491da177e4SLinus Torvalds leal PTENRM,%a1 |it is RM 4501da177e4SLinus Torvalds bras calc_p |go to init section 4511da177e4SLinus Torvaldsnot_rm: 4521da177e4SLinus Torvalds leal PTENRN,%a1 |it is RN 4531da177e4SLinus Torvaldscalc_p: 4541da177e4SLinus Torvalds movel %d1,%d0 |copy exp to d0;use d0 4551da177e4SLinus Torvalds bpls no_neg |if exp is negative, 4561da177e4SLinus Torvalds negl %d0 |invert it 4571da177e4SLinus Torvalds orl #0x40000000,(%a0) |and set SE bit 4581da177e4SLinus Torvaldsno_neg: 4591da177e4SLinus Torvalds clrl %d3 |table index 4601da177e4SLinus Torvalds fmoves FONE,%fp1 |init fp1 to 1 4611da177e4SLinus Torvaldse_loop: 4621da177e4SLinus Torvalds asrl #1,%d0 |shift next bit into carry 4631da177e4SLinus Torvalds bccs e_next |if zero, skip the mul 4641da177e4SLinus Torvalds fmulx (%a1,%d3),%fp1 |mul by 10**(d3_bit_no) 4651da177e4SLinus Torvaldse_next: 4661da177e4SLinus Torvalds addl #12,%d3 |inc d3 to next rtable entry 4671da177e4SLinus Torvalds tstl %d0 |check if d0 is zero 4681da177e4SLinus Torvalds bnes e_loop |not zero, continue shifting 4691da177e4SLinus Torvalds| 4701da177e4SLinus Torvalds| 4711da177e4SLinus Torvalds| Check the sign of the adjusted exp and make the value in fp0 the 4721da177e4SLinus Torvalds| same sign. If the exp was pos then multiply fp1*fp0; 4731da177e4SLinus Torvalds| else divide fp0/fp1. 4741da177e4SLinus Torvalds| 4751da177e4SLinus Torvalds| Register Usage: 4761da177e4SLinus Torvalds| norm: 4771da177e4SLinus Torvalds| ( ) a0: pointer to working bcd value 4781da177e4SLinus Torvalds| (*) fp0: mantissa accumulator 4791da177e4SLinus Torvalds| ( ) fp1: scaling factor - 10**(abs(exp)) 4801da177e4SLinus Torvalds| 4811da177e4SLinus Torvaldsnorm: 4821da177e4SLinus Torvalds btst #30,(%a0) |test the sign of the exponent 4831da177e4SLinus Torvalds beqs mul |if clear, go to multiply 4841da177e4SLinus Torvaldsdiv: 4851da177e4SLinus Torvalds fdivx %fp1,%fp0 |exp is negative, so divide mant by exp 4861da177e4SLinus Torvalds bras end_dec 4871da177e4SLinus Torvaldsmul: 4881da177e4SLinus Torvalds fmulx %fp1,%fp0 |exp is positive, so multiply by exp 4891da177e4SLinus Torvalds| 4901da177e4SLinus Torvalds| 4911da177e4SLinus Torvalds| Clean up and return with result in fp0. 4921da177e4SLinus Torvalds| 4931da177e4SLinus Torvalds| If the final mul/div in decbin incurred an inex exception, 4941da177e4SLinus Torvalds| it will be inex2, but will be reported as inex1 by get_op. 4951da177e4SLinus Torvalds| 4961da177e4SLinus Torvaldsend_dec: 4971da177e4SLinus Torvalds fmovel %FPSR,%d0 |get status register 4981da177e4SLinus Torvalds bclrl #inex2_bit+8,%d0 |test for inex2 and clear it 4991da177e4SLinus Torvalds fmovel %d0,%FPSR |return status reg w/o inex2 5001da177e4SLinus Torvalds beqs no_exc |skip this if no exc 5011da177e4SLinus Torvalds orl #inx1a_mask,USER_FPSR(%a6) |set inex1/ainex 5021da177e4SLinus Torvaldsno_exc: 5031da177e4SLinus Torvalds moveml (%a7)+,%d2-%d5 5041da177e4SLinus Torvalds rts 5051da177e4SLinus Torvalds |end 506