|
|
1.1 ! root 1: /* $NetBSD$ */ ! 2: ! 3: /* ! 4: * Copyright (C) 2019 Y.Sugahara (moveccr). All rights reserved. ! 5: * ! 6: * Redistribution and use in source and binary forms, with or without ! 7: * modification, are permitted provided that the following conditions ! 8: * are met: ! 9: * 1. Redistributions of source code must retain the above copyright ! 10: * notice, this list of conditions and the following disclaimer. ! 11: * 2. Redistributions in binary form must reproduce the above copyright ! 12: * notice, this list of conditions and the following disclaimer in the ! 13: * documentation and/or other materials provided with the distribution. ! 14: * ! 15: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR ! 16: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES ! 17: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ! 18: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, ! 19: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, ! 20: * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; ! 21: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED ! 22: * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ! 23: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ! 24: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ! 25: * SUCH DAMAGE. ! 26: */ ! 27: ! 28: #include "fpu_emulate.h" ! 29: ! 30: struct fpn * ! 31: fpu_cmp(struct fpemu *fe) ! 32: { ! 33: struct fpn *x = &fe->fe_f1, *y = &fe->fe_f2; ! 34: int N; ! 35: int Z; ! 36: ! 37: N = x->fp_sign; ! 38: Z = 0; ! 39: ! 40: if (ISNAN(x)) { ! 41: return x; ! 42: } else if (ISNAN(y)) { ! 43: return y; ! 44: } else if (ISINF(x)) { ! 45: /* dst:INF src:NUM,ZERO,INF */ ! 46: Z = ISINF(y) && (x->fp_sign == y->fp_sign); ! 47: } else if (ISINF(y)) { ! 48: /* dst:NUM,ZERO src:INF */ ! 49: N = !y->fp_sign; ! 50: } else if (ISZERO(x)) { ! 51: /* dst:ZERO src:NUM,ZERO */ ! 52: if (ISZERO(y)) { ! 53: Z = 1; ! 54: } else { ! 55: N = !y->fp_sign; ! 56: } ! 57: } else if (ISZERO(y)) { ! 58: /* dst:NUM src:ZERO */ ! 59: /* nop. done by initial */ ! 60: } else { ! 61: /* dst:NUM src:NUM */ ! 62: if (x->fp_sign != y->fp_sign) { ! 63: /* dst:+ src:- or dst:- src:+ */ ! 64: /* nop. done by initial */ ! 65: } else { ! 66: /* dst:+ src:+ or dst:- src:- */ ! 67: if (x->fp_exp > y->fp_exp) { ! 68: /* nop. done by initial */ ! 69: } else if (x->fp_exp < y->fp_exp) { ! 70: N = !N; ! 71: } else { ! 72: /* if block when nop, done by initial */ ! 73: if (x->fp_mant[0] > y->fp_mant[0]) { ! 74: } else if (x->fp_mant[0] < y->fp_mant[0]) { ! 75: N = !N; ! 76: } else if (x->fp_mant[1] > y->fp_mant[1]) { ! 77: } else if (x->fp_mant[1] < y->fp_mant[1]) { ! 78: N = !N; ! 79: } else if (x->fp_mant[2] > y->fp_mant[2]) { ! 80: } else if (x->fp_mant[2] < y->fp_mant[2]) { ! 81: N = !N; ! 82: } else { ! 83: Z = 1; ! 84: } ! 85: } ! 86: } ! 87: } ! 88: if (Z) { ! 89: x->fp_class = FPC_ZERO; ! 90: } else { ! 91: /* Any non-zero value */ ! 92: x->fp_class = FPC_NUM; ! 93: x->fp_exp = 0; ! 94: x->fp_mant[0] = FP_1; ! 95: x->fp_mant[1] = 0; ! 96: x->fp_mant[2] = 0; ! 97: } ! 98: x->fp_sign = N; ! 99: ! 100: return x; ! 101: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.