2017-02-27 19:56:38 +02:00
|
|
|
// Copyright 2017 The Go Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
package gc
|
|
|
|
|
|
|
|
|
|
type bitset8 uint8
|
|
|
|
|
|
|
|
|
|
func (f *bitset8) set(mask uint8, b bool) {
|
|
|
|
|
if b {
|
|
|
|
|
*(*uint8)(f) |= mask
|
|
|
|
|
} else {
|
|
|
|
|
*(*uint8)(f) &^= mask
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-03 13:38:49 -08:00
|
|
|
type bitset32 uint32
|
|
|
|
|
|
|
|
|
|
func (f *bitset32) set(mask uint32, b bool) {
|
|
|
|
|
if b {
|
|
|
|
|
*(*uint32)(f) |= mask
|
|
|
|
|
} else {
|
|
|
|
|
*(*uint32)(f) &^= mask
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-04-25 17:30:08 -07:00
|
|
|
|
|
|
|
|
func (f bitset32) get2(shift uint8) uint8 {
|
|
|
|
|
return uint8(f>>shift) & 3
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-26 10:18:41 -07:00
|
|
|
// set2 sets two bits in f using the bottom two bits of b.
|
2017-04-25 17:30:08 -07:00
|
|
|
func (f *bitset32) set2(shift uint8, b uint8) {
|
|
|
|
|
// Clear old bits.
|
|
|
|
|
*(*uint32)(f) &^= 3 << shift
|
|
|
|
|
// Set new bits.
|
2017-04-26 10:18:41 -07:00
|
|
|
*(*uint32)(f) |= uint32(b&3) << shift
|
2017-04-25 17:30:08 -07:00
|
|
|
}
|
2017-04-25 18:14:12 -07:00
|
|
|
|
|
|
|
|
func (f bitset32) get3(shift uint8) uint8 {
|
|
|
|
|
return uint8(f>>shift) & 7
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-26 10:18:41 -07:00
|
|
|
// set3 sets three bits in f using the bottom three bits of b.
|
2017-04-25 18:14:12 -07:00
|
|
|
func (f *bitset32) set3(shift uint8, b uint8) {
|
|
|
|
|
// Clear old bits.
|
|
|
|
|
*(*uint32)(f) &^= 7 << shift
|
|
|
|
|
// Set new bits.
|
2017-04-26 10:18:41 -07:00
|
|
|
*(*uint32)(f) |= uint32(b&7) << shift
|
2017-04-25 18:14:12 -07:00
|
|
|
}
|