1 | /* |
---|

2 | Copyright (C) 1994-2001 Digitool, Inc |
---|

3 | This file is part of OpenMCL. |
---|

4 | |
---|

5 | OpenMCL is licensed under the terms of the Lisp Lesser GNU Public |
---|

6 | License , known as the LLGPL and distributed with OpenMCL as the |
---|

7 | file "LICENSE". The LLGPL consists of a preamble and the LGPL, |
---|

8 | which is distributed with OpenMCL as the file "LGPL". Where these |
---|

9 | conflict, the preamble takes precedence. |
---|

10 | |
---|

11 | OpenMCL is referenced in the preamble as the "LIBRARY." |
---|

12 | |
---|

13 | The LLGPL is also available online at |
---|

14 | http://opensource.franz.com/preamble.html |
---|

15 | */ |
---|

16 | |
---|

17 | |
---|

18 | #include "bits.h" |
---|

19 | #include "lisp.h" |
---|

20 | |
---|

21 | |
---|

22 | |
---|

23 | /* This should be a lot faster than calling set_bit N times */ |
---|

24 | |
---|

25 | void |
---|

26 | set_n_bits(bitvector bits, unsigned first, unsigned n) |
---|

27 | { |
---|

28 | if (n) { |
---|

29 | unsigned |
---|

30 | lastbit = (first+n)-1, |
---|

31 | leftbit = first & 0x1f, |
---|

32 | leftmask = 0xffffffff >> leftbit, |
---|

33 | rightmask = 0xffffffff << (31 - (lastbit & 0x1f)), |
---|

34 | *wstart = ((unsigned *) bits) + (first>>5), |
---|

35 | *wend = ((unsigned *) bits) + (lastbit>>5); |
---|

36 | |
---|

37 | if (wstart == wend) { |
---|

38 | *wstart |= (leftmask & rightmask); |
---|

39 | } else { |
---|

40 | *wstart++ |= leftmask; |
---|

41 | n -= (32 - leftbit); |
---|

42 | |
---|

43 | while (n >= 32) { |
---|

44 | *wstart++ = 0xffffffff; |
---|

45 | n-=32; |
---|

46 | } |
---|

47 | |
---|

48 | if (n) { |
---|

49 | *wstart |= rightmask; |
---|

50 | } |
---|

51 | } |
---|

52 | } |
---|

53 | } |
---|

54 | |
---|

55 | |
---|

56 | |
---|

57 | |
---|

58 | |
---|

59 | bitvector |
---|

60 | new_bitvector(unsigned nbits) |
---|

61 | { |
---|

62 | return (bitvector) zalloc((sizeof(unsigned)*(nbits+31)>>5)); |
---|

63 | } |
---|

64 | |
---|

65 | /* Note that this zeros fullwords */ |
---|

66 | void |
---|

67 | zero_bits(bitvector bits, unsigned nbits) |
---|

68 | { |
---|

69 | memset(bits, 0, (sizeof(unsigned)*((nbits+31)>>5))); |
---|

70 | } |
---|

71 | |
---|

72 | void |
---|

73 | ior_bits(bitvector dest, bitvector src, unsigned nbits) |
---|

74 | { |
---|

75 | while (nbits > 0) { |
---|

76 | *dest++ |= *src++; |
---|

77 | nbits -= 32; |
---|

78 | } |
---|

79 | } |
---|