package bits
import "gvisor.dev/gvisor/pkg/bits"
Package bits includes all bit related types and operations.
Index ¶
- func AlignDown(length int, align uint) int
- func AlignUp(length int, align uint) int
- func ForEachSetBit64(x uint64, f func(i int))
- func IsAnyOn(mask, bits T) bool
- func IsOn(mask, bits T) bool
- func IsPowerOfTwo(v T) bool
- func MostSignificantOne64(x uint64) int
- func TrailingZeros64(x uint64) int
- type T
Functions ¶
func AlignDown ¶
AlignDown rounds a length down to an alignment. align must be a power of 2.
func AlignUp ¶
AlignUp rounds a length up to an alignment. align must be a power of 2.
func ForEachSetBit64 ¶
ForEachSetBit64 calls f once for each set bit in x, with argument i equal to the set bit's index.
func IsAnyOn ¶
IsAnyOn returns true if *any* bit set in 'bits' is set in 'mask'.
func IsOn ¶
IsOn returns true if *all* bits set in 'bits' are set in 'mask'.
func IsPowerOfTwo ¶
IsPowerOfTwo returns true if v is power of 2.
func MostSignificantOne64 ¶
MostSignificantOne64 returns the index of the most significant 1 bit in x. If x is 0, MostSignificantOne64 returns 64.
func TrailingZeros64 ¶
TrailingZeros64 returns the number of bits before the least significant 1 bit in x; in other words, it returns the index of the least significant 1 bit in x. If x is 0, TrailingZeros64 returns 64.
Types ¶
type T ¶
type T uint64
T is a required type parameter that must be an integral type.
func Mask ¶
Mask returns a T with all of the given bits set.
func MaskOf ¶
MaskOf is like Mask, but sets only a single bit (more efficiently).
Source Files ¶
bits.go bits_template.go uint64_arch.go
- Version
- v0.0.0-20250605235530-a6711d1e1dc6 (latest)
- Published
- Jun 5, 2025
- Platform
- linux/amd64
- Last checked
- 4 hours ago –
Tools for package owners.