diff options
author | Yannis Huber <[email protected]> | 2020-06-08 16:47:39 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2020-06-08 16:47:39 +0200 |
commit | 2396c22658275c3df83ac24453e81fb5d252f5e6 (patch) | |
tree | 4ff06229dd68649573e0b76e833a6b1fdf710990 /src | |
parent | d61d5d7ab1beeb7d2ecace8c510ec6bdaece88d8 (diff) | |
download | tinygo-2396c22658275c3df83ac24453e81fb5d252f5e6.tar.gz tinygo-2396c22658275c3df83ac24453e81fb5d252f5e6.zip |
risc-v: add support for 64-bit RISC-V CPUs
Diffstat (limited to 'src')
-rw-r--r-- | src/runtime/volatile/register.go | 64 | ||||
-rw-r--r-- | src/runtime/volatile/volatile.go | 6 |
2 files changed, 69 insertions, 1 deletions
diff --git a/src/runtime/volatile/register.go b/src/runtime/volatile/register.go index 5be97e7fd..adfe372ee 100644 --- a/src/runtime/volatile/register.go +++ b/src/runtime/volatile/register.go @@ -1,6 +1,6 @@ package volatile -// This file defines Register{8,16,32} types, which are convenience types for +// This file defines Register{8,16,32,64} types, which are convenience types for // volatile register accesses. // Special types that causes loads/stores to be volatile (necessary for @@ -190,3 +190,65 @@ func (r *Register32) HasBits(value uint32) bool { func (r *Register32) ReplaceBits(value uint32, mask uint32, pos uint8) { StoreUint32(&r.Reg, LoadUint32(&r.Reg)&^(mask<<pos)|value<<pos) } + +type Register64 struct { + Reg uint64 +} + +// Get returns the value in the register. It is the volatile equivalent of: +// +// *r.Reg +// +//go:inline +func (r *Register64) Get() uint64 { + return LoadUint64(&r.Reg) +} + +// Set updates the register value. It is the volatile equivalent of: +// +// *r.Reg = value +// +//go:inline +func (r *Register64) Set(value uint64) { + StoreUint64(&r.Reg, value) +} + +// SetBits reads the register, sets the given bits, and writes it back. It is +// the volatile equivalent of: +// +// r.Reg |= value +// +//go:inline +func (r *Register64) SetBits(value uint64) { + StoreUint64(&r.Reg, LoadUint64(&r.Reg)|value) +} + +// ClearBits reads the register, clears the given bits, and writes it back. It +// is the volatile equivalent of: +// +// r.Reg &^= value +// +//go:inline +func (r *Register64) ClearBits(value uint64) { + StoreUint64(&r.Reg, LoadUint64(&r.Reg)&^value) +} + +// HasBits reads the register and then checks to see if the passed bits are set. It +// is the volatile equivalent of: +// +// (*r.Reg & value) > 0 +// +//go:inline +func (r *Register64) HasBits(value uint64) 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 *Register64) ReplaceBits(value uint64, mask uint64, pos uint8) { + StoreUint64(&r.Reg, LoadUint64(&r.Reg)&^(mask<<pos)|value<<pos) +} diff --git a/src/runtime/volatile/volatile.go b/src/runtime/volatile/volatile.go index 47262f347..ce5e69774 100644 --- a/src/runtime/volatile/volatile.go +++ b/src/runtime/volatile/volatile.go @@ -24,6 +24,9 @@ func LoadUint16(addr *uint16) (val uint16) // LoadUint32 loads the volatile value *addr. func LoadUint32(addr *uint32) (val uint32) +// LoadUint64 loads the volatile value *addr. +func LoadUint64(addr *uint64) (val uint64) + // StoreUint8 stores val to the volatile value *addr. func StoreUint8(addr *uint8, val uint8) @@ -32,3 +35,6 @@ func StoreUint16(addr *uint16, val uint16) // StoreUint32 stores val to the volatile value *addr. func StoreUint32(addr *uint32, val uint32) + +// StoreUint64 stores val to the volatile value *addr. +func StoreUint64(addr *uint64, val uint64) |