mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-08 13:03:39 +00:00
runtime/volatile: include ReplaceBits method
This commit is contained in:
@@ -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<<pos)|value<<pos)
|
||||
}
|
||||
|
||||
type Register16 struct {
|
||||
Reg uint16
|
||||
}
|
||||
@@ -109,6 +119,16 @@ func (r *Register16) HasBits(value uint16) 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 *Register16) ReplaceBits(value uint16, mask uint16, pos uint8) {
|
||||
StoreUint16(&r.Reg, LoadUint16(&r.Reg)&^(mask<<pos)|value<<pos)
|
||||
}
|
||||
|
||||
type Register32 struct {
|
||||
Reg uint32
|
||||
}
|
||||
@@ -160,3 +180,13 @@ func (r *Register32) ClearBits(value uint32) {
|
||||
func (r *Register32) HasBits(value uint32) 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 *Register32) ReplaceBits(value uint32, mask uint32, pos uint8) {
|
||||
StoreUint32(&r.Reg, LoadUint32(&r.Reg)&^(mask<<pos)|value<<pos)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user