bits

package
v0.0.0-...-27f1cf3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2025 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bits

type Bits[U Uint] interface {
	Int(x U) int
	FromInt(int) U

	Add(x, y, carry U) (sum, carryOut U)
	Sub(x, y, borrow U) (diff, borrowOut U)
	Inc(x U) U
	Dec(x U) U

	Mul(x, y U) (hi, lo U)
	Div(hi, lo, y U) (quo, rem U)

	Not(U) U
	Or(x, y U) U
	And(x, y U) U
	Mask(x, mask U) U
	MaskInsert(x, y, mask U) U
	Xor(x, y U) U

	Rotl(x U, k int) U
	Pow2(x int) U
	Pow2m1(x int) U
	Shl(x U, k int) U
	Shr(x U, k int) U
	Lzcnt(x U) int

	Cmp(x, y U) int
	Eq(x, y U) bool
	Neq(x, y U) bool
	Lt(x, y U) bool
	Lte(x, y U) bool
	Gt(x, y U) bool
	Gte(x, y U) bool

	// Usefully, avoid needing to declare zero values.
	IsZero(x U) bool
}

Bits defines a generic interface of operations upon a Uint.

type Bits16

type Bits16 struct{}

Bits16 provides a genericable surface to abstract uint16 math.

func (Bits16) Add

func (Bits16) Add(x, y, carry uint16) (sum, carryOut uint16)

Add is bits.Add16.

func (Bits16) And

func (Bits16) And(x, y uint16) uint16

And returns the bitwise AND of the arguments.

func (Bits16) Cmp

func (Bits16) Cmp(x, y uint16) int

Cmp is cmp.Compare.

func (Bits16) Dec

func (Bits16) Dec(x uint16) uint16

Dec is a simplified decrement.

func (Bits16) Div

func (Bits16) Div(hi, lo, y uint16) (quo, rem uint16)

Div is bits.Div16.

func (Bits16) Eq

func (Bits16) Eq(x, y uint16) bool

Eq returns true if x equals y.

func (Bits16) FromInt

func (Bits16) FromInt(i int) uint16

FromInt converts from an int.

func (Bits16) Gt

func (Bits16) Gt(x, y uint16) bool

Gt returns true if x is greater than y.

func (Bits16) Gte

func (Bits16) Gte(x, y uint16) bool

Gte returns true if x is greater than or equal to y.

func (Bits16) Inc

func (Bits16) Inc(x uint16) uint16

Inc is a simplified increment.

func (Bits16) Int

func (Bits16) Int(x uint16) int

Int converts to an int.

func (Bits16) IsZero

func (b Bits16) IsZero(x uint16) bool

IsZero returns true if x is zero.

func (Bits16) Lt

func (Bits16) Lt(x, y uint16) bool

Lt returns true if x is less than y.

func (Bits16) Lte

func (Bits16) Lte(x, y uint16) bool

Lte returns true if x is less than or equal to y.

func (Bits16) Lzcnt

func (Bits16) Lzcnt(x uint16) int

Lzcnt is bits.LeadingZeros16.

func (Bits16) Mask

func (Bits16) Mask(x, mask uint16) uint16

Mask masks out the mask bits from x.

func (Bits16) MaskInsert

func (Bits16) MaskInsert(x, y, mask uint16) uint16

MaskInsert composes masking out the mask bits from x with ORing in the mask bits of y.

func (Bits16) Mul

func (Bits16) Mul(x, y uint16) (hi, lo uint16)

Mul is bits.Mul16.

func (Bits16) Neq

func (Bits16) Neq(x, y uint16) bool

Neq returns true if x does not equal y.

func (Bits16) Not

func (Bits16) Not(x uint16) uint16

Not returns the bitwise inverse of all bits in the argument.

func (Bits16) Or

func (Bits16) Or(x, y uint16) uint16

Or returns the bitwise OR of the arguments.

func (Bits16) Pow2

func (Bits16) Pow2(x int) uint16

Pow2 returns the integer power of two.

It is undefined behavior to use an x greater than or equal to the bit width.

func (Bits16) Pow2m1

func (Bits16) Pow2m1(x int) uint16

Pow2m1 returns the integer power of two minus one.

It is undefined behavior to use an x greater than the bit width.

