qbitbits.c 1.1 KB

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