Source file src/cmd/compile/internal/ir/bitset.go

     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 ir
     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  func (f bitset8) get2(shift uint8) uint8 {
    18  	return uint8(f>>shift) & 3
    19  }
    20  
    21  // set2 sets two bits in f using the bottom two bits of b.
    22  func (f *bitset8) set2(shift uint8, b uint8) {
    23  	// Clear old bits.
    24  	*(*uint8)(f) &^= 3 << shift
    25  	// Set new bits.
    26  	*(*uint8)(f) |= uint8(b&3) << shift
    27  }
    28  
    29  type bitset16 uint16
    30  
    31  func (f *bitset16) set(mask uint16, b bool) {
    32  	if b {
    33  		*(*uint16)(f) |= mask
    34  	} else {
    35  		*(*uint16)(f) &^= mask
    36  	}
    37  }
    38  

View as plain text