Xilinx MicroBlaze Reference Manual page 23

Hide thumbs Also See for MicroBlaze:
Table of Contents

Advertisement

A conditional sequence begins with an LWX instruction. It can be followed by memory
accesses and/or computations on the loaded value. The sequence ends with an SWX
instruction. In most cases, failure of the SWX instruction should cause a branch back to
the LWX for a repeated attempt.
An LWX instruction can be left unpaired when executing certain synchronization
primitives if the value loaded by the LWX is not zero. An implementation of Test and Set
exemplifies this:
loop: lwx
bnei
addik r5,r5,1
swx
addic r5,r0,0
bnei
next:
Performance can be improved by minimizing looping on an LWX instruction that fails to
return a desired value. Performance can also be improved by using an ordinary load
instruction to do the initial value check. An implementation of a spinlock exemplifies
this:
loop: lw
bnei
lwx
bnei
addik r5,r5,1
swx
addic r5,r0,0
bnei
Minimizing the looping on an LWX/SWX instruction pair increases the likelihood that
forward progress is made. The old value should be tested before attempting the store.
If the order is reversed (store before load), more SWX instructions are executed and
reservations are more likely to be lost between the LWX and SWX instructions.
Self-modifying Code
When using self-modifying code software must ensure that the modified instructions have
been written to memory prior to fetching them for execution. There are several aspects to
consider:
MicroBlaze Processor Reference Guide
UG984 (v2018.2) June 21, 2018
r5,r3,r0
; load and reserve
r5,next
; branch if not equal to zero
; increment value
r5,r3,r0
; try to store non-zero value
; check reservation
r5,loop
; loop if reservation lost
r5,r3,r0
; load the word
r5,loop
; loop back if word not equal to 0
r5,r3,r0
; try reserving again
r5,loop
; likely that no branch is needed
; increment value
r5,r3,r0
; try to store non-zero value
; check reservation
r5,loop
; loop if reservation lost
www.xilinx.com
Chapter 2: MicroBlaze Architecture
Send Feedback
23

Advertisement

Table of Contents
loading

Table of Contents