github.com/usbarmory/tamago@v0.0.0-20240508072735-8612bbe1e454/bits/bits64.go (about) 1 // https://github.com/usbarmory/tamago 2 // 3 // Copyright (c) WithSecure Corporation 4 // https://foundry.withsecure.com 5 // 6 // Use of this source code is governed by the license 7 // that can be found in the LICENSE file. 8 9 package bits 10 11 // Get64 returns the pointed value at a specific bit position and with a 12 // bitmask applied. 13 func Get64(addr *uint64, pos int, mask int) uint64 { 14 return uint64((int(*addr) >> pos) & mask) 15 } 16 17 // Set64 modifies the pointed value by setting an individual bit at the 18 // position argument. 19 func Set64(addr *uint64, pos int) { 20 *addr |= (1 << pos) 21 } 22 23 // Clear64 modifies the pointed value by clearing an individual bit at the 24 // position argument. 25 func Clear64(addr *uint64, pos int) { 26 *addr &= ^(1 << pos) 27 } 28 29 // SetTo64 modifies the pointed value by setting an individual bit at the 30 // position argument. 31 func SetTo64(addr *uint64, pos int, val bool) { 32 if val { 33 Set64(addr, pos) 34 } else { 35 Clear64(addr, pos) 36 } 37 } 38 39 // SetN64 modifies the pointed value by setting a value at a specific bit 40 // position and with a bitmask applied. 41 func SetN64(addr *uint64, pos int, mask int, val uint64) { 42 *addr = (*addr & (^(uint64(mask) << pos))) | (val << pos) 43 }