1
0

bits.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. #define EXTERN
  10. #include "gc.h"
  11. /*
  12. Bits
  13. bor(Bits a, Bits b)
  14. {
  15. Bits c;
  16. int i;
  17. for(i=0; i<BITS; i++)
  18. c.b[i] = a.b[i] | b.b[i];
  19. return c;
  20. }
  21. */
  22. /*
  23. Bits
  24. band(Bits a, Bits b)
  25. {
  26. Bits c;
  27. int i;
  28. for(i=0; i<BITS; i++)
  29. c.b[i] = a.b[i] & b.b[i];
  30. return c;
  31. }
  32. */
  33. /*
  34. Bits
  35. bnot(Bits a)
  36. {
  37. Bits c;
  38. int i;
  39. for(i=0; i<BITS; i++)
  40. c.b[i] = ~a.b[i];
  41. return c;
  42. }
  43. */
  44. int
  45. bany(Bits *a)
  46. {
  47. int i;
  48. for(i=0; i<BITS; i++)
  49. if(a->b[i])
  50. return 1;
  51. return 0;
  52. }
  53. /*
  54. int
  55. beq(Bits a, Bits b)
  56. {
  57. int i;
  58. for(i=0; i<BITS; i++)
  59. if(a.b[i] != b.b[i])
  60. return 0;
  61. return 1;
  62. }
  63. */
  64. int
  65. bnum(Bits a)
  66. {
  67. int i;
  68. int32_t b;
  69. for(i=0; i<BITS; i++)
  70. if(b = a.b[i])
  71. return 32*i + bitno(b);
  72. diag(Z, "bad in bnum");
  73. return 0;
  74. }
  75. Bits
  76. blsh(unsigned n)
  77. {
  78. Bits c;
  79. c = zbits;
  80. c.b[n/32] = 1L << (n%32);
  81. return c;
  82. }
  83. /*
  84. int
  85. bset(Bits a, unsigned n)
  86. {
  87. int i;
  88. if(a.b[n/32] & (1L << (n%32)))
  89. return 1;
  90. return 0;
  91. }
  92. */
  93. int
  94. Bconv(va_list *arg, Fconv *fp)
  95. {
  96. char str[STRINGSZ], ss[STRINGSZ], *s;
  97. Bits bits;
  98. int i;
  99. str[0] = 0;
  100. bits = va_arg(*arg, Bits);
  101. while(bany(&bits)) {
  102. i = bnum(bits);
  103. if(str[0])
  104. strcat(str, " ");
  105. if(var[i].sym == S) {
  106. sprint(ss, "$%ld", var[i].offset);
  107. s = ss;
  108. } else
  109. s = var[i].sym->name;
  110. if(strlen(str) + strlen(s) + 1 >= STRINGSZ)
  111. break;
  112. strcat(str, s);
  113. bits.b[i/32] &= ~(1L << (i%32));
  114. }
  115. strconv(str, fp);
  116. return 0;
  117. }