blob: a25adb752b7a54d60d6556d74a9101162ea12948 [file] [log] [blame]
Lorenz Brunfba5da02022-12-15 11:20:47 +00001package nvme
2
3import (
4 "math"
5 "math/big"
6)
7
8// uint128 little endian composed of two uint64s, readable by binary.Read.
9// Auxiliary type to simplify structures with uint128s (of which NVMe has
10// quite a few).
11type uint128le struct {
12 Lo, Hi uint64
13}
14
15// BigInt returns u as a bigint
16func (u uint128le) BigInt() *big.Int {
17 v := new(big.Int).SetUint64(u.Hi)
18 v = v.Lsh(v, 64)
19 v = v.Or(v, new(big.Int).SetUint64(u.Lo))
20 return v
21}
22
23// Uint64 returns u as a clamped uint64
24func (u uint128le) Uint64() uint64 {
25 if u.Hi > 0 {
26 return math.MaxUint64
27 }
28 return u.Lo
29}