www.ti.com
2.3.3AlgorithmversusApplication
Persistent
Scratch
Shared Private
Shadow
DataMemory
Guideline1
Algorithmsshouldminimizetheirpersistentdatamemoryrequirementsinfavorofscratchmemory.
Inadditiontothetypesofmemorydescribedabove,thereareoftenseveralmemoryspacesprovidedbya
DSPtoalgorithms.
•Dual-accessmemory(DARAM)ison-chipmemorythatallowstwosimultaneousaccessesinasingle
instructioncycle.
•Single-accessmemory(SARAM)ison-chipmemorythatallowsonlyasingleaccessperinstruction
cycle.
•ExternalmemoryismemorythatisexternaltotheDSPandmayrequiremorethanzerowaitstates
peraccess.
Thesememoryspacesareoftentreatedverydifferentlybyalgorithmimplementations;inordertooptimize
performance,frequentlyaccesseddataisplacedinon-chipmemory,forexample.Thescratchversus
persistentattributeofablockofmemoryisindependentofthememoryspace.Thus,therearesixdistinct
memoryclasses;scratchandpersistentforeachofthethreememoryspacesdescribedabove.
Otherthanamemoryblock'ssize,alignment,andmemoryspace,threeindependentquestionsmustbe
answeredbeforeaclientcanproperlymanageablockofanalgorithm'sdatamemory.
•Istheblockofmemorytreatedasscratchorpersistentbythealgorithm?
•Istheblockofmemorysharedbymorethanonealgorithm?
•Dothealgorithmsthatsharetheblockpreemptoneanother?
Thefirstquestionisdeterminedbytheimplementationofthealgorithm;thealgorithmmustbewrittenwith
assumptionsaboutthecontentsofcertainmemorybuffers.We'vearguedthatthereissignificantbenefitto
distinguishbetweenscratchmemoryandpersistentmemory,butitisuptothealgorithmimplementation
totradethebenefitsofincreasingscratch,anddecreasingpersistentmemoryagainstthepotential
performanceoverheadincurredbyre-computingintermediateresults.
Thesecondtwoquestionsregardingsharingandpreemption,canonlybeansweredbytheclientofan
eXpressDSP-compliantalgorithm.Theclientdecideswhetherpreemptionisrequiredforthesystemand
theclientallocatesallmemory.Thus,onlytheclientknowswhethermemoryissharedamongalgorithms.
Someframeworks,forexample,nevershareanyallocatedmemoryamongalgorithmswhereasothers
alwayssharescratchmemory.
Thereisaspecialtypeofpersistentmemorymanagedbyclientsofalgorithmsthatisworthdistinguishing:
shadowmemoryisunsharedpersistentmemorythatisusedtoshadoworsavethecontentsofshared
registersandmemoryinasystem.Shadowmemoryisnotusedbyalgorithms;itisusedbytheirclientsto
savethememoryregionssharedbyvariousalgorithms.
Figure2-2illustratestherelationshipbetweenthevarioustypesofmemory.
Figure2-2.DataMemoryTypes
GeneralProgrammingGuidelines 22SPRU352G–June2005–RevisedFebruary2007
SubmitDocumentationFeedback