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