lbitbits.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "f2c.h"
  2. #ifdef __cplusplus
  3. extern "C" {
  4. #endif
  5. #ifndef LONGBITS
  6. #define LONGBITS 32
  7. #endif
  8. integer
  9. #ifdef KR_headers
  10. lbit_bits(a, b, len) integer a, b, len;
  11. #else
  12. lbit_bits(integer a, integer b, integer len)
  13. #endif
  14. {
  15. /* Assume 2's complement arithmetic */
  16. unsigned long x, y;
  17. x = (unsigned long) a;
  18. y = (unsigned long)-1L;
  19. x >>= b;
  20. y <<= len;
  21. return (integer)(x & ~y);
  22. }
  23. integer
  24. #ifdef KR_headers
  25. lbit_cshift(a, b, len) integer a, b, len;
  26. #else
  27. lbit_cshift(integer a, integer b, integer len)
  28. #endif
  29. {
  30. unsigned long x, y, z;
  31. x = (unsigned long)a;
  32. if (len <= 0) {
  33. if (len == 0)
  34. return 0;
  35. goto full_len;
  36. }
  37. if (len >= LONGBITS) {
  38. full_len:
  39. if (b >= 0) {
  40. b %= LONGBITS;
  41. return (integer)(x << b | x >> LONGBITS -b );
  42. }
  43. b = -b;
  44. b %= LONGBITS;
  45. return (integer)(x << LONGBITS - b | x >> b);
  46. }
  47. y = z = (unsigned long)-1;
  48. y <<= len;
  49. z &= ~y;
  50. y &= x;
  51. x &= z;
  52. if (b >= 0) {
  53. b %= len;
  54. return (integer)(y | z & (x << b | x >> len - b));
  55. }
  56. b = -b;
  57. b %= len;
  58. return (integer)(y | z & (x >> b | x << len - b));
  59. }
  60. #ifdef __cplusplus
  61. }
  62. #endif