[BACK]Return to binstr.sa CVS log [TXT][DIR] Up to [local] / sys / arch / m68k / fpsp

Annotation of sys/arch/m68k/fpsp/binstr.sa, Revision 1.1.1.1

1.1       nbrk        1: *      $OpenBSD: binstr.sa,v 1.2 1996/05/29 21:05:25 niklas Exp $
                      2: *      $NetBSD: binstr.sa,v 1.3 1994/10/26 07:48:53 cgd Exp $
                      3:
                      4: *      MOTOROLA MICROPROCESSOR & MEMORY TECHNOLOGY GROUP
                      5: *      M68000 Hi-Performance Microprocessor Division
                      6: *      M68040 Software Package
                      7: *
                      8: *      M68040 Software Package Copyright (c) 1993, 1994 Motorola Inc.
                      9: *      All rights reserved.
                     10: *
                     11: *      THE SOFTWARE is provided on an "AS IS" basis and without warranty.
                     12: *      To the maximum extent permitted by applicable law,
                     13: *      MOTOROLA DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED,
                     14: *      INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
                     15: *      PARTICULAR PURPOSE and any warranty against infringement with
                     16: *      regard to the SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF)
                     17: *      and any accompanying written materials.
                     18: *
                     19: *      To the maximum extent permitted by applicable law,
                     20: *      IN NO EVENT SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER
                     21: *      (INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS
                     22: *      PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR
                     23: *      OTHER PECUNIARY LOSS) ARISING OF THE USE OR INABILITY TO USE THE
                     24: *      SOFTWARE.  Motorola assumes no responsibility for the maintenance
                     25: *      and support of the SOFTWARE.
                     26: *
                     27: *      You are hereby granted a copyright license to use, modify, and
                     28: *      distribute the SOFTWARE so long as this entire notice is retained
                     29: *      without alteration in any modified and/or redistributed versions,
                     30: *      and that such modified versions are clearly identified as such.
                     31: *      No licenses are granted by implication, estoppel or otherwise
                     32: *      under any patents or trademarks of Motorola, Inc.
                     33:
                     34: *
                     35: *      binstr.sa 3.3 12/19/90
                     36: *
                     37: *
                     38: *      Description: Converts a 64-bit binary integer to bcd.
                     39: *
                     40: *      Input: 64-bit binary integer in d2:d3, desired length (LEN) in
                     41: *          d0, and a  pointer to start in memory for bcd characters
                     42: *          in d0. (This pointer must point to byte 4 of the first
                     43: *          lword of the packed decimal memory string.)
                     44: *
                     45: *      Output: LEN bcd digits representing the 64-bit integer.
                     46: *
                     47: *      Algorithm:
                     48: *              The 64-bit binary is assumed to have a decimal point before
                     49: *              bit 63.  The fraction is multiplied by 10 using a mul by 2
                     50: *              shift and a mul by 8 shift.  The bits shifted out of the
                     51: *              msb form a decimal digit.  This process is iterated until
                     52: *              LEN digits are formed.
                     53: *
                     54: *      A1. Init d7 to 1.  D7 is the byte digit counter, and if 1, the
                     55: *              digit formed will be assumed the least significant.  This is
                     56: *              to force the first byte formed to have a 0 in the upper 4 bits.
                     57: *
                     58: *      A2. Beginning of the loop:
                     59: *              Copy the fraction in d2:d3 to d4:d5.
                     60: *
                     61: *      A3. Multiply the fraction in d2:d3 by 8 using bit-field
                     62: *              extracts and shifts.  The three msbs from d2 will go into
                     63: *              d1.
                     64: *
                     65: *      A4. Multiply the fraction in d4:d5 by 2 using shifts.  The msb
                     66: *              will be collected by the carry.
                     67: *
                     68: *      A5. Add using the carry the 64-bit quantities in d2:d3 and d4:d5
                     69: *              into d2:d3.  D1 will contain the bcd digit formed.
                     70: *
                     71: *      A6. Test d7.  If zero, the digit formed is the ms digit.  If non-
                     72: *              zero, it is the ls digit.  Put the digit in its place in the
                     73: *              upper word of d0.  If it is the ls digit, write the word
                     74: *              from d0 to memory.
                     75: *
                     76: *      A7. Decrement d6 (LEN counter) and repeat the loop until zero.
                     77: *
                     78: *      Implementation Notes:
                     79: *
                     80: *      The registers are used as follows:
                     81: *
                     82: *              d0: LEN counter
                     83: *              d1: temp used to form the digit
                     84: *              d2: upper 32-bits of fraction for mul by 8
                     85: *              d3: lower 32-bits of fraction for mul by 8
                     86: *              d4: upper 32-bits of fraction for mul by 2
                     87: *              d5: lower 32-bits of fraction for mul by 2
                     88: *              d6: temp for bit-field extracts
                     89: *              d7: byte digit formation word;digit count {0,1}
                     90: *              a0: pointer into memory for packed bcd string formation
                     91: *
                     92:
                     93: BINSTR    IDNT    2,1 Motorola 040 Floating Point Software Package
                     94:
                     95:        section 8
                     96:
                     97:        include fpsp.h
                     98:
                     99:        xdef    binstr
                    100: binstr:
                    101:        movem.l d0-d7,-(a7)
                    102: *
                    103: * A1: Init d7
                    104: *
                    105:        moveq.l #1,d7                   ;init d7 for second digit
                    106:        subq.l  #1,d0                   ;for dbf d0 would have LEN+1 passes
                    107: *
                    108: * A2. Copy d2:d3 to d4:d5.  Start loop.
                    109: *
                    110: loop:
                    111:        move.l  d2,d4                   ;copy the fraction before muls
                    112:        move.l  d3,d5                   ;to d4:d5
                    113: *
                    114: * A3. Multiply d2:d3 by 8; extract msbs into d1.
                    115: *
                    116:        bfextu  d2{0:3},d1              ;copy 3 msbs of d2 into d1
                    117:        asl.l   #3,d2                   ;shift d2 left by 3 places
                    118:        bfextu  d3{0:3},d6              ;copy 3 msbs of d3 into d6
                    119:        asl.l   #3,d3                   ;shift d3 left by 3 places
                    120:        or.l    d6,d2                   ;or in msbs from d3 into d2
                    121: *
                    122: * A4. Multiply d4:d5 by 2; add carry out to d1.
                    123: *
                    124:        add.l   d5,d5                   ;mul d5 by 2
                    125:        addx.l  d4,d4                   ;mul d4 by 2
                    126:        swap    d6                      ;put 0 in d6 lower word
                    127:        addx.w  d6,d1                   ;add in extend from mul by 2
                    128: *
                    129: * A5. Add mul by 8 to mul by 2.  D1 contains the digit formed.
                    130: *
                    131:        add.l   d5,d3                   ;add lower 32 bits
                    132:        nop                             ;ERRATA FIX #13 (Rev. 1.2 6/6/90)
                    133:        addx.l  d4,d2                   ;add with extend upper 32 bits
                    134:        nop                             ;ERRATA FIX #13 (Rev. 1.2 6/6/90)
                    135:        addx.w  d6,d1                   ;add in extend from add to d1
                    136:        swap    d6                      ;with d6 = 0; put 0 in upper word
                    137: *
                    138: * A6. Test d7 and branch.
                    139: *
                    140:        tst.w   d7                      ;if zero, store digit & to loop
                    141:        beq.b   first_d                 ;if non-zero, form byte & write
                    142: sec_d:
                    143:        swap    d7                      ;bring first digit to word d7b
                    144:        asl.w   #4,d7                   ;first digit in upper 4 bits d7b
                    145:        add.w   d1,d7                   ;add in ls digit to d7b
                    146:        move.b  d7,(a0)+                ;store d7b byte in memory
                    147:        swap    d7                      ;put LEN counter in word d7a
                    148:        clr.w   d7                      ;set d7a to signal no digits done
                    149:        dbf.w   d0,loop                 ;do loop some more!
                    150:        bra.b   end_bstr                ;finished, so exit
                    151: first_d:
                    152:        swap    d7                      ;put digit word in d7b
                    153:        move.w  d1,d7                   ;put new digit in d7b
                    154:        swap    d7                      ;put LEN counter in word d7a
                    155:        addq.w  #1,d7                   ;set d7a to signal first digit done
                    156:        dbf.w   d0,loop                 ;do loop some more!
                    157:        swap    d7                      ;put last digit in string
                    158:        lsl.w   #4,d7                   ;move it to upper 4 bits
                    159:        move.b  d7,(a0)+                ;store it in memory string
                    160: *
                    161: * Clean up and return with result in fp0.
                    162: *
                    163: end_bstr:
                    164:        movem.l (a7)+,d0-d7
                    165:        rts
                    166:        end

CVSweb