|
|
1.1 ! root 1: /* $NetBSD: fpu_int.c,v 1.12 2013/03/19 09:17:17 isaki Exp $ */ ! 2: ! 3: /* ! 4: * Copyright (c) 1995 Ken Nakata ! 5: * All rights reserved. ! 6: * ! 7: * Redistribution and use in source and binary forms, with or without ! 8: * modification, are permitted provided that the following conditions ! 9: * are met: ! 10: * 1. Redistributions of source code must retain the above copyright ! 11: * notice, this list of conditions and the following disclaimer. ! 12: * 2. Redistributions in binary form must reproduce the above copyright ! 13: * notice, this list of conditions and the following disclaimer in the ! 14: * documentation and/or other materials provided with the distribution. ! 15: * ! 16: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ! 17: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ! 18: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ! 19: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE ! 20: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ! 21: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ! 22: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ! 23: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT ! 24: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ! 25: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ! 26: * SUCH DAMAGE. ! 27: * ! 28: * @(#)fpu_int.c ! 29: */ ! 30: ! 31: #include "fpu_arith.h" ! 32: #include "fpu_emulate.h" ! 33: ! 34: /* FINTRZ - always round to zero */ ! 35: struct fpn * ! 36: fpu_intrz(struct fpemu *fe) ! 37: { ! 38: struct fpn *x = &fe->fe_f2; ! 39: int sh, clr, mask, i; ! 40: uint32_t mant[3]; ! 41: ! 42: /* special cases first */ ! 43: if (x->fp_class != FPC_NUM) { ! 44: return x; ! 45: } ! 46: /* when |x| < 1.0 */ ! 47: if (x->fp_exp < 0) { ! 48: x->fp_class = FPC_ZERO; ! 49: x->fp_mant[0] = x->fp_mant[1] = x->fp_mant[2] = 0; ! 50: fe->fe_fpsr |= FPSR_INEX2; ! 51: return x; ! 52: } ! 53: ! 54: /* real work */ ! 55: sh = FP_NMANT - 1 - x->fp_exp; ! 56: if (sh <= 0) { ! 57: return x; ! 58: } ! 59: ! 60: clr = 2 - sh / 32; ! 61: mask = (0xffffffff << (sh % 32)); ! 62: ! 63: /* save */ ! 64: for (i = 0; i < 3; i++) { ! 65: mant[i] = x->fp_mant[i]; ! 66: } ! 67: ! 68: for (i = 2; i > clr; i--) { ! 69: x->fp_mant[i] = 0; ! 70: } ! 71: x->fp_mant[i] &= mask; ! 72: ! 73: /* check INEX2 */ ! 74: for (i = 0; i < 3; i++) { ! 75: if (x->fp_mant[i] != mant[i]) { ! 76: fe->fe_fpsr |= FPSR_INEX2; ! 77: } ! 78: } ! 79: ! 80: return x; ! 81: } ! 82: ! 83: /* FINT */ ! 84: struct fpn * ! 85: fpu_int(struct fpemu *fe) ! 86: { ! 87: struct fpn *x = &fe->fe_f2; ! 88: int rsh; ! 89: ! 90: /* special cases first */ ! 91: if (x->fp_class != FPC_NUM) { ! 92: return x; ! 93: } ! 94: ! 95: rsh = FP_NMANT - 1 - x->fp_exp; ! 96: if (rsh <= FP_NG) { ! 97: return x; ! 98: } ! 99: ! 100: /* shift to the right */ ! 101: x->fp_exp = 0; ! 102: fpu_shr(x, rsh - FP_NG); ! 103: ! 104: /* round according to FPCR round mode */ ! 105: fpu_round(fe, x); ! 106: ! 107: /* shift it back to the left */ ! 108: x->fp_exp = FP_NMANT - 1; ! 109: fpu_norm(x); ! 110: ! 111: return x; ! 112: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.