gmisc.c 2.0 KB

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