[BACK]Return to fpu_int.c CVS log [TXT][DIR] Up to [local] / sys / arch / m68k / fpe

Annotation of sys/arch/m68k/fpe/fpu_int.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: fpu_int.c,v 1.4 2006/06/11 20:43:28 miod Exp $        */
        !             2: /*     $NetBSD: fpu_int.c,v 1.6 2003/07/15 02:43:10 lukem Exp $        */
        !             3:
        !             4: /*
        !             5:  * Copyright (c) 1995 Ken Nakata
        !             6:  * All rights reserved.
        !             7:  *
        !             8:  * Redistribution and use in source and binary forms, with or without
        !             9:  * modification, are permitted provided that the following conditions
        !            10:  * are met:
        !            11:  * 1. Redistributions of source code must retain the above copyright
        !            12:  *    notice, this list of conditions and the following disclaimer.
        !            13:  * 2. Redistributions in binary form must reproduce the above copyright
        !            14:  *    notice, this list of conditions and the following disclaimer in the
        !            15:  *    documentation and/or other materials provided with the distribution.
        !            16:  *
        !            17:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
        !            18:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            19:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            20:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
        !            21:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            22:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            23:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            24:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            25:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            26:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            27:  * SUCH DAMAGE.
        !            28:  *
        !            29:  *     @(#)fpu_int.c
        !            30:  */
        !            31:
        !            32: #include <sys/types.h>
        !            33:
        !            34: #include <machine/reg.h>
        !            35:
        !            36: #include <m68k/fpe/fpu_arith.h>
        !            37: #include <m68k/fpe/fpu_emulate.h>
        !            38:
        !            39: /* FINTRZ - always round to zero */
        !            40: struct fpn *
        !            41: fpu_intrz(fe)
        !            42:      struct fpemu *fe;
        !            43: {
        !            44:   struct fpn *x = &fe->fe_f2;
        !            45:   int sh, clr, mask, i;
        !            46:
        !            47:   /* special cases first */
        !            48:   if (x->fp_class != FPC_NUM) {
        !            49:     return x;
        !            50:   }
        !            51:   /* when |x| < 1.0 */
        !            52:   if (x->fp_exp < 0) {
        !            53:     x->fp_class = FPC_ZERO;
        !            54:     x->fp_mant[0] = x->fp_mant[1] = x->fp_mant[2] = 0;
        !            55:     return x;
        !            56:   }
        !            57:
        !            58:   /* real work */
        !            59:   sh = FP_NMANT - 1 - x->fp_exp;
        !            60:   if (sh <= 0) {
        !            61:     return x;
        !            62:   }
        !            63:
        !            64:   clr = 2 - sh / 32;
        !            65:   mask = (0xffffffff << (sh % 32));
        !            66:
        !            67:   for (i = 2; i > clr; i--) {
        !            68:     x->fp_mant[i] = 0;
        !            69:   }
        !            70:   x->fp_mant[i] &= mask;
        !            71:
        !            72:   return x;
        !            73: }
        !            74:
        !            75: /* FINT */
        !            76: struct fpn *
        !            77: fpu_int(fe)
        !            78:      struct fpemu *fe;
        !            79: {
        !            80:   struct fpn *x = &fe->fe_f2;
        !            81:   int rsh, lsh, wsh, i;
        !            82:
        !            83:   /* special cases first */
        !            84:   if (x->fp_class != FPC_NUM) {
        !            85:     return x;
        !            86:   }
        !            87:   /* even if we have exponent == -1, we still have possiblity
        !            88:      that the result >= 1.0 when mantissa ~= 1.0 and rounded up */
        !            89:   if (x->fp_exp < -1) {
        !            90:     x->fp_class = FPC_ZERO;
        !            91:     x->fp_mant[0] = x->fp_mant[1] = x->fp_mant[2] = 0;
        !            92:     return x;
        !            93:   }
        !            94:
        !            95:   /* real work */
        !            96:   rsh = FP_NMANT - 1 - x->fp_exp;
        !            97:   if (rsh - FP_NG <= 0) {
        !            98:     return x;
        !            99:   }
        !           100:
        !           101:   fpu_shr(x, rsh - FP_NG);     /* shift to the right */
        !           102:
        !           103:   if (fpu_round(fe, x) == 1 /* rounded up */ &&
        !           104:       x->fp_mant[2 - (FP_NMANT-rsh)/32] & (1 << ((FP_NMANT-rsh)%32))
        !           105:       /* x >= 2.0 */) {
        !           106:     rsh--;                     /* reduce shift count by 1 */
        !           107:     x->fp_exp++;               /* adjust exponent */
        !           108:   }
        !           109:
        !           110:   /* shift it back to the left */
        !           111:   wsh = rsh / 32;
        !           112:   lsh = rsh % 32;
        !           113:   rsh = 32 - lsh;
        !           114:   for (i = 0; i + wsh < 2; i++) {
        !           115:     x->fp_mant[i] = (x->fp_mant[i+wsh] << lsh) | (x->fp_mant[i+wsh+1] >> rsh);
        !           116:   }
        !           117:   x->fp_mant[i] = (x->fp_mant[i+wsh] << lsh);
        !           118:   i++;
        !           119:   for (; i < 3; i++) {
        !           120:     x->fp_mant[i] = 0;
        !           121:   }
        !           122:
        !           123:   return x;
        !           124: }

CVSweb