1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 #pragma ident "%Z%%M% %I% %E% SMI"
23
24 /*
25 * Copyright (c) 1986 by Sun Microsystems, Inc.
26 */
27
28 /*
29 * Machine-independent versions of base conversion primitives.
30 * Routines to multiply buffers by 2**16 or 10**4. Base 10**4 buffers have
31 * b[i] < 10000, carry in and out < 65536. Base 2**16 buffers have b[i] <
32 * 65536, carry in and out < 10000. If n is positive, b[0]..b[n-1] are
33 * processed; if n is negative, b[0]..b[n+1] are processed.
34 */
35
36 void
_fourdigits(t,d)37 _fourdigits(t, d)
38 unsigned t;
39 char d[4];
40
41 /* Converts t < 10000 into four ascii digits at *pc. */
42
43 {
44 register short i;
45
46 i = 3;
47 do {
48 d[i] = '0' + t % 10;
49 t = t / 10;
50 }
51 while (--i != -1);
52 }
53
54 unsigned
_quorem10000(u,pr)55 _quorem10000(u, pr)
56 unsigned u;
57 unsigned *pr;
58 {
59 *pr = u % 10000;
60 return (u / 10000);
61 }
62
63 void
_mul_10000(b,n,c)64 _mul_10000(b, n, c)
65 unsigned *b;
66 int n;
67 unsigned *c;
68 {
69 /* Multiply base-2**16 buffer by 10000. */
70
71 register unsigned carry, t;
72 register short int i;
73 register unsigned *pb;
74
75 carry = *c;
76 pb = b;
77 if ((i = n) > 0) {
78 i--;
79 do {
80 *pb = (t = (*pb * 10000) + carry) & 0xffff;
81 pb++;
82 carry = t >> 16;
83 }
84 while (--i != -1);
85 } else {
86 i = -i - 1;
87 do {
88 *pb = (t = (*pb * 10000) + carry) & 0xffff;
89 pb--;
90 carry = t >> 16;
91 }
92 while (--i != -1);
93 }
94 *c = carry;
95 }
96
97 void
_mul_65536(b,n,c)98 _mul_65536(b, n, c)
99 unsigned *b;
100 int n;
101 unsigned *c;
102 {
103 /* Multiply base-10**4 buffer by 65536. */
104
105 register unsigned carry, t;
106 register short int i;
107 register unsigned *pb;
108
109 carry = *c;
110 pb = b;
111 if ((i = n) > 0) {
112 i--;
113 do {
114 *pb = (t = (*pb << 16) | carry) % 10000;
115 pb++;
116 carry = t / 10000;
117 }
118 while (--i != -1);
119 } else {
120 i = -i - 1;
121 do {
122 *pb = (t = (*pb << 16) | carry) % 10000;
123 pb--;
124 carry = t / 10000;
125 }
126 while (--i != -1);
127 }
128 *c = carry;
129 }
130