source: branches/working-0711/ccl/lisp-kernel/bits.c @ 12415

Last change on this file since 12415 was 11089, checked in by gz, 11 years ago

Merge/bootstrap assorted low level stuff from trunk - kernel, syscall stuff, lowmem-bias, formatting tweaks, a few bug fixes included

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.7 KB
Line 
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 "lisp.h"
19#include "bits.h"
20#include "lisp-exceptions.h"
21
22
23/* This should be a lot faster than calling set_bit N times */
24
25void
26set_n_bits(bitvector bits, natural first, natural n)
27{
28  if (n) {
29    natural
30      lastbit = (first+n)-1,
31      leftbit = first & bitmap_shift_count_mask,
32      leftmask = ALL_ONES >> leftbit,
33      rightmask = ALL_ONES << ((nbits_in_word-1) - (lastbit & bitmap_shift_count_mask)),
34      *wstart = ((natural *) bits) + (first>>bitmap_shift),
35      *wend = ((natural *) bits) + (lastbit>>bitmap_shift);
36
37    if (wstart == wend) {
38      *wstart |= (leftmask & rightmask);
39    } else {
40      *wstart++ |= leftmask;
41      n -= (nbits_in_word - leftbit);
42     
43      while (n >= nbits_in_word) {
44        *wstart++ = ALL_ONES;
45        n-= nbits_in_word;
46      }
47     
48      if (n) {
49        *wstart |= rightmask;
50      }
51    }
52  }
53}
54
55/* Note that this zeros longwords */
56void
57zero_bits(bitvector bits, natural nbits)
58{
59  memset(bits, 0, ((sizeof(natural)*(((nbits+(nbits_in_word-1)))>>bitmap_shift))));
60}
61
62void
63ior_bits(bitvector dest, bitvector src, natural nbits)
64{
65  while (nbits > 0) {
66    *dest++ |= *src++;
67    nbits -= nbits_in_word;
68  }
69}
Note: See TracBrowser for help on using the repository browser.