func (Bits16) Rotl

func (Bits16) Rotl(x uint16, k int) uint16

Rotl is bits.RotateLeft16.

func (Bits16) Shl

func (Bits16) Shl(x uint16, k int) uint16

Shl performs a left shift.

func (Bits16) Shr

func (Bits16) Shr(x uint16, k int) uint16

Shr performs a right shift.

func (Bits16) Sub

func (Bits16) Sub(x, y, borrow uint16) (diff, borrowOut uint16)

Sub is bits.Sub16.

func (Bits16) Xor

func (Bits16) Xor(x, y uint16) uint16

Xor returns the bitwise XOR.

type Bits32

type Bits32 struct{}

Bits32 provides a genericable surface to abstract uint32 math.

func (Bits32) Add

func (Bits32) Add(x, y, carry uint32) (sum, carryOut uint32)

Add is bits.Add32.

func (Bits32) And

func (Bits32) And(x, y uint32) uint32

And returns the bitwise AND of the arguments.

func (Bits32) Cmp

func (Bits32) Cmp(x, y uint32) int

Cmp is cmp.Compare.

func (Bits32) Dec

func (Bits32) Dec(x uint32) uint32

Dec is a simplified decrement.

func (Bits32) Div

func (Bits32) Div(hi, lo, y uint32) (quo, rem uint32)

Div is bits.Div32.

func (Bits32) Eq

func (Bits32) Eq(x, y uint32) bool

Eq returns true if x equals y.

func (Bits32) FromInt

func (Bits32) FromInt(i int) uint32

FromInt converts from an int.

func (Bits32) Gt

func (Bits32) Gt(x, y uint32) bool

Gt returns true if x is greater than y.

func (Bits32) Gte

func (Bits32) Gte(x, y uint32) bool

Gte returns true if x is greater than or equal to y.

func (Bits32) Inc

func (Bits32) Inc(x uint32) uint32

Inc is a simplified increment.

func (Bits32) Int

func (Bits32) Int(x uint32) int

Int converts to an int.

func (Bits32) IsZero

func (b Bits32) IsZero(x uint32) bool

IsZero returns true if x is zero.

func (Bits32) Lt

func (Bits32) Lt(x, y uint32) bool

Lt returns true if x is less than y.

func (Bits32) Lte

func (Bits32) Lte(x, y uint32) bool

Lte returns true if x is less than or equal to y.

func (Bits32) Lzcnt

func (Bits32) Lzcnt(x uint32) int

Lzcnt is bits.LeadingZeros32.

func (Bits32) Mask

func (Bits32) Mask(x, mask uint32) uint32

Mask masks out the mask bits from x.

func (Bits32) MaskInsert

func (Bits32) MaskInsert(x, y, mask uint32) uint32

MaskInsert composes masking out the mask bits from x with ORing in the mask bits of y.

func (Bits32) Mul

func (Bits32) Mul(x, y uint32) (hi, lo uint32)

Mul is bits.Mul32.

func (Bits32) Neq

func (Bits32) Neq(x, y uint32) bool

Neq returns true if x does not equal y.

func (Bits32) Not

func (Bits32) Not(x uint32) uint32

Not returns the bitwise inverse of all bits in the argument.

func (Bits32) Or

func (Bits32) Or(x, y uint32) uint32

Or returns the bitwise OR of the arguments.

func (Bits32) Pow2

func (Bits32) Pow2(x int) uint32

Pow2 returns the integer power of two.

It is undefined behavior to use an x greater than or equal to the bit width.

func (Bits32) Pow2m1

func (Bits32) Pow2m1(x int) uint32

Pow2m1 returns the integer power of two minus one.

It is undefined behavior to use an x greater than the bit width.

func (Bits32) Rotl

func (Bits32) Rotl(x uint32, k int) uint32

Rotl is bits.RotateLeft32.

func (Bits32) Shl

func (Bits32) Shl(x uint32, k int) uint32

Shl performs a left shift.

func (Bits32) Shr

func (Bits32) Shr(x uint32, k int) uint32

Shr performs a right shift.

func (Bits32) Sub

func (Bits32) Sub(x, y, borrow uint32) (diff, borrowOut uint32)

Sub is bits.Sub32.

func (Bits32) Xor

