bits.c 850 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #include "cc.h"
  2. Bits
  3. bor(Bits a, Bits b)
  4. {
  5. Bits c;
  6. int i;
  7. for(i=0; i<BITS; i++)
  8. c.b[i] = a.b[i] | b.b[i];
  9. return c;
  10. }
  11. Bits
  12. band(Bits a, Bits b)
  13. {
  14. Bits c;
  15. int i;
  16. for(i=0; i<BITS; i++)
  17. c.b[i] = a.b[i] & b.b[i];
  18. return c;
  19. }
  20. /*
  21. Bits
  22. bnot(Bits a)
  23. {
  24. Bits c;
  25. int i;
  26. for(i=0; i<BITS; i++)
  27. c.b[i] = ~a.b[i];
  28. return c;
  29. }
  30. */
  31. int
  32. bany(Bits *a)
  33. {
  34. int i;
  35. for(i=0; i<BITS; i++)
  36. if(a->b[i])
  37. return 1;
  38. return 0;
  39. }
  40. int
  41. beq(Bits a, Bits b)
  42. {
  43. int i;
  44. for(i=0; i<BITS; i++)
  45. if(a.b[i] != b.b[i])
  46. return 0;
  47. return 1;
  48. }
  49. int
  50. bnum(Bits a)
  51. {
  52. int i;
  53. long b;
  54. for(i=0; i<BITS; i++)
  55. if(b = a.b[i])
  56. return 32*i + bitno(b);
  57. diag(Z, "bad in bnum");
  58. return 0;
  59. }
  60. Bits
  61. blsh(uint n)
  62. {
  63. Bits c;
  64. c = zbits;
  65. c.b[n/32] = 1L << (n%32);
  66. return c;
  67. }
  68. int
  69. bset(Bits a, uint n)
  70. {
  71. if(a.b[n/32] & (1L << (n%32)))
  72. return 1;
  73. return 0;
  74. }