Embedded Artistry libc
C Standard Library Support for Bare-metal Systems
gmisc.c
Go to the documentation of this file.
1 /****************************************************************
2 
3 The author of this software is David M. Gay.
4 
5 Copyright (C) 1998 by Lucent Technologies
6 All Rights Reserved
7 
8 Permission to use, copy, modify, and distribute this software and
9 its documentation for any purpose and without fee is hereby
10 granted, provided that the above copyright notice appear in all
11 copies and that both that the copyright notice and this
12 permission notice and warranty disclaimer appear in supporting
13 documentation, and that the name of Lucent or any of its entities
14 not be used in advertising or publicity pertaining to
15 distribution of the software without specific, written prior
16 permission.
17 
18 LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
20 IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
21 SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
23 IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
24 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
25 THIS SOFTWARE.
26 
27 ****************************************************************/
28 
29 /* Please send bug reports to David M. Gay (dmg at acm dot org,
30  * with " at " changed at "@" and " dot " changed to "."). */
31 
32 #include "gdtoaimp.h"
33 
34 void
35 #ifdef KR_headers
36  rshift(b, k) Bigint* b;
37 int k;
38 #else
39 rshift(Bigint *b, int k)
40 #endif
41 {
42  ULong *x, *x1, y;
43  int n;
44 
45  x = x1 = b->x;
46  n = k >> kshift;
47  if(n < b->wds)
48  {
49  ULong* xe = x + b->wds;
50  x += n;
51  if(k &= kmask)
52  {
53  n = ULbits - k;
54  y = *x++ >> k;
55  while(x < xe)
56  {
57  *x1++ = (y | (*x << n)) & ALL_ON;
58  y = *x++ >> k;
59  }
60  if((*x1 = y) != 0)
61  {
62  {
63  x1++;
64  }
65  }
66  }
67  else
68  {
69  {
70  while(x < xe)
71  {
72  {
73  *x1++ = *x++;
74  }
75  }
76  }
77  }
78  }
79  b->wds = (int)(x1 - b->x);
80  if((b->wds) == 0)
81  {
82  {
83  b->x[0] = 0;
84  }
85  }
86 }
87 
88 int
89 #ifdef KR_headers
90  trailz(b) Bigint* b;
91 #else
93 #endif
94 {
95  ULong L, *x, *xe;
96  int n = 0;
97 
98  x = b->x;
99  xe = x + b->wds;
100  for(n = 0; x < xe && !*x; x++)
101  {
102  {
103  n += ULbits;
104  }
105  }
106  if(x < xe)
107  {
108  L = *x;
109  n += lo0bits(&L);
110  }
111  return n;
112 }
#define ALL_ON
Definition: gdtoaimp.h:469
ULong x[1]
Definition: gdtoaimp.h:488
int wds
Definition: gdtoaimp.h:487
int trailz(Bigint *b)
Definition: gmisc.c:92
int lo0bits(ULong *y)
Definition: misc.c:108
#define kshift
Definition: gdtoaimp.h:467
unsigned Long ULong
Definition: gdtoa.h:41
void rshift(Bigint *b, int k)
Definition: gmisc.c:39
#define kmask
Definition: gdtoaimp.h:468
#define ULbits
Definition: gdtoaimp.h:466