%%
%%Thisfilecontainstlccodeforgenerationof
%%fixedpointaddition,subtraction.
%%
%%Copyright1994-2011TheMathWorks,Inc.
%%
 
%%Function:FixPt_Accumulate==========================================
%%
%%Abstract:
%%FixedPointAccumulation
%%
%%Vc+=Vbor
%%Vc-=Vb
%%
%%Synopsis:
%%FixPt_Accumulate(C,B,roundMode,satMode,doAdd)
%%
%%cLabel=stringthatgivesoutputlvalue
%%cDT=outputdatatype
%%bLabel=stringthatgivesinputrvalue
%%bDT=inputdatatype
%%roundMode=stringspecifyingroundto"Zero","Nearest",etc.
%%satMode=stringspecifying"Wrap"or"Saturate"onoverflow
%%doAdd=boolean0=subtraction,otherwiseaddition
%%
%%Itisrequiredthattheinputandoutputhaveidenticalstoragetypes,
%%identicalscaling,andzerobiases
%%becauseoftheserequirementstheformulasforthe
%%StoredIntegers(notcountingsaturation)aretrivial
%%
%%C+=Bor
%%C-=B
%%
%function FixPt_Accumulate(cLabel,cDT,bLabel,bDT,satMode,doAdd) Output
  %%
  %if !FixPt_DataTypeIsFloat(cDT)
    %%
    %<FixPt_FloatingPointNotSupported(bDT)>/
    %%
    %% Check that storage types and scaling are identical
    %% and biases are zero
    %%
    %if (bDT.Bias != 0) || ...
      (cDT.RequiredBits != bDT.RequiredBits) || ...
      (cDT.IsSigned != bDT.IsSigned ) || ...
      !FixPt_FracSlopesSame(cDT.FracSlope, bDT.FracSlope ) || ...
      (cDT.FixedExp != bDT.FixedExp )
      %%
      %%START_ASSERT
      %<LibReportFatalError("FixPt_Accumulate: Incompatible Input and Output Data Types.")>
      %%END_ASSERT
    %endif
  %endif
  %%
  %if doAdd
    %assign opStr = "FixPtAdd"
  %else
    %assign opStr = "FixPtSubtract"
  %endif
  %%
  %<FixPt_WordLengthLimitationCheck(cDT)>/
  %<FixPt_WordLengthLimitationCheck(bDT)>/
  %%
  %assign vec = FixPt_BinaryOp(opStr, cLabel, cDT, cLabel, cDT, bLabel, bDT, ...
    "Simplest", satMode)
  %%
  %/
  %%
%endfunction %% FixPt_Accumulate
 
 
 
%%Function:FixPt_AccumPos==========================================
%%
%%Abstract:
%%FixedPointPositiveAccumulation
%%
%%Vc+=Vb
%%
%%SeeFixPt_Accumulationformoredetails
%%
%function FixPt_AccumPos(cLabel,cDT,bLabel,bDT,satMode) Output
    %%
    %<FixPt_Accumulate(cLabel,cDT,bLabel,bDT,satMode,1)>/
    %%
%endfunction %% FixPt_AccumPos
 
 
 
%%Function:FixPt_AccumNeg==========================================
%%
%%Abstract:
%%FixedPointNegativeAccumulation
%%
%%Vc+=Vb
%%
%%SeeFixPt_Accumulationformoredetails
%%
%function FixPt_AccumNeg(cLabel,cDT,bLabel,bDT,satMode) Output
    %%
    %<FixPt_Accumulate(cLabel,cDT,bLabel,bDT,satMode,0)>/
    %%
%endfunction %% FixPt_AccumPos
 
 
 
%%Function:FixPt_Accumulate_Easy==========================================
%%
%%Abstract:
%%FixedPointAccumulation
%%
%%Vc+=Vb
%%
%%ThisEASYversionofFixPt_Accumulate
%%Handlesalldatatypesandallscalings.
%%Ifneededitalwaysdoestheconversionfromb'sdatatypeandscaling
%%toc'sdatatypeandscaling.Italsodeclaresalocalvariableto
%%handlethecastifneeded.
%%Thereasontousethe"hard"versionFixPt_Accumulateinsteadof
%%thiseasyversionwouldbetomovethecastsanddeclarationsoutside
%%toamoreefficientand/orreadablelocationinthegeneratedcode.
%%
%function FixPt_Accumulate_Easy(cLabel,cDT,bLabel,bDT,roundMode,satMode,doAdd) Output
    %%
    %% create Bias Free version of output Data Type
    %%
    %copyrecord cNoBiasDT cDT
    %%
    %assign cNoBiasDT.Bias = 0.0
    %%
    %assign castInLabel = "castIn_Accumulate"
    %%
    %openfile gutsOfAdd
    %%
    %assign castInWasUsed = 0
    %%
    %% cast input to outputs data type
    %% add or subtract input from output
    %%
    %assign retVecStr = FixPt_Fix2Fix(castInLabel,cNoBiasDT,...
                                      bLabel, bDT,...
                                      roundMode,satMode)
    %%
    %if SIZE(retVecStr,1) == 3
        %%
        %<FixPt_Accumulate(cLabel, cNoBiasDT,...
                           retVecStr[1],cNoBiasDT,...
                           satMode,doAdd)>/
    %else
        %assign castInWasUsed = 1
        %<FixPt_Accumulate(cLabel, cNoBiasDT,...
                           castInLabel,cNoBiasDT,...
                           satMode,doAdd)>/
    %endif
    %%
    %closefile gutsOfAdd
    %%
    %if castInWasUsed
    {
        %<cNoBiasDT.NativeType> %<castInLabel>;
 
        %<gutsOfAdd>/
    }
    %else
        %<gutsOfAdd>/
    %endif
    %%
%endfunction %% FixPt_Accumulate_Easy
 
 
 
%%Function:FixPt_AccumPos_Easy==========================================
%%
%%Abstract:
%%FixedPointPositiveAccumulation
%%
%%Vc+=Vb
%%
%%SeeFixPt_Accumulation_Easyformoredetails
%%
%function FixPt_AccumPos_Easy(cLabel,cDT,bLabel,bDT,roundMode,satMode) Output
    %%
    %<FixPt_Accumulate_Easy(cLabel,cDT,bLabel,bDT,roundMode,satMode,1)>/
    %%
%endfunction %% FixPt_AccumPos_Easy
 
 
 
%%Function:FixPt_AccumNeg_Easy==========================================
%%
%%Abstract:
%%FixedPointNegativeAccumulation
%%
%%Vc+=Vb
%%
%%SeeFixPt_Accumulation_Easyformoredetails
%%
%function FixPt_AccumNeg_Easy(cLabel,cDT,bLabel,bDT,roundMode,satMode) Output
    %%
    %<FixPt_Accumulate_Easy(cLabel,cDT,bLabel,bDT,roundMode,satMode,0)>/
    %%
%endfunction %% FixPt_AccumPos_Easy