]>
Commit | Line | Data |
---|---|---|
2aa62f2b | 1 | /* $NetBSD: gmisc.c,v 1.3 2006/03/11 18:38:14 kleink Exp $ */\r |
2 | \r | |
3 | /****************************************************************\r | |
4 | \r | |
5 | The author of this software is David M. Gay.\r | |
6 | \r | |
7 | Copyright (C) 1998 by Lucent Technologies\r | |
8 | All Rights Reserved\r | |
9 | \r | |
10 | Permission to use, copy, modify, and distribute this software and\r | |
11 | its documentation for any purpose and without fee is hereby\r | |
12 | granted, provided that the above copyright notice appear in all\r | |
13 | copies and that both that the copyright notice and this\r | |
14 | permission notice and warranty disclaimer appear in supporting\r | |
15 | documentation, and that the name of Lucent or any of its entities\r | |
16 | not be used in advertising or publicity pertaining to\r | |
17 | distribution of the software without specific, written prior\r | |
18 | permission.\r | |
19 | \r | |
20 | LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,\r | |
21 | INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.\r | |
22 | IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY\r | |
23 | SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\r | |
24 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER\r | |
25 | IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,\r | |
26 | ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\r | |
27 | THIS SOFTWARE.\r | |
28 | \r | |
29 | ****************************************************************/\r | |
30 | \r | |
31 | /* Please send bug reports to David M. Gay (dmg at acm dot org,\r | |
32 | * with " at " changed at "@" and " dot " changed to "."). */\r | |
33 | #include <LibConfig.h>\r | |
34 | \r | |
35 | #include "gdtoaimp.h"\r | |
36 | \r | |
37 | void\r | |
38 | rshift(Bigint *b, int k)\r | |
39 | {\r | |
40 | ULong *x, *x1, *xe, y;\r | |
41 | int n;\r | |
42 | \r | |
43 | x = x1 = b->x;\r | |
44 | n = (unsigned int)k >> kshift;\r | |
45 | if (n < b->wds) {\r | |
46 | xe = x + b->wds;\r | |
47 | x += n;\r | |
48 | if (k &= kmask) {\r | |
49 | n = ULbits - k;\r | |
50 | y = *x++ >> k;\r | |
51 | while(x < xe) {\r | |
52 | *x1++ = (y | (*x << n)) & ALL_ON;\r | |
53 | y = *x++ >> k;\r | |
54 | }\r | |
55 | if ((*x1 = y) !=0)\r | |
56 | x1++;\r | |
57 | }\r | |
58 | else\r | |
59 | while(x < xe)\r | |
60 | *x1++ = *x++;\r | |
61 | }\r | |
62 | if ((b->wds = (int)(x1 - b->x)) == 0)\r | |
63 | b->x[0] = 0;\r | |
64 | }\r | |
65 | \r | |
66 | int\r | |
67 | trailz(CONST Bigint *b)\r | |
68 | {\r | |
69 | ULong L;\r | |
70 | CONST ULong *x, *xe;\r | |
71 | int n = 0;\r | |
72 | \r | |
73 | x = b->x;\r | |
74 | xe = x + b->wds;\r | |
75 | for(n = 0; x < xe && !*x; x++)\r | |
76 | n += ULbits;\r | |
77 | if (x < xe) {\r | |
78 | L = *x;\r | |
79 | n += lo0bits(&L);\r | |
80 | }\r | |
81 | return n;\r | |
82 | }\r |