mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-09 13:33:39 +00:00
all: use unsafe.Add instead of unsafe.Pointer(uintptr(...) + ...)
We have an optimization for this specific pattern, but it's really just a hack. With the addition of unsafe.Add in Go 1.17 we can directly specify the intent instead and eventually remove this special case. The code is also easier to read.
This commit is contained in:
committed by
Ron Evans
parent
d98c0afbab
commit
4ec1e58aa6
@@ -34,7 +34,7 @@ func (i Interrupt) Enable() error {
|
||||
esp.INTERRUPT_CORE0.CPU_INT_TYPE.SetBits(1 << i.num)
|
||||
|
||||
// Set default threshold to defaultThreshold
|
||||
reg := (*volatile.Register32)(unsafe.Pointer((uintptr(unsafe.Pointer(&esp.INTERRUPT_CORE0.CPU_INT_PRI_0)) + uintptr(i.num)*4)))
|
||||
reg := (*volatile.Register32)(unsafe.Add(unsafe.Pointer(&esp.INTERRUPT_CORE0.CPU_INT_PRI_0), i.num*4))
|
||||
reg.Set(defaultThreshold)
|
||||
|
||||
// Reset interrupt before reenabling
|
||||
@@ -171,7 +171,7 @@ func handleInterrupt() {
|
||||
mepc := riscv.MEPC.Get()
|
||||
// Useing threshold to temporary disable this interrupts.
|
||||
// FYI: using CPU interrupt enable bit make runtime to loose interrupts.
|
||||
reg := (*volatile.Register32)(unsafe.Pointer((uintptr(unsafe.Pointer(&esp.INTERRUPT_CORE0.CPU_INT_PRI_0)) + uintptr(interruptNumber)*4)))
|
||||
reg := (*volatile.Register32)(unsafe.Add(unsafe.Pointer(&esp.INTERRUPT_CORE0.CPU_INT_PRI_0), interruptNumber*4))
|
||||
thresholdSave := reg.Get()
|
||||
reg.Set(disableThreshold)
|
||||
riscv.Asm("fence")
|
||||
|
||||
Reference in New Issue
Block a user