www.ti.com
4.1.2StackMemory
4.1.3StaticLocalandGlobalDataMemory
DataMemory
Intheexampleabove,thealgorithmrequires96016-bitwordsofsingle-accesson-chipmemory,720
16-bitwordsofexternalpersistentmemory,andtherearenospecialalignmentrequirementsforthis
memory.Notethattheentriesinthistablearenotrequiredtobeconstants;theymaybefunctionsof
algorithminstancecreationparameters.
Inadditiontobulk"heap"memory,algorithmsoftenmakeuseofthestackforveryefficientallocationof
temporarystorage.Formostreal-timesystems,thetotalamountofstackmemoryforathreadissetonce
(eitherwhentheprogramisbuiltorwhenthethreadiscreated)andneverchangesduringexecutionof
thethread.Thisisdonetoensuredeterministicexecutionofthethread.Itisimportant,therefore,thatthe
systemintegratorknowtheworst-casestackspacerequirementsforeveryalgorithm.
Rule20
Allalgorithmsmustcharacterizetheirworst-casestackspacememoryrequirements(including
alignment).
Stackspacerequirementsforanalgorithmmustbecharacterizedusingatablesuchasthatshownbelow.
SizeAlign
StackSpace4000
Boththesizeandalignmentfieldsshouldbeexpressedinunitsof8-bitbytes.Ifnospecialalignmentis
required,thealignmentnumbershouldbesettozero.
Intheexampleabove,thealgorithmrequires20016-bitwordsofstackmemoryandthereisnospecial
alignmentrequirementforthismemory.Notethattheentryinthistablearenotrequiredtobeaconstant;
itmaybefunctionofthealgorithm'sinstancecreationparameters.
Onewaytoachievereentrancyinafunctionistodeclareallscratchdataobjectsonthelocalstack.Ifthe
stackisinon-chipmemorythisprovideseasyaccesstofastscratchmemory.
Theproblemwiththisapproachtoreentrancyisthat,ifcarriedtoofar,itmayrequireaverylargestack.
Whilethisisnotaproblemforsinglethreadedapplications,traditionalmulti-threadedapplicationsmust
allocateaseparatestackforeachthread.Itisunlikelythatmorethanafewthesestackswillfitinon-chip
memory.Moreover,eveninasinglethreadedenvironment,analgorithmhasnocontroloverthe
placementofthesystemstack;itmayendupwitheasyaccesstoveryslowmemory.
TheseproblemscanbeavoidedbyalgorithmstakingadvantageoftheIALGinterfacetodeclaretheir
scratchdatamemoryrequirements.Thisgivestheapplicationthechancetodecidewhethertoallocate
thememoryfromthestackortheheap,whicheverisbestforthesystemoverall.
Guideline5
Algorithmsshouldkeepstacksizerequirementstoaminimum.
Staticdatamemoryisanydatamemorythatisallocatedandplacedwhentheprogramisbuiltand
remainsfixedduringprogramexecution.InmanyDSParchitectures,therearespecialinstructionsthat
canbeusedtoaccessstaticdataveryefficientlybyencodingtheaddressofthedataintheinstruction's
opcode.Therefore,oncetheprogramisbuilt,thismemorycannotbemoved.
Rule21
Algorithmsmustcharacterizetheirstaticdatamemoryrequirements.
SPRU352G–June2005–RevisedFebruary2007AlgorithmPerformanceCharacterization39
SubmitDocumentationFeedback