bits.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include "cc.h"
  10. Bits
  11. bor(Bits a, Bits b)
  12. {
  13. Bits c;
  14. int i;
  15. for(i=0; i<BITS; i++)
  16. c.b[i] = a.b[i] | b.b[i];
  17. return c;
  18. }
  19. Bits
  20. band(Bits a, Bits b)
  21. {
  22. Bits c;
  23. int i;
  24. for(i=0; i<BITS; i++)
  25. c.b[i] = a.b[i] & b.b[i];
  26. return c;
  27. }
  28. /*
  29. Bits
  30. bnot(Bits a)
  31. {
  32. Bits c;
  33. int i;
  34. for(i=0; i<BITS; i++)
  35. c.b[i] = ~a.b[i];
  36. return c;
  37. }
  38. */
  39. int
  40. bany(Bits *a)
  41. {
  42. int i;
  43. for(i=0; i<BITS; i++)
  44. if(a->b[i])
  45. return 1;
  46. return 0;
  47. }
  48. int
  49. beq(Bits a, Bits b)
  50. {
  51. int i;
  52. for(i=0; i<BITS; i++)
  53. if(a.b[i] != b.b[i])
  54. return 0;
  55. return 1;
  56. }
  57. int
  58. bnum(Bits a)
  59. {
  60. int i;
  61. long b;
  62. for(i=0; i<BITS; i++)
  63. if((b = a.b[i]))
  64. return 32*i + bitno(b);
  65. diag(Z, "bad in bnum");
  66. return 0;
  67. }
  68. Bits
  69. blsh(uint n)
  70. {
  71. Bits c;
  72. c = zbits;
  73. c.b[n/32] = 1L << (n%32);
  74. return c;
  75. }
  76. int
  77. bset(Bits a, uint n)
  78. {
  79. if(a.b[n/32] & (1L << (n%32)))
  80. return 1;
  81. return 0;
  82. }