Embedded Artistry libc
C Standard Library Support for Bare-metal Systems
gmisc.c File Reference
#include "gdtoaimp.h"
Include dependency graph for gmisc.c:

Go to the source code of this file.

Functions

void rshift (Bigint *b, int k)
 
int trailz (Bigint *b)
 

Function Documentation

◆ rshift()

void rshift ( Bigint b,
int  k 
)

Definition at line 39 of file gmisc.c.

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 }
#define ALL_ON
Definition: gdtoaimp.h:469
ULong x[1]
Definition: gdtoaimp.h:488
int wds
Definition: gdtoaimp.h:487
#define kshift
Definition: gdtoaimp.h:467
unsigned Long ULong
Definition: gdtoa.h:41
#define kmask
Definition: gdtoaimp.h:468
#define ULbits
Definition: gdtoaimp.h:466

References ALL_ON, kmask, kshift, ULbits, Bigint::wds, and Bigint::x.

Referenced by g_ddfmt(), gdtoa(), gethex(), rvOK(), strtodg(), and strtoIg().

◆ trailz()

int trailz ( Bigint b)

Definition at line 92 of file gmisc.c.

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 }
ULong x[1]
Definition: gdtoaimp.h:488
int wds
Definition: gdtoaimp.h:487
int lo0bits(ULong *y)
Definition: misc.c:108
unsigned Long ULong
Definition: gdtoa.h:41
#define ULbits
Definition: gdtoaimp.h:466

References lo0bits(), ULbits, Bigint::wds, and Bigint::x.

Referenced by gdtoa(), and strtodg().