runtime/volatile: include ReplaceBits method

Этот коммит содержится в:
gwtnz 2020-02-11 08:55:14 -06:00 коммит произвёл GitHub
родитель a0cdd6b4ed
коммит e3ae57090f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23

Просмотреть файл

@ -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)
}