From e3ae57090f235bd5dc37487b0228c1274d530bd4 Mon Sep 17 00:00:00 2001 From: gwtnz <10123549+gwtnz@users.noreply.github.com> Date: Tue, 11 Feb 2020 08:55:14 -0600 Subject: [PATCH] runtime/volatile: include ReplaceBits method --- src/runtime/volatile/register.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/runtime/volatile/register.go b/src/runtime/volatile/register.go index 57c0e7d2..5be97e7f 100644 --- a/src/runtime/volatile/register.go +++ b/src/runtime/volatile/register.go @@ -57,6 +57,16 @@ func (r *Register8) HasBits(value uint8) bool { return (r.Get() & value) > 0 } +// ReplaceBits is a helper to simplify setting multiple bits high and/or low at +// once. It is the volatile equivalent of: +// +// r.Reg = (r.Reg & ^(mask << pos)) | value << pos +// +// go:inline +func (r *Register8) ReplaceBits(value uint8, mask uint8, pos uint8) { + StoreUint8(&r.Reg, LoadUint8(&r.Reg)&^(mask< 0 } +// ReplaceBits is a helper to simplify setting multiple bits high and/or low at +// once. It is the volatile equivalent of: +// +// r.Reg = (r.Reg & ^(mask << pos)) | value << pos +// +// go:inline +func (r *Register16) ReplaceBits(value uint16, mask uint16, pos uint8) { + StoreUint16(&r.Reg, LoadUint16(&r.Reg)&^(mask< 0 } + +// ReplaceBits is a helper to simplify setting multiple bits high and/or low at +// once. It is the volatile equivalent of: +// +// r.Reg = (r.Reg & ^(mask << pos)) | value << pos +// +// go:inline +func (r *Register32) ReplaceBits(value uint32, mask uint32, pos uint8) { + StoreUint32(&r.Reg, LoadUint32(&r.Reg)&^(mask<