8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libbc / libc / gen / common / _base_S.c
blobee7999d53967fb87d314419bff046c89d784b3a0
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
23 * Copyright 1988 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include "base_conversion.h"
31 /* Fundamental utilities for base conversion that should be recoded as assembly language subprograms or as inline expansion templates. */
33 /* Converts t < 10000 into four ascii digits at *pc. */
34 void
35 _fourdigitsquick(short unsigned t, char *d)
37 short i;
39 i = 3;
40 do {
41 d[i] = '0' + t % 10;
42 t = t / 10;
44 while (--i != -1);
47 void
48 _multiply_base_two_vector(short unsigned n, _BIG_FLOAT_DIGIT *px,
49 short unsigned *py, _BIG_FLOAT_DIGIT product[3])
52 * Given xi and yi, base 2**16 vectors of length n, computes dot
53 * product
55 * sum (i=0,n-1) of x[i]*y[n-1-i]
57 * Product may fill as many as three short-unsigned buckets. Product[0]
58 * is least significant, product[2] most.
61 unsigned long acc, p;
62 short unsigned carry;
63 int i;
65 acc = 0;
66 carry = 0;
67 for (i = 0; i < n; i++) {
68 p=_umac(px[i],py[n - 1 - i],acc);
69 if (p < acc)
70 carry++;
71 acc = p;
73 product[0] = (_BIG_FLOAT_DIGIT) (acc & 0xffff);
74 product[1] = (_BIG_FLOAT_DIGIT) (acc >> 16);
75 product[2] = (_BIG_FLOAT_DIGIT) (carry);
78 void
79 _multiply_base_ten_vector(short unsigned n, _BIG_FLOAT_DIGIT *px,
80 short unsigned *py, _BIG_FLOAT_DIGIT product[3])
83 * Given xi and yi, base 10**4 vectors of length n, computes dot
84 * product
86 * sum (i=0,n-1) of x[i]*y[n-1-i]
88 * Product may fill as many as three short-unsigned buckets. Product[0]
89 * is least significant, product[2] most.
92 #define ABASE 3000000000U /* Base of accumulator. */
94 unsigned long acc;
95 short unsigned carry;
96 int i;
98 acc = 0;
99 carry = 0;
100 for (i = 0; i < n; i++) {
101 acc=_umac(px[i],py[n - 1 - i],acc);
102 if (acc >= (unsigned long) ABASE) {
103 carry++;
104 acc -= ABASE;
108 NOTE: because
109 acc * <= ABASE-1,
110 acc/10000 <= 299999
111 which would overflow a short unsigned
113 product[0] = (_BIG_FLOAT_DIGIT) (acc % 10000);
114 acc /= 10000;
115 product[1] = (_BIG_FLOAT_DIGIT) (acc % 10000);
116 acc /= 10000;
117 product[2] = (_BIG_FLOAT_DIGIT) (acc + (ABASE / 100000000) * carry);