1f9f848faSopenharmony_ci/****************************************************************
2f9f848faSopenharmony_ci
3f9f848faSopenharmony_ciThe author of this software is David M. Gay.
4f9f848faSopenharmony_ci
5f9f848faSopenharmony_ciCopyright (C) 1998 by Lucent Technologies
6f9f848faSopenharmony_ciAll Rights Reserved
7f9f848faSopenharmony_ci
8f9f848faSopenharmony_ciPermission to use, copy, modify, and distribute this software and
9f9f848faSopenharmony_ciits documentation for any purpose and without fee is hereby
10f9f848faSopenharmony_cigranted, provided that the above copyright notice appear in all
11f9f848faSopenharmony_cicopies and that both that the copyright notice and this
12f9f848faSopenharmony_cipermission notice and warranty disclaimer appear in supporting
13f9f848faSopenharmony_cidocumentation, and that the name of Lucent or any of its entities
14f9f848faSopenharmony_cinot be used in advertising or publicity pertaining to
15f9f848faSopenharmony_cidistribution of the software without specific, written prior
16f9f848faSopenharmony_cipermission.
17f9f848faSopenharmony_ci
18f9f848faSopenharmony_ciLUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19f9f848faSopenharmony_ciINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
20f9f848faSopenharmony_ciIN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
21f9f848faSopenharmony_ciSPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22f9f848faSopenharmony_ciWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
23f9f848faSopenharmony_ciIN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
24f9f848faSopenharmony_ciARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
25f9f848faSopenharmony_ciTHIS SOFTWARE.
26f9f848faSopenharmony_ci
27f9f848faSopenharmony_ci****************************************************************/
28f9f848faSopenharmony_ci
29f9f848faSopenharmony_ci/* Please send bug reports to David M. Gay (dmg at acm dot org,
30f9f848faSopenharmony_ci * with " at " changed at "@" and " dot " changed to ".").	*/
31f9f848faSopenharmony_ci
32f9f848faSopenharmony_ci#include "gdtoaimp.h"
33f9f848faSopenharmony_ci
34f9f848faSopenharmony_ci void
35f9f848faSopenharmony_ci#ifdef KR_headers
36f9f848faSopenharmony_cirshift(b, k) Bigint *b; int k;
37f9f848faSopenharmony_ci#else
38f9f848faSopenharmony_cirshift(Bigint *b, int k)
39f9f848faSopenharmony_ci#endif
40f9f848faSopenharmony_ci{
41f9f848faSopenharmony_ci	ULong *x, *x1, *xe, y;
42f9f848faSopenharmony_ci	int n;
43f9f848faSopenharmony_ci
44f9f848faSopenharmony_ci	x = x1 = b->x;
45f9f848faSopenharmony_ci	n = k >> kshift;
46f9f848faSopenharmony_ci	if (n < b->wds) {
47f9f848faSopenharmony_ci		xe = x + b->wds;
48f9f848faSopenharmony_ci		x += n;
49f9f848faSopenharmony_ci		if (k &= kmask) {
50f9f848faSopenharmony_ci			n = ULbits - k;
51f9f848faSopenharmony_ci			y = *x++ >> k;
52f9f848faSopenharmony_ci			while(x < xe) {
53f9f848faSopenharmony_ci				*x1++ = (y | (*x << n)) & ALL_ON;
54f9f848faSopenharmony_ci				y = *x++ >> k;
55f9f848faSopenharmony_ci				}
56f9f848faSopenharmony_ci			if ((*x1 = y) !=0)
57f9f848faSopenharmony_ci				x1++;
58f9f848faSopenharmony_ci			}
59f9f848faSopenharmony_ci		else
60f9f848faSopenharmony_ci			while(x < xe)
61f9f848faSopenharmony_ci				*x1++ = *x++;
62f9f848faSopenharmony_ci		}
63f9f848faSopenharmony_ci	if ((b->wds = x1 - b->x) == 0)
64f9f848faSopenharmony_ci		b->x[0] = 0;
65f9f848faSopenharmony_ci	}
66f9f848faSopenharmony_ci
67f9f848faSopenharmony_ci int
68f9f848faSopenharmony_ci#ifdef KR_headers
69f9f848faSopenharmony_citrailz(b) Bigint *b;
70f9f848faSopenharmony_ci#else
71f9f848faSopenharmony_citrailz(Bigint *b)
72f9f848faSopenharmony_ci#endif
73f9f848faSopenharmony_ci{
74f9f848faSopenharmony_ci	ULong L, *x, *xe;
75f9f848faSopenharmony_ci	int n = 0;
76f9f848faSopenharmony_ci
77f9f848faSopenharmony_ci	x = b->x;
78f9f848faSopenharmony_ci	xe = x + b->wds;
79f9f848faSopenharmony_ci	for(n = 0; x < xe && !*x; x++)
80f9f848faSopenharmony_ci		n += ULbits;
81f9f848faSopenharmony_ci	if (x < xe) {
82f9f848faSopenharmony_ci		L = *x;
83f9f848faSopenharmony_ci		n += lo0bits(&L);
84f9f848faSopenharmony_ci		}
85f9f848faSopenharmony_ci	return n;
86f9f848faSopenharmony_ci	}
87