Xilinx MicroBlaze Reference Manual page 23

Embedded development kit edk 14.7
Hide thumbs Also See for MicroBlaze:
Table of Contents

Advertisement

the read and the update. Other devices can read from the semaphore location during the operation.
For a semaphore operation to work properly, the LWX instruction must be paired with an SWX
instruction, and both must specify identical addresses. The reservation granularity in MicroBlaze is
a word. For both instructions, the address must be word aligned. No unaligned exceptions are
generated for these instructions.
The conditional store is always performed when a reservation exists, even if the store address does
not match the load address that set the reservation.
Only one reservation can be maintained at a time. The address associated with the reservation can be
changed by executing a subsequent LWX instruction. The conditional store is performed based upon
the reservation established by the last LWX instruction executed. Executing an SWX instruction
always clears a reservation held by the processor, whether the address matches that established by
the LWX or not.
Reset, interrupts, exceptions, and breaks (including the BRK and BRKI instructions) all clear the
reservation.
The following provides general guidelines for using the LWX and SWX instructions:
MicroBlaze Processor Reference Guide
UG081 (v14.7)
The LWX and SWX instructions should be paired and use the same address.
An unpaired SWX instruction to an arbitrary address can be used to clear any reservation held
by the processor.
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
r5,r3,r0
bnei
r5,next
addik r5,r5,1
swx
r5,r3,r0
addic r5,r0,0
bnei
r5,loop
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
r5,r3,r0
bnei
r5,loop
lwx
r5,r3,r0
bnei
r5,loop
addik r5,r5,1
swx
r5,r3,r0
addic r5,r0,0
bnei
r5,loop
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.
www.xilinx.com
; load and reserve
; branch if not equal to zero
; increment value
; try to store non-zero value
; check reservation
; loop if reservation lost
; load the word
; loop back if word not equal to 0
; try reserving again
; likely that no branch is needed
; increment value
; try to store non-zero value
; check reservation
; loop if reservation lost
Instructions
23
Send Feedback

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the MicroBlaze and is the answer not in the manual?

Table of Contents