// Copyright 2020 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 netipimport// uint128 represents a uint128 using two uint64s.//// When the methods below mention a bit number, bit 0 is the most// significant bit (in hi) and bit 127 is the lowest (lo&1).typeuint128struct {hiuint64louint64}// mask6 returns a uint128 bitmask with the topmost n bits of a// 128-bit number.func ( int) uint128 {returnuint128{^(^uint64(0) >> ), ^uint64(0) << (128 - )}}// isZero reports whether u == 0.//// It's faster than u == (uint128{}) because the compiler (as of Go// 1.15/1.16b1) doesn't do this trick and instead inserts a branch in// its eq alg's generated code.func ( uint128) () bool { return .hi|.lo == 0 }// and returns the bitwise AND of u and m (u&m).func ( uint128) ( uint128) uint128 {returnuint128{.hi & .hi, .lo & .lo}}// xor returns the bitwise XOR of u and m (u^m).func ( uint128) ( uint128) uint128 {returnuint128{.hi ^ .hi, .lo ^ .lo}}// or returns the bitwise OR of u and m (u|m).func ( uint128) ( uint128) uint128 {returnuint128{.hi | .hi, .lo | .lo}}// not returns the bitwise NOT of u.func ( uint128) () uint128 {returnuint128{^.hi, ^.lo}}// subOne returns u - 1.func ( uint128) () uint128 { , := bits.Sub64(.lo, 1, 0)returnuint128{.hi - , }}// addOne returns u + 1.func ( uint128) () uint128 { , := bits.Add64(.lo, 1, 0)returnuint128{.hi + , }}// halves returns the two uint64 halves of the uint128.//// Logically, think of it as returning two uint64s.// It only returns pointers for inlining reasons on 32-bit platforms.func ( *uint128) () [2]*uint64 {return [2]*uint64{&.hi, &.lo}}// bitsSetFrom returns a copy of u with the given bit// and all subsequent ones set.func ( uint128) ( uint8) uint128 {return .or(mask6(int()).not())}// bitsClearedFrom returns a copy of u with the given bit// and all subsequent ones cleared.func ( uint128) ( uint8) uint128 {return .and(mask6(int()))}
The pages are generated with Goldsv0.6.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.