Annotation of sys/arch/hppa/spmath/divsim.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: divsim.c,v 1.5 2002/05/07 22:19:30 mickey Exp $ */
2: /*
3: (c) Copyright 1986 HEWLETT-PACKARD COMPANY
4: To anyone who acknowledges that this file is provided "AS IS"
5: without any express or implied warranty:
6: permission to use, copy, modify, and distribute this file
7: for any purpose is hereby granted without fee, provided that
8: the above copyright notice and this notice appears in all
9: copies, and that the name of Hewlett-Packard Company not be
10: used in advertising or publicity pertaining to distribution
11: of the software without specific, written prior permission.
12: Hewlett-Packard Company makes no representations about the
13: suitability of this software for any purpose.
14: */
15: /* @(#)divsim.c: Revision: 1.6.88.1 Date: 93/12/07 15:05:56 */
16:
17: #include "md.h"
18:
19: void
20: divsim(opnd1,opnd2,result)
21: int opnd1, opnd2;
22: struct mdsfu_register *result;
23: {
24: int sign, op1_sign;
25:
26: /* check divisor for zero */
27: if (opnd2 == 0) {
28: overflow = TRUE;
29: return;
30: }
31:
32: /* get sign of result */
33: sign = opnd1 ^ opnd2;
34:
35: /* get absolute value of operands */
36: if (opnd1 < 0) {
37: opnd1 = -opnd1;
38: op1_sign = TRUE;
39: }
40: else op1_sign = FALSE;
41: if (opnd2 < 0) opnd2 = -opnd2;
42:
43: /* check for opnd2 == -2**31 */
44: if (opnd2 < 0) {
45: if (opnd1 == opnd2) {
46: result_hi = 0; /* remainder = 0 */
47: result_lo = 1;
48: }
49: else {
50: result_hi = opnd1; /* remainder = opnd1 */
51: result_lo = 0;
52: }
53: }
54: else {
55: /* do the divide */
56: divu(0,opnd1,opnd2,result);
57:
58: /*
59: * check for overflow
60: *
61: * at this point, the only way we can get overflow
62: * is with opnd1 = -2**31 and opnd2 = -1
63: */
64: if (sign>0 && result_lo<0) {
65: overflow = TRUE;
66: return;
67: }
68: }
69: overflow = FALSE;
70:
71: /* return positive residue */
72: if (op1_sign && result_hi) {
73: result_hi = opnd2 - result_hi;
74: if (++result_lo < 0) {
75: overflow = TRUE;
76: return;
77: }
78: }
79:
80: /* return appropriately signed result */
81: if (sign<0) result_lo = -result_lo;
82: return;
83: }
CVSweb