1 | /* |
---|

2 | Copyright (C) 2009 Clozure Associates |
---|

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

4 | This file is part of Clozure CL. |
---|

5 | |
---|

6 | Clozure CL is licensed under the terms of the Lisp Lesser GNU Public |
---|

7 | License , known as the LLGPL and distributed with Clozure CL as the |
---|

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

9 | which is distributed with Clozure CL as the file "LGPL". Where these |
---|

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

11 | |
---|

12 | Clozure CL is referenced in the preamble as the "LIBRARY." |
---|

13 | |
---|

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

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

16 | */ |
---|

17 | |
---|

18 | |
---|

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

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

21 | #include "lisp-exceptions.h" |
---|

22 | |
---|

23 | |
---|

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

25 | |
---|

26 | void |
---|

27 | set_n_bits(bitvector bits, natural first, natural n) |
---|

28 | { |
---|

29 | if (n) { |
---|

30 | natural |
---|

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

32 | leftbit = first & bitmap_shift_count_mask, |
---|

33 | leftmask = ALL_ONES >> leftbit, |
---|

34 | rightmask = ALL_ONES << ((nbits_in_word-1) - (lastbit & bitmap_shift_count_mask)), |
---|

35 | *wstart = ((natural *) bits) + (first>>bitmap_shift), |
---|

36 | *wend = ((natural *) bits) + (lastbit>>bitmap_shift); |
---|

37 | |
---|

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

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

40 | } else { |
---|

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

42 | n -= (nbits_in_word - leftbit); |
---|

43 | |
---|

44 | while (n >= nbits_in_word) { |
---|

45 | *wstart++ = ALL_ONES; |
---|

46 | n-= nbits_in_word; |
---|

47 | } |
---|

48 | |
---|

49 | if (n) { |
---|

50 | *wstart |= rightmask; |
---|

51 | } |
---|

52 | } |
---|

53 | } |
---|

54 | } |
---|

55 | |
---|

56 | /* Note that this zeros longwords */ |
---|

57 | void |
---|

58 | zero_bits(bitvector bits, natural nbits) |
---|

59 | { |
---|

60 | memset(bits, 0, ((sizeof(natural)*(((nbits+(nbits_in_word-1)))>>bitmap_shift)))); |
---|

61 | } |
---|

62 | |
---|

63 | void |
---|

64 | ior_bits(bitvector dest, bitvector src, natural nbits) |
---|

65 | { |
---|

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

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

68 | nbits -= nbits_in_word; |
---|

69 | } |
---|

70 | } |
---|