Print this page
10097 indenting fixes in usr/src/{lib,common}
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libmp/common/mdiv.c
+++ new/usr/src/lib/libmp/common/mdiv.c
1 1 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
2 2 /* All Rights Reserved */
3 3
4 4
5 5 /*
6 6 * Copyright (c) 1980 Regents of the University of California.
7 7 * All rights reserved. The Berkeley software License Agreement
↓ open down ↓ |
7 lines elided |
↑ open up ↑ |
8 8 * specifies the terms and conditions for redistribution.
9 9 */
10 10 /* Portions Copyright(c) 1988, Sun Microsystems Inc. */
11 11 /* All Rights Reserved */
12 12
13 13 /*
14 14 * Copyright (c) 1997, by Sun Microsystems, Inc.
15 15 * All rights reserved.
16 16 */
17 17
18 -#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
18 +/*
19 + * Copyright (c) 2018, Joyent, Inc.
20 + */
19 21
20 22 /* LINTLIBRARY */
21 23
22 24 #include <mp.h>
23 25 #include <stdio.h>
24 26 #include <stdlib.h>
25 27 #include <sys/types.h>
26 28 #include "libmp.h"
27 29
28 30 static void m_div(MINT *, MINT *, MINT *, MINT *);
29 31
30 32 void
31 33 mp_mdiv(MINT *a, MINT *b, MINT *q, MINT *r)
32 34 {
33 35 MINT x, y;
34 36 int sign;
35 37
36 38 sign = 1;
37 39 x.len = y.len = 0;
38 40 _mp_move(a, &x);
39 41 _mp_move(b, &y);
40 42 if (x.len < 0) {
41 43 sign = -1;
42 44 x.len = -x.len;
43 45 }
44 46 if (y.len < 0) {
45 47 sign = -sign;
46 48 y.len = -y.len;
47 49 }
48 50 _mp_xfree(q);
49 51 _mp_xfree(r);
50 52 m_div(&x, &y, q, r);
51 53 if (sign == -1) {
52 54 q->len = -q->len;
53 55 r->len = -r->len;
54 56 }
55 57 _mp_xfree(&x);
56 58 _mp_xfree(&y);
57 59 }
58 60
59 61 static int
60 62 m_dsb(int qx, int n, short *a, short *b)
61 63 {
62 64 int borrow;
63 65 int s3b2shit;
64 66 int j;
65 67 short fifteen = 15;
66 68 short *aptr, *bptr;
67 69 #ifdef DEBUGDSB
68 70 (void) printf("m_dsb %d %d %d %d\n", qx, n, *a, *b);
69 71 #endif
70 72
71 73 borrow = 0;
72 74 aptr = a;
73 75 bptr = b;
74 76 for (j = n; j > 0; j--) {
75 77 #ifdef DEBUGDSB
76 78 (void) printf("1 borrow=%x %d %d %d\n", borrow, (*aptr * qx),
77 79 *bptr, *aptr);
78 80 #endif
79 81 borrow -= (*aptr++) * qx - *bptr;
80 82 #ifdef DEBUGDSB
81 83 (void) printf("2 borrow=%x %d %d %d\n", borrow, (*aptr * qx),
82 84 *bptr, *aptr);
83 85 #endif
84 86 *bptr++ = (short)(borrow & 077777);
85 87 #ifdef DEBUGDSB
86 88 (void) printf("3 borrow=%x %d %d %d\n", borrow, (*aptr * qx),
87 89 *bptr, *aptr);
↓ open down ↓ |
59 lines elided |
↑ open up ↑ |
88 90 #endif
89 91 if (borrow >= 0) borrow >>= fifteen; /* 3b2 */
90 92 else borrow = 0xfffe0000 | (borrow >> fifteen);
91 93 #ifdef DEBUGDSB
92 94 (void) printf("4 borrow=%x %d %d %d\n", borrow, (*aptr * qx),
93 95 *bptr, *aptr);
94 96 #endif
95 97 }
96 98 borrow += *bptr;
97 99 *bptr = (short)(borrow & 077777);
98 - if (borrow >= 0) s3b2shit = borrow >> fifteen; /* 3b2 */
99 - else s3b2shit = 0xfffe0000 | (borrow >> fifteen);
100 + if (borrow >= 0) s3b2shit = borrow >> fifteen; /* 3b2 */
101 + else s3b2shit = 0xfffe0000 | (borrow >> fifteen);
100 102 if (s3b2shit == 0) {
101 103 #ifdef DEBUGDSB
102 104 (void) printf("mdsb 0\n");
103 105 #endif
104 106 return (0);
105 107 }
106 108 borrow = 0;
107 109 aptr = a;
108 110 bptr = b;
109 111 for (j = n; j > 0; j--) {
110 112 borrow += *aptr++ + *bptr;
111 113 *bptr++ = (short)(borrow & 077777);
112 114 if (borrow >= 0) borrow >>= fifteen; /* 3b2 */
113 115 else borrow = 0xfffe0000 | (borrow >>fifteen);
114 116 }
115 117 #ifdef DEBUGDSB
116 118 (void) printf("mdsb 1\n");
117 119 #endif
118 120 return (1);
119 121 }
120 122
121 123 static int
122 124 m_trq(short v1, short v2, short u1, short u2, short u3)
123 125 {
124 126 short d;
125 127 int x1;
126 128 int c1;
127 129
128 130 c1 = u1 * 0100000 + u2;
129 131 if (u1 == v1) {
130 132 d = 077777;
131 133 } else {
132 134 d = (short)(c1 / v1);
133 135 }
134 136 do {
135 137 x1 = c1 - v1 * d;
136 138 x1 = x1 * 0100000 + u3 - v2 * d;
137 139 --d;
138 140 } while (x1 < 0);
139 141 #ifdef DEBUGMTRQ
140 142 (void) printf("mtrq %d %d %d %d %d %d\n", v1, v2, u1, u2, u3, (d+1));
141 143 #endif
142 144 return ((int)d + 1);
143 145 }
144 146
145 147 static void
146 148 m_div(MINT *a, MINT *b, MINT *q, MINT *r)
147 149 {
148 150 MINT u, v, x, w;
149 151 short d;
150 152 short *qval;
151 153 short *uval;
152 154 int j;
153 155 int qq;
154 156 int n;
155 157 short v1;
156 158 short v2;
157 159
158 160 u.len = v.len = x.len = w.len = 0;
159 161 if (b->len == 0) {
160 162 _mp_fatal("mdiv divide by zero");
161 163 return;
162 164 }
163 165 if (b->len == 1) {
164 166 r->val = _mp_xalloc(1, "m_div1");
165 167 mp_sdiv(a, b->val[0], q, r->val);
166 168 if (r->val[0] == 0) {
167 169 free(r->val);
168 170 r->len = 0;
169 171 } else {
170 172 r->len = 1;
171 173 }
172 174 return;
173 175 }
174 176 if (a -> len < b -> len) {
175 177 q->len = 0;
176 178 r->len = a->len;
177 179 r->val = _mp_xalloc(r->len, "m_div2");
178 180 for (qq = 0; qq < r->len; qq++) {
179 181 r->val[qq] = a->val[qq];
180 182 }
181 183 return;
182 184 }
183 185 x.len = 1;
184 186 x.val = &d;
185 187 n = b->len;
186 188 d = 0100000 / (b->val[n - 1] + 1);
187 189 mp_mult(a, &x, &u); /* subtle: relies on mult allocing extra space */
188 190 mp_mult(b, &x, &v);
189 191 #ifdef DEBUG_MDIV
190 192 (void) printf(" u=%s\n", mtox(&u));
191 193 (void) printf(" v=%s\n", mtox(&v));
192 194 #endif
193 195 v1 = v.val[n - 1];
194 196 v2 = v.val[n - 2];
195 197 qval = _mp_xalloc(a -> len - n + 1, "m_div3");
196 198 uval = u.val;
197 199 for (j = a->len - n; j >= 0; j--) {
198 200 qq = m_trq(v1, v2, uval[j + n], uval[j + n - 1],
199 201 uval[j + n - 2]);
200 202 if (m_dsb(qq, n, v.val, uval + j))
201 203 qq -= 1;
202 204 qval[j] = (short)qq;
203 205 }
204 206 x.len = n;
205 207 x.val = u.val;
206 208 _mp_mcan(&x);
207 209 #ifdef DEBUG_MDIV
208 210 (void) printf(" x=%s\n", mtox(&x));
209 211 (void) printf(" d(in)=%d\n", (d));
210 212 #endif
211 213 mp_sdiv(&x, d, &w, &d);
212 214 #ifdef DEBUG_MDIV
213 215 (void) printf(" w=%s\n", mtox(&w));
214 216 (void) printf(" d(out)=%d\n", (d));
215 217 #endif
216 218 r->len = w.len;
217 219 r->val = w.val;
218 220 q->val = qval;
219 221 qq = a->len - n + 1;
220 222 if (qq > 0 && qval[qq - 1] == 0)
221 223 qq -= 1;
222 224 q->len = qq;
223 225 if (qq == 0)
224 226 free(qval);
225 227 if (x.len != 0)
226 228 _mp_xfree(&u);
227 229 _mp_xfree(&v);
228 230 }
↓ open down ↓ |
119 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX