github.com/sanprasirt/go@v0.0.0-20170607001320-a027466e4b6d/src/cmd/compile/internal/gc/bitset.go (about)

     1  // Copyright 2017 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package gc
     6  
     7  type bitset8 uint8
     8  
     9  func (f *bitset8) set(mask uint8, b bool) {
    10  	if b {
    11  		*(*uint8)(f) |= mask
    12  	} else {
    13  		*(*uint8)(f) &^= mask
    14  	}
    15  }
    16  
    17  type bitset32 uint32
    18  
    19  func (f *bitset32) set(mask uint32, b bool) {
    20  	if b {
    21  		*(*uint32)(f) |= mask
    22  	} else {
    23  		*(*uint32)(f) &^= mask
    24  	}
    25  }
    26  
    27  func (f bitset32) get2(shift uint8) uint8 {
    28  	return uint8(f>>shift) & 3
    29  }
    30  
    31  // set2 sets two bits in f using the bottom two bits of b.
    32  func (f *bitset32) set2(shift uint8, b uint8) {
    33  	// Clear old bits.
    34  	*(*uint32)(f) &^= 3 << shift
    35  	// Set new bits.
    36  	*(*uint32)(f) |= uint32(b&3) << shift
    37  }
    38  
    39  func (f bitset32) get3(shift uint8) uint8 {
    40  	return uint8(f>>shift) & 7
    41  }
    42  
    43  // set3 sets three bits in f using the bottom three bits of b.
    44  func (f *bitset32) set3(shift uint8, b uint8) {
    45  	// Clear old bits.
    46  	*(*uint32)(f) &^= 7 << shift
    47  	// Set new bits.
    48  	*(*uint32)(f) |= uint32(b&7) << shift
    49  }