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

Annotation of sys/arch/m68k/fpsp/sacos.sa, Revision 1.1

1.1     ! nbrk        1: *      $OpenBSD: sacos.sa,v 1.2 1996/05/29 21:05:34 niklas Exp $
        !             2: *      $NetBSD: sacos.sa,v 1.3 1994/10/26 07:49:27 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: *      sacos.sa 3.3 12/19/90
        !            36: *
        !            37: *      Description: The entry point sAcos computes the inverse cosine of
        !            38: *              an input argument; sAcosd does the same except for denormalized
        !            39: *              input.
        !            40: *
        !            41: *      Input: Double-extended number X in location pointed to
        !            42: *              by address register a0.
        !            43: *
        !            44: *      Output: The value arccos(X) returned in floating-point register Fp0.
        !            45: *
        !            46: *      Accuracy and Monotonicity: The returned result is within 3 ulps in
        !            47: *              64 significant bit, i.e. within 0.5001 ulp to 53 bits if the
        !            48: *              result is subsequently rounded to double precision. The
        !            49: *              result is provably monotonic in double precision.
        !            50: *
        !            51: *      Speed: The program sCOS takes approximately 310 cycles.
        !            52: *
        !            53: *      Algorithm:
        !            54: *
        !            55: *      ACOS
        !            56: *      1. If |X| >= 1, go to 3.
        !            57: *
        !            58: *      2. (|X| < 1) Calculate acos(X) by
        !            59: *              z := (1-X) / (1+X)
        !            60: *              acos(X) = 2 * atan( sqrt(z) ).
        !            61: *              Exit.
        !            62: *
        !            63: *      3. If |X| > 1, go to 5.
        !            64: *
        !            65: *      4. (|X| = 1) If X > 0, return 0. Otherwise, return Pi. Exit.
        !            66: *
        !            67: *      5. (|X| > 1) Generate an invalid operation by 0 * infinity.
        !            68: *              Exit.
        !            69: *
        !            70:
        !            71: SACOS  IDNT    2,1 Motorola 040 Floating Point Software Package
        !            72:
        !            73:        section 8
        !            74:
        !            75: PI     DC.L $40000000,$C90FDAA2,$2168C235,$00000000
        !            76: PIBY2  DC.L $3FFF0000,$C90FDAA2,$2168C235,$00000000
        !            77:
        !            78:        xref    t_operr
        !            79:        xref    t_frcinx
        !            80:        xref    satan
        !            81:
        !            82:        xdef    sacosd
        !            83: sacosd:
        !            84: *--ACOS(X) = PI/2 FOR DENORMALIZED X
        !            85:        fmove.l         d1,fpcr         ...load user's rounding mode/precision
        !            86:        FMOVE.X         PIBY2,FP0
        !            87:        bra             t_frcinx
        !            88:
        !            89:        xdef    sacos
        !            90: sacos:
        !            91:        FMOVE.X         (a0),FP0        ...LOAD INPUT
        !            92:
        !            93:        move.l          (a0),d0         ...pack exponent with upper 16 fraction
        !            94:        move.w          4(a0),d0
        !            95:        ANDI.L          #$7FFFFFFF,D0
        !            96:        CMPI.L          #$3FFF8000,D0
        !            97:        BGE.B           ACOSBIG
        !            98:
        !            99: *--THIS IS THE USUAL CASE, |X| < 1
        !           100: *--ACOS(X) = 2 * ATAN( SQRT( (1-X)/(1+X) )     )
        !           101:
        !           102:        FMOVE.S         #:3F800000,FP1
        !           103:        FADD.X          FP0,FP1         ...1+X
        !           104:        FNEG.X          FP0             ... -X
        !           105:        FADD.S          #:3F800000,FP0  ...1-X
        !           106:        FDIV.X          FP1,FP0         ...(1-X)/(1+X)
        !           107:        FSQRT.X         FP0             ...SQRT((1-X)/(1+X))
        !           108:        fmovem.x        fp0,(a0)        ...overwrite input
        !           109:        move.l          d1,-(sp)        ;save original users fpcr
        !           110:        clr.l           d1
        !           111:        bsr             satan           ...ATAN(SQRT([1-X]/[1+X]))
        !           112:        fMOVE.L         (sp)+,fpcr      ;restore users exceptions
        !           113:        FADD.X          FP0,FP0         ...2 * ATAN( STUFF )
        !           114:        bra             t_frcinx
        !           115:
        !           116: ACOSBIG:
        !           117:        FABS.X          FP0
        !           118:        FCMP.S          #:3F800000,FP0
        !           119:        fbgt            t_operr         ;cause an operr exception
        !           120:
        !           121: *--|X| = 1, ACOS(X) = 0 OR PI
        !           122:        move.l          (a0),d0         ...pack exponent with upper 16 fraction
        !           123:        move.w          4(a0),d0
        !           124:        TST.L           D0              ;D0 has original exponent+fraction
        !           125:        BGT.B           ACOSP1
        !           126:
        !           127: *--X = -1
        !           128: *Returns PI and inexact exception
        !           129:        FMOVE.X         PI,FP0
        !           130:        FMOVE.L         d1,FPCR
        !           131:        FADD.S          #:00800000,FP0  ;cause an inexact exception to be put
        !           132: *                                      ;into the 040 - will not trap until next
        !           133: *                                      ;fp inst.
        !           134:        bra             t_frcinx
        !           135:
        !           136: ACOSP1:
        !           137:        FMOVE.L         d1,FPCR
        !           138:        FMOVE.S         #:00000000,FP0
        !           139:        rts                             ;Facos of +1 is exact
        !           140:
        !           141:        end

CVSweb