func (Bits32) Xor(x, y uint32) uint32

Xor returns the bitwise XOR.

type Bits64

type Bits64 struct{}

Bits64 provides a genericable surface to abstract uint64 math.

func (Bits64) Add

func (Bits64) Add(x, y, carry uint64) (sum, carryOut uint64)

Add is bits.Add64.

func (Bits64) And

func (Bits64) And(x, y uint64) uint64

And returns the bitwise AND of the arguments.

func (Bits64) Cmp

func (Bits64) Cmp(x, y uint64) int

Cmp is cmp.Compare.

func (Bits64) Dec

func (Bits64) Dec(x uint64) uint64

Dec is a simplified decrement.

func (Bits64) Div

func (Bits64) Div(hi, lo, y uint64) (quo, rem uint64)

Div is bits.Div64.

func (Bits64) Eq

func (Bits64) Eq(x, y uint64) bool

Eq returns true if x equals y.

func (Bits64) FromInt

func (Bits64) FromInt(i int) uint64

FromInt converts from an int.

func (Bits64) Gt

func (Bits64) Gt(x, y uint64) bool

Gt returns true if x is greater than y.

func (Bits64) Gte

func (Bits64) Gte(x, y uint64) bool

Gte returns true if x is greater than or equal to y.

func (Bits64) Inc

func (Bits64) Inc(x uint64) uint64

Inc is a simplified increment.

func (Bits64) Int

func (Bits64) Int(x uint64) int

Int converts to an int.

func (Bits64) IsZero

func (b Bits64) IsZero(x uint64) bool

IsZero returns true if x is zero.

func (Bits64) Lt

func (Bits64) Lt(x, y uint64) bool

Lt returns true if x is less than y.

func (Bits64) Lte

func (Bits64) Lte(x, y uint64) bool

Lte returns true if x is less than or equal to y.

func (Bits64) Lzcnt

func (Bits64) Lzcnt(x uint64) int

Lzcnt is bits.LeadingZeros64.

func (Bits64) Mask

func (Bits64) Mask(x, mask uint64) uint64

Mask masks out the mask bits from x.

func (Bits64) MaskInsert

func (Bits64) MaskInsert(x, y, mask uint64) uint64

MaskInsert composes masking out the mask bits from x with ORing in the mask bits of y.

func (Bits64) Mul

func (Bits64) Mul(x, y uint64) (hi, lo uint64)

Mul is bits.Mul64.

func (Bits64) Neq

func (Bits64) Neq(x, y uint64) bool

Neq returns true if x does not equal y.

func (Bits64) Not

func (Bits64) Not(x uint64) uint64

Not returns the bitwise inverse of all bits in the argument.

func (Bits64) Or

func (Bits64) Or(x, y uint64) uint64

Or returns the bitwise OR of the arguments.

func (Bits64) Pow2

func (Bits64) Pow2(x int) uint64

Pow2 returns the integer power of two.

It is undefined behavior to use an x greater than or equal to the bit width.

func (Bits64) Pow2m1

func (Bits64) Pow2m1(x int) uint64

Pow2m1 returns the integer power of two minus one.

It is undefined behavior to use an x greater than the bit width.

func (Bits64) Rotl

func (Bits64) Rotl(x uint64, k int) uint64

Rotl is bits.RotateLeft64.

func (Bits64) Shl

func (Bits64) Shl(x uint64, k int) uint64

Shl performs a left shift.

func (Bits64) Shr

func (Bits64) Shr(x uint64, k int) uint64

Shr performs a right shift.

func (Bits64) Sub

func (Bits64) Sub(x, y, borrow uint64) (diff, borrowOut uint64)

Sub is bits.Sub64.

func (Bits64) Xor

func (Bits64) Xor(x, y uint64) uint64

Xor returns the bitwise XOR of the arguments.

type Bits128

type Bits128 struct{}

Bits128 provides a genericable surface to abstract uint64 math.

func (Bits128) Add

func (Bits128) Add(x, y, carry Uint128) (sum, carryOut Uint128)

Add is bits.Add128.

func (Bits128) And

func (Bits128) And(x, y Uint128) Uint128

And returns the bitwise AND of the arguments.

func (Bits128) Cmp

func (Bits128) Cmp(x, y Uint128) int

