From 8c60b4def4663915726342c70d62265d124bded2 Mon Sep 17 00:00:00 2001 From: Ethan Reesor Date: Sun, 12 Jul 2020 19:16:54 -0500 Subject: [PATCH] runtime/volatile: add GetBits --- src/runtime/volatile/register.go | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/runtime/volatile/register.go b/src/runtime/volatile/register.go index adfe372e..a2ec6b35 100644 --- a/src/runtime/volatile/register.go +++ b/src/runtime/volatile/register.go @@ -67,6 +67,16 @@ func (r *Register8) ReplaceBits(value uint8, mask uint8, pos uint8) { StoreUint8(&r.Reg, LoadUint8(&r.Reg)&^(mask<> pos) & mask +// +// go:inline +func (r *Register8) GetBits(mask uint8, pos uint8) uint8 { + return (LoadUint8(&r.Reg) >> pos) & mask +} + type Register16 struct { Reg uint16 } @@ -129,6 +139,16 @@ func (r *Register16) ReplaceBits(value uint16, mask uint16, pos uint8) { StoreUint16(&r.Reg, LoadUint16(&r.Reg)&^(mask<> pos) & mask +// +// go:inline +func (r *Register16) GetBits(mask uint16, pos uint8) uint16 { + return (LoadUint16(&r.Reg) >> pos) & mask +} + type Register32 struct { Reg uint32 } @@ -191,6 +211,16 @@ func (r *Register32) ReplaceBits(value uint32, mask uint32, pos uint8) { StoreUint32(&r.Reg, LoadUint32(&r.Reg)&^(mask<> pos) & mask +// +// go:inline +func (r *Register32) GetBits(mask uint32, pos uint8) uint32 { + return (LoadUint32(&r.Reg) >> pos) & mask +} + type Register64 struct { Reg uint64 } @@ -252,3 +282,13 @@ func (r *Register64) HasBits(value uint64) bool { func (r *Register64) ReplaceBits(value uint64, mask uint64, pos uint8) { StoreUint64(&r.Reg, LoadUint64(&r.Reg)&^(mask<> pos) & mask +// +// go:inline +func (r *Register64) GetBits(mask uint64, pos uint8) uint64 { + return (LoadUint64(&r.Reg) >> pos) & mask +}