Texas Instruments TMS320 DSP Computer Hardware User Manual


 
www.ti.com
Scratch
Algorithm A
Scratch
Algorithm B
Write-Once C
Scratch
Algorithm C
Scratch
Physical
Memory
Persistent B
Persistent A
Persistent A Persistent B Write-Once C
0000
FFFF
0
1
Algorithm C
Scratch
Scratch
Write-Once C
DataMemory
Noticethatbotha()andb()freelyusesomeofthesamescratchregistersandnosavingandrestoringof
theseregistersisnecessary.Thisispossiblebecausebothfunctions,a()andb(),agreeonthesetof
scratchregistersandthatvaluesintheseregistersareindeterminateatthebeginningofeachfunction.
Byanalogy,wepartitionallmemoryintotwogroups:scratchandpersistent.
Scratchmemoryismemorythatisfreelyusedbyanalgorithmwithoutregardtoitspriorcontents,i.e.,
noassumptionsaboutthecontentcanbemadebythealgorithmandthealgorithmisfreetoleaveitin
anystate.
Persistentmemoryisusedtostorestateinformationwhileanalgorithminstanceisnotexecuting.
Persistentmemoryisanyareaofmemorythatanalgorithmcanwritetoassumethatthecontentsare
unchangedbetweensuccessiveinvocationsofthealgorithmwithinanapplication.Allphysicalmemory
hasthisbehavior,butapplicationsthatsharememoryamongmultiplealgorithmsmayopttooverwrite
someregionsofmemory(e.g.,on-chipDARAM).
Aspecialvariantofpersistentmemoryisthewrite-oncepersistentmemory.Analgorithm'sinitialization
functionensuresthatitswrite-oncebuffersareinitializedduringinstancecreationandthatallsubsequent
accessesbythealgorithm'sprocessingtowrite-oncebuffersarestrictlyread-only.Additionally,the
algorithmcanlinkitsownstaticallyallocatedwrite-oncebuffersandprovidethebufferaddressestothe
client.Theclientisfreetouseprovidedbuffersorallocateitsown.Frameworkscanoptimizememory
allocationbyarrangingmultipleinstancesofthesamealgorithm,createdwithidenticalcreation
parameters,tosharewrite-oncebuffers.
Notethatasimpleralternativetodeclaringwrite-oncebuffersforsharingstaticallyinitializedread-only
dataistouseglobalstaticallylinkedconstanttablesandpublishtheiralignmentandmemoryspace
requirementsintherequiredstandardalgorithmdocumentation.Ifdatahastobecomputedorrelocatedat
run-time,thewrite-oncebuffersapproachcanbeemployed.
Theimportanceofmakingadistinctionbetweenscratchmemoryandpersistentmemoryisillustratedin
Figure2-1.
Figure2-1.ScratchvsPersistentMemoryAllocation
Allalgorithmscratchmemorycanbe"overlaid"onthesamephysicalmemory.Withoutthedistinction
betweenscratchandpersistentmemory,itwouldbenecessarytostrictlypartitionmemoryamong
algorithms,makingthetotalmemoryrequirementthesumofallalgorithms'memoryrequirements.Onthe
otherhand,bymakingthedistinction,thetotalmemoryrequirementforacollectionofalgorithmsisthe
sumofeachalgorithm'sdistinctpersistentmemory,plusanysharedwrite-oncepersistentmemory,plus
themaximumscratchmemoryrequirementofanyofthesealgorithms.
SPRU352GJune2005RevisedFebruary2007GeneralProgrammingGuidelines21
SubmitDocumentationFeedback