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