Cmp is cmp.Compare.

func (Bits128) Dec

func (b Bits128) Dec(x Uint128) Uint128

Dec is a simplified decrement.

func (Bits128) Div

func (Bits128) Div(hi, lo, y Uint128) (quo, rem Uint128)

Div is bits.Div128.

func (Bits128) Eq

func (b Bits128) Eq(x, y Uint128) bool

Eq returns true if x equals y.

func (Bits128) FromInt

func (Bits128) FromInt(i int) (u Uint128)

FromInt converts from an int.

func (Bits128) Gt

func (b Bits128) Gt(x, y Uint128) bool

Gt returns true if x is greater than y.

func (Bits128) Gte

func (b Bits128) Gte(x, y Uint128) bool

Gte returns true if x is greater than or equal to y.

func (Bits128) Inc

func (b Bits128) Inc(x Uint128) Uint128

Inc is a simplified increment.

func (Bits128) Int

func (Bits128) Int(x Uint128) int

Int converts to an int.

This is a simple cast, and will discard bits above strconv.IntSize.

func (Bits128) IsZero

func (b Bits128) IsZero(x Uint128) bool

IsZero returns true if x is zero.

func (Bits128) Lt

func (b Bits128) Lt(x, y Uint128) bool

Lt returns true if x is less than y.

func (Bits128) Lte

func (b Bits128) Lte(x, y Uint128) bool

Lte returns true if x is less than or equal to y.

func (Bits128) Lzcnt

func (Bits128) Lzcnt(x Uint128) int

Lzcnt is bits.LeadingZeros128.

func (Bits128) Mask

func (Bits128) Mask(x, mask Uint128) Uint128

Mask masks out the mask bits from x.

func (Bits128) MaskInsert

func (Bits128) MaskInsert(x, y, mask Uint128) Uint128

MaskInsert composes masking out the mask bits from x with ORing in the mask bits of y.

func (Bits128) Mul

func (b Bits128) Mul(x, y Uint128) (hi, lo Uint128)

Mul is bits.Mul128.

func (Bits128) Neq

func (b Bits128) Neq(x, y Uint128) bool

Neq returns true if x does not equal y.

func (Bits128) Not

func (Bits128) Not(x Uint128) Uint128

Not returns the bitwise inverse of all bits in the argument.

func (Bits128) Or

func (Bits128) Or(x, y Uint128) Uint128

Or returns the bitwise OR of the arguments.

func (Bits128) Pow2

func (Bits128) Pow2(x int) Uint128

Pow2 returns the integer power of two.

It is undefined behavior to use an x greater than or equal to the bit width.

func (Bits128) Pow2m1

func (Bits128) Pow2m1(x int) Uint128

Pow2m1 returns the integer power of two minus one.

It is undefined behavior to use an x greater than the bit width.

func (Bits128) Rotl

func (Bits128) Rotl(x Uint128, k int) (r Uint128)

Rotl is bits.RotateLeft128.

func (Bits128) Shl

func (Bits128) Shl(x Uint128, k int) (r Uint128)

Shl performs a left shift.

func (Bits128) Shr

func (Bits128) Shr(x Uint128, k int) Uint128

Shr performs a right shift.

func (Bits128) Sub

func (Bits128) Sub(x, y, borrow Uint128) (diff, borrowOut Uint128)

Sub is bits.Sub128.

func (Bits128) Xor

func (Bits128) Xor(x, y Uint128) Uint128

Xor returns the bitwise XOR of the arguments.

type Uint

type Uint interface {
	Uint16 | uint32 | Uint64 | Uint128
}

Uint defines a constraint on available unsigned ints supported.

type Uint16

type Uint16 = uint16

Uint16 is an alias to uint16, to provide name consistency with Uint128.

type Uint32

type Uint32 = uint32

Uint32 is an alias to uint32, to provide name consistency with Uint128.

type Uint64

type Uint64 = uint64

Uint64 is an alias to uint64, to provide name consistency with Uint128.

type Uint128

type Uint128 struct {
	Hi, Lo uint64
}

Uint128 defines a 128 bit unsigned integer.

func (Uint128) Format

func (u Uint128) Format(f fmt.State, verb rune)

Format implements fmt.Formatter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL