8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libbc / libc / gen / common / sparc / base_conv.c
blob405b0ab99a25a73bf335db722908900b27083727
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
22 #pragma ident "%Z%%M% %I% %E% SMI"
25 * Copyright (c) 1986 by Sun Microsystems, Inc.
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.
36 void
37 _fourdigits(t, d)
38 unsigned t;
39 char d[4];
41 /* Converts t < 10000 into four ascii digits at *pc. */
44 register short i;
46 i = 3;
47 do {
48 d[i] = '0' + t % 10;
49 t = t / 10;
51 while (--i != -1);
54 unsigned
55 _quorem10000(u, pr)
56 unsigned u;
57 unsigned *pr;
59 *pr = u % 10000;
60 return (u / 10000);
63 void
64 _mul_10000(b, n, c)
65 unsigned *b;
66 int n;
67 unsigned *c;
69 /* Multiply base-2**16 buffer by 10000. */
71 register unsigned carry, t;
72 register short int i;
73 register unsigned *pb;
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;
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;
92 while (--i != -1);
94 *c = carry;
97 void
98 _mul_65536(b, n, c)
99 unsigned *b;
100 int n;
101 unsigned *c;
103 /* Multiply base-10**4 buffer by 65536. */
105 register unsigned carry, t;
106 register short int i;
107 register unsigned *pb;
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;
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;
126 while (--i != -1);
128 *c = carry;