%%
%%
%%
%%
%%Thisfilecontainstlccodeforgenerationoffixedpoint
%%lookuptables
%%
%%Copyright1994-2013TheMathWorks,Inc.
%%
 
%%
%%createvariabletoindicatethatthisfilehasalreadybeenloaded
%%
%if EXISTS("_FIXPTLOOK_SUPPORT_") == 0
%assign _FIXPTLOOK_SUPPORT_ = 1
 
 
%%Thesefixedpointlookuputilitiesaredesignedtohandle
%%thelookupdatacomingfrommultiple"categories"
%%ThedatacancomefromaRun-Time-Parameter,anInput-Port,
%%orfromalocalvariable.Thelocalvariablecancome
%%inseveralformats.
%%
%%Inorderfortheutilityfunctionstodeterminethe
%%category,thedataisusuallypassedinasatriplet,
%%suchas
%%YData,yDataDT,yDataCategory,...
%%Thethirdargumentalwaysends"DataCategory"and
%%indicatesthecategory.IfyDataCategoryisastring
%%thenthestringindicatesthetypeoflocalvariable
%%beingpassedin(usuallyapointer).Inthesecases,
%%YDatawillbeastringthatgivestherootpartof
%%thevariablename.Theutilitywillusuallydo
%%somethinglikedereferencethepointervariable
%%orappendanindexlike[5]totherootstring.
%%IfDataCategoryisnotastring,thenitmustbe
%%numeric.Anegativevalueindicatesthedatacomes
%%fromaruntimeparameter.Usingthefirstargument
%%fromthetriplet(YData),theelements
%%canbeaccessedinthenormalruntimeparameter"ways"
%%suchas
%%%assignyLeftLabel=LibBlockParameter(YData,"","",index)
%%
%%Anegativevalueindicatesthatthedatacomesfroman
%%inputport.Usingthefirstargumentfromthetriplet(YData),
%%theelementsoftheinputportcanbeaccessedinthenormal"ways"
%%suchas
%%%assignyLeftLabel=LibBlockInputSignal(yDataCategory,"","",index)
%%
 
 
 
%function FixPt_BreakPointInfoDefault() void
    %%
    %createrecord BreakPointInfo { ...
      invariant 0; ...
      knownLength 0; ...
      evenlySpaced 0; ...
      spacingValue -1; ...
      zeroAdjustStr ""; ...
      spacingIsPow2 0; ...
      spacingPow2Exp 0; ...
      valueLo 0; ...
      valueHi 1; ...
      indexHi "" }
    %%
    %return BreakPointInfo
    %%
%endfunction
 
 
 
%function utilUnsignedTypeFromDT(xDT) void
  %%
  %% determine the appropriate size for an unsigned type
  %%
  %if FixPt_DataTypeIsFloat(xDT)
    %%
    %assign unsignType = FixPt_ulong_label
    %%
  %elseif xDT.RequiredBits <= IntegerSizes.IntNumBits
    %%
    %assign unsignType = FixPt_uint_label
    %%
  %else
    %%
    %assign unsignType = FixPt_ulong_label
    %%
  %endif
  %%
  %return unsignType
  %%
%endfunction
 
 
 
%function utilUnsignedTypeFrom2xDT(xDT,yDT) void
  %%
  %% determine the appropriate size for an unsigned type
  %%
  %if FixPt_DataTypeIsFloat">FixPt_DataTypeIsFloat(xDT) || FixPt_DataTypeIsFloat">FixPt_DataTypeIsFloat(yDT)
    %%
    %assign unsignType = FixPt_ulong_label
    %%
  %elseif xDT.RequiredBits <= IntegerSizes.IntNumBits && ...
          yDT.RequiredBits <= IntegerSizes.IntNumBits
    %%
    %assign unsignType = FixPt_uint_label
    %%
  %else
    %%
    %assign unsignType = FixPt_ulong_label
    %%
  %endif
  %%
  %return unsignType
  %%
%endfunction
 
 
 
%function utilFloatOrUnsignedTypeFromDT(xDT) void
  %%
  %% determine the appropriate size for an unsigned type
  %%
  %if FixPt_DataTypeIsFloat(xDT)
    %%
    %assign unsignType = xDT.NativeType
    %%
  %elseif xDT.RequiredBits <= IntegerSizes.IntNumBits
    %%
    %assign unsignType = FixPt_uint_label
    %%
  %else
    %%
    %assign unsignType = FixPt_ulong_label
    %%
  %endif
  %%
  %return unsignType
  %%
%endfunction
 
 
 
%function utilDownCastTempExpression(xDT,expressStr) void
  %%
  %% determine the appropriate size for an unsigned type
  %%
  %if FixPt_DataTypeIsFloat(xDT)
    %%
    %assign retStr = expressStr
    %%
  %elseif xDT.RequiredBits < IntegerSizes.IntNumBits
    %%
    %assign retStr = "((%<xDT.NativeType>)(%<expressStr>))"
    %%
  %else
    %%
    %assign retStr = expressStr
    %%
  %endif
  %%
  %return retStr
  %%
%endfunction
 
 
 
%%Function:FixPt_GetBreakPointInfo========================================
%%
%function FixPt_GetBreakPointInfo(u0DataValue) void
    %%
    %assign BreakPointInfo = FixPt_BreakPointInfoDefault()
    %%
    %if TYPE(u0DataValue[0]) == "String"
      %return BreakPointInfo
    %endif
    %%
    %assign nCols = SIZE(u0DataValue, 1)
    %%
    %assign BreakPointInfo.indexHi = nCols - 1
    %assign BreakPointInfo.indexHi = CAST( "Unsigned", %<BreakPointInfo.indexHi>)
    %%
    %% determine if evenly spaced
    %%
    %assign BreakPointInfo.evenlySpaced = 1
    %%
    %assign BreakPointInfo.valueLo = u0DataValue[0]
    %assign BreakPointInfo.valueHi = u0DataValue[nCols-1]
    %%
    %if BreakPointInfo.valueLo != 0
        %assign BreakPointInfo.zeroAdjustStr = " - (%<BreakPointInfo.valueLo>)"
    %endif
    %%
    %assign xjm1 = BreakPointInfo.valueLo
    %assign xj = u0DataValue[1]
    %%
    %assign BreakPointInfo.spacingValue = xj - xjm1
    %%
    %assign jMax = nCols - 2
    %%
    %foreach j = jMax
        %%
        %assign xjm1 = xj
        %assign xj = u0DataValue[j+2]
        %%
        %if BreakPointInfo.spacingValue != (xj - xjm1)
            %%
            %assign BreakPointInfo.evenlySpaced = 0
            %assign BreakPointInfo.spacingValue = -1
            %assign BreakPointInfo.zeroAdjustStr = ""
            %%
            %break
        %endif
    %endforeach
    %%
    %if BreakPointInfo.evenlySpaced && FixPtLookup_opt_pow2
        %%
        %if TYPE(u0DataValue[0]) != "Real" && TYPE(u0DataValue[0]) != "Real32"
            %%
            %assign spacingIsPow2Vec = LibIsPow2(BreakPointInfo.spacingValue)
            %assign BreakPointInfo.spacingIsPow2 = spacingIsPow2Vec[0]
            %assign BreakPointInfo.spacingPow2Exp = spacingIsPow2Vec[1]
        %endif
    %endif
    %%
    %return BreakPointInfo
    %%
%endfunction %% FixPt_GetBreakPointInfo
 
 
 
%%Function:FixPt_BreakPointInfoCast========================================
%%
%%Abstract:ChangetheBreakPointInfostructuresothatitisbasedon
%%adifferentdatatype.
%%ThisismainlyofuseinLookuptableswheretheinputsignal
%%hasadifferencedatatypethenthatusedforthebreakpoints.
%%TheFixedPointDynamicLook1isanexamplewherethiscanhappen.
%%
%%ReturnsoutBreakPointInfo
%%
%function FixPt_BreakPointInfoCast(u0DataBreakPointInfo,u0DataDT,u0DT) void
    %%
    %<FixPt_CheckInputBreakpointDataTypes(u0DT,u0DataDT)>/
    %%
    %copyrecord u0BreakPointInfo u0DataBreakPointInfo
    %%
    %if u0DT.FixedExp != u0DataDT.FixedExp
        %%
        %if TYPE(u0DataBreakPointInfo.valueLo) == "String" || ...
            TYPE(u0DataBreakPointInfo.valueHi) == "String" || ...
            TYPE(u0DataBreakPointInfo.spacingValue) == "String" || ...
            TYPE(u0DataBreakPointInfo.spacingPow2Exp) == "String"
          %%
          %%START_ASSERT
          %<LibReportFatalError("FixPt_BreakPointInfoCast used improperly. Key fields were not numeric types as required.")>
          %%END_ASSERT
          %%
        %endif
        %%
        %% if scaling is not identical, then the spacing and
        %% zero adjust value need to be changed
        %% Example input is U16 2^-12
        %% breakpoints are U8 2^-8
        %% u0DataBreakPointInfo.valueLo = 0x80 = 128
        %% => Real World 128*2^-8 = 0.5
        %% Adjust u0DataBreakPointInfo.valueLo = 0x80 * 2^(-8-(-12))
        %% = 0x0800 = 2048
        %% => Real World 2048*2^-12 = 0.5
        %%
        %assign adjExponent = u0DataDT.FixedExp-u0DT.FixedExp
        %%
        %assign adjValue = FixPt_Pow2(adjExponent)
        %%
        %if FixPt_DataTypeIsFloat(u0DT)
            %assign castType = "Real"
        %else
            %if u0DataDT.IsSigned
              %assign castType = "Number"
              %assign adjValue = CAST( "Number", adjValue )
            %else
              %assign castType = "Unsigned"
              %assign adjValue = CAST( "Unsigned", adjValue )
            %endif
        %endif
        %%
        %assign u0BreakPointInfo.valueLo = CAST(castType,u0DataBreakPointInfo.valueLo * adjValue)
        %assign u0BreakPointInfo.valueHi = CAST(castType,u0DataBreakPointInfo.valueHi * adjValue)
        %%
        %if u0BreakPointInfo.valueLo != 0
          %assign u0BreakPointInfo.zeroAdjustStr = " - (%<u0BreakPointInfo.valueLo>)"
        %endif
        %%
        %if u0DataBreakPointInfo.evenlySpaced
          %%
          %assign u0BreakPointInfo.spacingValue = CAST(castType,u0DataBreakPointInfo.spacingValue * adjValue)
          %%
          %if u0DataBreakPointInfo.spacingIsPow2
            %assign u0BreakPointInfo.spacingPow2Exp = u0DataBreakPointInfo.spacingPow2Exp + adjExponent
          %endif
        %endif
    %endif
    %%
    %return u0BreakPointInfo
    %%
%endfunction %% FixPt_BreakPointInfoCast
 
 
%%Function:FixPt_getLegacyIsSigned===============================
%%
%function FixPt_getLegacyIsSigned(DT) void
  %%
  %if !fxpIsDataTypeFixPt(DT)
    %return 0
  %else
    %return DT.IsSigned
  %endif
  %%
%endfunction
 
 
%%Function:FixPt_getLegacyRequiredBits===============================
%%
%function FixPt_getLegacyRequiredBits(DT) void
  %%
  %if !fxpIsDataTypeFixPt(DT)
    %return 0
  %else
    %return DT.RequiredBits
  %endif
  %%
%endfunction
 
 
%%Function:FixPt_CheckInputBreakpointDataTypes===============================
%%
%%Forlookuptables,theinputanditscorrespondingbreakpoints
%%arenotrequiredtousetheexactsamedatatypeandscaling
%%however,therearesomerestrictionswhicharecheckedhere.
%%
%function FixPt_CheckInputBreakpointDataTypes(u0DT,u0DataDT) void
    %%
    %assign errStr = ""
    %%
    %if !FixPt_BiasSame(u0DT.Bias,u0DataDT.Bias)
      %%
      %%START_ASSERT
      %assign errStr = errStr + " Input and breakpoints have different biases."
      %%END_ASSERT
      %%
    %endif
    %%
    %if !FixPt_FracSlopesSame( u0DT.FracSlope, u0DataDT.FracSlope )
      %%
      %%START_ASSERT
      %assign errStr = errStr + " Input and breakpoints have different fractional slopes."
      %%END_ASSERT
      %%
    %endif
    %%
    %if ( FixPt_getLegacyIsSigned">FixPt_getLegacyIsSigned(u0DT) && !FixPt_getLegacyIsSigned">FixPt_getLegacyIsSigned(u0DataDT) )
      %%
      %%START_ASSERT
      %assign errStr = errStr + " Input is signed, but breakpoints are unsigned."
      %%END_ASSERT
      %%
    %elseif ( !FixPt_getLegacyIsSigned">FixPt_getLegacyIsSigned(u0DT) && FixPt_getLegacyIsSigned">FixPt_getLegacyIsSigned(u0DataDT) )
      %%
      %%START_ASSERT
      %assign errStr = errStr + " Input is unsigned, but breakpoints are signed."
      %%END_ASSERT
      %%
    %endif
    %%
    %if ( u0DT.FixedExp > u0DataDT.FixedExp )
      %%
      %%START_ASSERT
      %assign errStr = errStr + " Input has less precision than breakpoints."
      %%END_ASSERT
      %%
    %endif
    %%
    %if ( u0DT.FixedExp+FixPt_getLegacyRequiredBits">FixPt_getLegacyRequiredBits(u0DT) < u0DataDT.FixedExp+FixPt_getLegacyRequiredBits">FixPt_getLegacyRequiredBits(u0DataDT) )
      %%
      %%START_ASSERT
      %assign errStr = errStr + " Input has less range than breakpoints."
      %%END_ASSERT
      %%
    %endif
    %%
    %if errStr != ""
        %%
        %%START_ASSERT
        %assign errStr = "Input and its breakpoints have incompatible data types and/or scaling." + errStr
        %%
        %<LibReportFatalError(errStr)>
        %%END_ASSERT
        %%
    %endif
%endfunction %% FixPt_CheckInputBreakpointDataTypes
 
 
 
%%Function:FixPt_IndexSearchProperUseCheck==================================
%%
%function FixPt_IndexSearchProperUseCheck(iLeftLabel,iRghtLabel,u0DT,u0DataDT,searchType) void
    %%
    %assign improperUse = 0
    %%
    %if ( searchType == "Below" ) || ( searchType == "Near" )
        %%
        %% left index must be declared outside this scope in order for this
        %% search to be useful
        %%
        %if ( iLeftLabel == "" )
            %%
            %%START_ASSERT
            %assign improperUse = 1
            %%END_ASSERT
        %endif
        %%
    %elseif searchType == "Above"
        %%
        %% rght index must be declared outside this scope in order for this
        %% search to be useful
        %%
        %if ( iRghtLabel == "" )
            %%
            %%START_ASSERT
            %assign improperUse = 2
            %%END_ASSERT
        %endif
        %%
    %else
        %%
        %% unsupported search type
        %%
        %%START_ASSERT
        %assign improperUse = 3
        %%END_ASSERT
    %endif
    %%
    %<FixPt_CheckInputBreakpointDataTypes(u0DT,u0DataDT)>/
    %%
    %if improperUse != 0
        %%
        %%START_ASSERT
        %<LibReportFatalError("FixPt_IndexSearch used improperly.")>
        %%END_ASSERT
        %%
    %endif
%endfunction %% FixPt_IndexSearchProperUseCheck
 
 
 
%%Function:FixPt_GreaterThanPossible==========================================
%%
%%Determineifasignaloftypeu0DTcouldeverbestrictlygreaterthan
%%thetestvalue.Thisinformationallowsmeaninglessinequalitiestobe
%%removedfromthegeneratedcode.
%%
%%Forfloatingpointcases,itisassumedthattheinequalitywould
%%alwaysbemeaningful.
%%
%function FixPt_GreaterThanPossible(u0DT,testValue) void
    %%
    %if u0DT.RequiredBits <= 32 && !FixPt_DataTypeIsFloat(u0DT)
        %if u0DT.IsSigned
            %assign storedIntMax = FixPt_Pow2(u0DT.RequiredBits-1)-1.0
        %else
            %assign storedIntMax = FixPt_Pow2(u0DT.RequiredBits )-1.0
        %endif
        %%
        %assign hiCheckNeeded = ( storedIntMax > testValue )
    %else
        %assign hiCheckNeeded = 1
    %endif
    %%
    %return hiCheckNeeded
    %%
%endfunction %% FixPt_GreaterThanPossible
 
 
 
%%Function:FixPt_LessThanPossible==========================================
%%
%%Determineifasignaloftypeu0DTcouldeverbestrictlylessthan
%%thetestvalue.Thisinformationallowsmeaninglessinequalitiestobe
%%removedfromthegeneratedcode.
%%
%%Forfloatingpointcases,itisassumedthattheinequalitywould
%%alwaysbemeaningful.
%%
%function FixPt_LessThanPossible(u0DT,testValue) void
    %%
    %if FixPt_DataTypeIsFloat(u0DT)
        %assign loCheckNeeded = 1
    %elseif !u0DT.IsSigned
        %assign storedIntMin = 0
        %assign loCheckNeeded = ( storedIntMin < testValue )
    %elseif u0DT.RequiredBits <= 32
        %assign storedIntMin = -1.0*FixPt_Pow2(u0DT.RequiredBits-1)
        %assign loCheckNeeded = ( storedIntMin < testValue )
    %else
        %assign loCheckNeeded = 1
    %endif
    %%
    %return loCheckNeeded
    %%
%endfunction %% FixPt_LessThanPossible
 
 
 
%%Function:FixPt_HelperVarHiIndex======================
%%
%function FixPt_HelperVarHiIndex(varSource, varCategory) void
    %%
    %% data comes from some type of C variable feed in by user
    %%
    %if TYPE(varCategory) == "String"
      %%
      %%START_ASSERT
      %<LibReportFatalError("FixPt_HelperVarHiIndex used in unsupported way.")>
      %%END_ASSERT
      %%
    %elseif varCategory >= 0
      %%
      %% data comes from a blocks input port
      %%
      %assign varSize = LibBlockInputSignalWidth(varCategory)
      %if TYPE(varSize) == "Vector"
    %%START_ASSERT
        %assign retSize = varSize[1] - 1
    %%END_ASSERT
      %else
        %assign retSize = varSize - 1
      %endif
      %%
    %else
      %%
      %% data comes from a blocks parameter
      %%
      %assign varSize = LibBlockParameterSize(varSource)
      %assign retSize = varSize[1] - 1
      %%
    %endif
    %assign retSize = CAST("Unsigned", %<retSize>)
    %return retSize
    %%
    %%
%endfunction %% FixPt_HelperVarHiIndex
 
 
 
%%Function:FixPt_HelperVarIsComplex======================
%%
%function FixPt_HelperVarIsComplex(varSource, varCategory) void
    %%
    %% data comes from some type of C variable feed in by user
    %%
    %%
    %if TYPE(varCategory) == "String"
      %%
      %% data comes from some type of C variable feed in by user
      %%
      %if varCategory == "real pointer to complex"
        %%
        %assign varIsComplex = 1
        %%
      %else
        %%
        %assign varIsComplex = 0
        %%
      %endif
      %%
    %elseif varCategory >= 0
      %%
      %% data comes from a blocks input port
      %%
      %assign varIsComplex = LibBlockInputSignalIsComplex(varCategory)
      %%
    %else
      %%
      %% data comes from a blocks parameter
      %%
      %assign varIsComplex = LibBlockParameterIsComplex(varSource)
      %%
    %endif
    %%
    %return varIsComplex
    %%
%endfunction %% FixPt_HelperVarIsComplex
 
 
 
%%Function:FixPt_HelperGetVarValue======================
%%
%function FixPt_HelperGetVarValue(ucv,lcv,idx,part,...
                                  varSource, varCategory) void
    %%
    %% data comes from some type of C variable feed in by user
    %%
    %assign widthAnyNonScalarWillDo = 2
    %%
    %assign vecIndex = FixPt_IndexStruct( widthAnyNonScalarWillDo, ucv, lcv, idx)
    %%
    %if varCategory == "pointer"
      %%
      %if FixPt_IndexTrivial(ucv, lcv, idx)
        %%
        %assign ValueLabel = "(*%<varSource>)"
        %%
      %else
        %%
        %assign ValueLabel = varSource + "[" + vecIndex + "]"
        %%
      %endif
      %%
    %elseif varCategory == "variable"
      %%
      %if !FixPt_IndexTrivial(ucv, lcv, idx)
        %%
        %%START_ASSERT
        %<LibReportFatalError("FixPt_HelperGetVarValue used in unsupported way.")>
        %%END_ASSERT
        %%
      %endif
      %%
      %if part == "real"
        %%
        %assign ValueLabel = "%<varSource>.re"
        %%
      %elseif part == "imag"
        %%
        %assign ValueLabel = "%<varSource>.im"
        %%
      %else
        %%
        %assign ValueLabel = varSource
        %%
      %endif
      %%
    %else %%if yDataCategory == "real pointer to complex"
      %%
      %if part == "real"
        %%
        %if FixPt_IndexTrivial(ucv, lcv, idx)
          %%
          %assign ValueLabel = "%<varSource>[0]"
          %%
        %else
          %%
          %assign ValueLabel = "%<varSource>[2*(%<vecIndex>)]"
          %%
        %endif
        %%
      %elseif part == "imag"
        %%
        %if FixPt_IndexTrivial(ucv, lcv, idx)
          %%
          %assign ValueLabel = "%<varSource>[1]"
          %%
        %else
          %%
          %assign ValueLabel = "%<varSource>[2*(%<vecIndex>)+1]"
          %%
        %endif
        %%
      %else
        %%
        %%START_ASSERT
        %<LibReportFatalError("FixPt_HelperGetVarValue used in unsupported way.")>
        %%END_ASSERT
        %%
      %endif
      %%
    %endif
    %%
    %return ValueLabel
    %%
%endfunction %% FixPt_HelperGetVarValue
 
 
 
%%Function:FixPt_HelperGetVarPtr======================
%%
%function FixPt_HelperGetVarPtr(ucv,lcv,idx,part,...
                                  varSource, varCategory) void
    %%
    %% data comes from some type of C variable feed in by user
    %%
    %assign widthAnyNonScalarWillDo = 2
    %%
    %assign vecIndex = FixPt_IndexStruct( widthAnyNonScalarWillDo, ucv, lcv, idx)
    %%
    %if varCategory == "pointer"
      %%
      %if FixPt_IndexTrivial( ucv, lcv, idx)
        %%
        %assign ValueLabel = varSource
        %%
      %else
        %%
        %assign ValueLabel = "(" + varSource + "+(" + vecIndex + "))"
        %%
      %endif
      %%
    %elseif varCategory == "variable"
      %%
      %if !FixPt_IndexTrivial( ucv, lcv, idx)
        %%
        %%START_ASSERT
        %<LibReportFatalError("FixPt_HelperGetVarPtr used in unsupported way.")>
        %%END_ASSERT
        %%
      %endif
      %%
      %if part == "real"
        %%
        %assign ValueLabel = "(&(%<varSource>.re))"
        %%
      %elseif part == "imag"
        %%
        %assign ValueLabel = "(&(%<varSource>.im))"
        %%
      %else
        %%
        %assign ValueLabel = "(&(%<varSource>))"
        %%
      %endif
      %%
    %else %%if yDataCategory == "real pointer to complex"
      %%
      %if part == "real"
        %%
        %if FixPt_IndexTrivial( ucv, lcv, idx)
          %%
          %assign ValueLabel = varSource
          %%
        %else
          %%
          %assign ValueLabel = "(%<varSource>+2*(%<vecIndex>))"
          %%
        %endif
        %%
      %elseif part == "imag"
        %%
        %if FixPt_IndexTrivial( ucv, lcv, idx)
          %%
          %assign ValueLabel = "(%<varSource>+1)"
          %%
        %else
          %%
          %assign ValueLabel = "(%<varSource>+2*(%<vecIndex>)+1)"
          %%
        %endif
        %%
      %else
        %%
        %if FixPt_IndexTrivial( ucv, lcv, idx)
          %%
          %assign ValueLabel = varSource
          %%
        %else
          %%
          %%START_ASSERT
          %<LibReportFatalError("FixPt_HelperGetVarPtr used in unsupported way.")>
          %%END_ASSERT
        %endif
        %%
      %endif
      %%
    %endif
    %%
    %return ValueLabel
    %%
%endfunction %% FixPt_HelperGetVarPtr
 
 
       
%%Function:FixPt_HelperGetRValue======================
%%
%function FixPt_HelperGetRValue(ucv,lcv,idx,part,...
                                varSource, varCategory) void
    %%
    %if TYPE(varCategory) == "String"
      %%
      %% data comes from some type of C variable feed in by user
      %%
      %assign ValueLabel = FixPt_HelperGetVarValue(ucv,lcv,idx,part,varSource,varCategory)
      %%
    %else
      %%
      %if TYPE(ucv) == "String"
        %assign localUcv = ucv
      %else
        %if ISEQUAL(ucv,idx) && ISEQUAL(lcv,"")
          %assign localUcv = ""
        %else
          %assign localUcv = "%<ucv>"
        %endif
      %endif
      %%
      %if part == "real"
        %%
        %assign idxReIm = FLib_ReImIdx(idx,0)
        %%
      %elseif part == "imag"
        %%
        %assign idxReIm = FLib_ReImIdx(idx,1)
        %%
      %else
        %%
        %assign idxReIm = FLib_ReImIdx(idx,-1)
        %%
      %endif
      %%
      %if varCategory >= 0
        %%
        %% data comes from a blocks input port
        %%
        %assign ValueLabel = LibBlockInputSignal(varCategory, localUcv, lcv, idxReIm )
        %%
      %else
        %%
        %% data comes from a blocks parameter
        %%
        %assign ValueLabel = LibBlockParameter(varSource, localUcv, lcv, idxReIm)
        %%
      %endif
    %endif
    %%
    %return ValueLabel
    %%
%endfunction %% FixPt_HelperGetRValue
 
 
 
%%Function:FixPt_HelperGetRValuePtr======================
%%
%function FixPt_HelperGetRValuePtr(ucv,lcv,idx,part,...
                                varSource, varCategory) void
    %%
    %if TYPE(varCategory) == "String"
      %%
      %% data comes from some type of C variable feed in by user
      %%
      %assign ValueLabel = FixPt_HelperGetVarPtr(ucv,lcv,idx,part,varSource,varCategory)
      %%
    %else
      %%
      %if TYPE(ucv) == "String"
        %assign localUcv = ucv
      %else
        %if ISEQUAL(ucv,idx) && ISEQUAL(lcv,"")
          %assign localUcv = ""
        %else
          %assign localUcv = "%<ucv>"
        %endif
      %endif
      %%
      %if part == "real"
        %%
        %assign idxReIm = FLib_ReImIdx(idx,0)
        %%
      %elseif part == "imag"
        %%
        %assign idxReIm = FLib_ReImIdx(idx,1)
        %%
      %else
        %%
        %assign idxReIm = FLib_ReImIdx(idx,-1)
        %%
      %endif
      %%
      %if varCategory >= 0
        %%
        %% data comes from a blocks input port
        %%
        %assign ValueLabel = LibBlockInputSignalAddr(varCategory, localUcv, lcv, idxReIm )
        %%
      %else
        %%
        %% data comes from a blocks parameter
        %%
        %assign nRows = SIZE(varSource.Value, 0)
        %%
        %if SIZE(varSource.Value, 0) > 1
          %if FixPt_IndexTrivial(localUcv, lcv, idx)
            %assign ValueLabel = LibBlockMatrixParameterBaseAddr(varSource)
          %else
            %%
            %%START_ASSERT
            %<LibReportFatalError("For matrix parameters, only support getting the base address.")>
            %%END_ASSERT
            %%
          %endif
        %else
          %if FixPt_IndexTrivial(localUcv, lcv, idx)
            %assign ValueLabel = LibBlockParameterBaseAddr(varSource)
          %else
            %assign ValueLabel = LibBlockParameterAddr(varSource, localUcv, lcv, idxReIm)
          %endif
        %endif
        %%
      %endif
    %endif
    %%
    %return ValueLabel
    %%
%endfunction %% FixPt_HelperGetRValuePtr
 
 
 
%%Function:FixPt_HelperGetLValue======================
%%
%function FixPt_HelperGetLValue(ucv,lcv,idx,part,...
                                varSource, varCategory) void
    %%
    %if TYPE(varCategory) == "String"
      %%
      %% data comes from some type of C variable feed in by user
      %%
      %assign ValueLabel = FixPt_HelperGetVarValue(ucv,lcv,idx,part,varSource,varCategory)
      %%
    %else
      %%
      %if TYPE(ucv) == "String"
        %assign localUcv = ucv
      %else
        %if ISEQUAL(ucv,idx) && ISEQUAL(lcv,"")
          %assign localUcv = ""
        %else
          %assign localUcv = "%<ucv>"
        %endif
      %endif
      %%
      %if part == "real"
        %%
        %assign idxReIm = FLib_ReImIdx(idx,0)
        %%
      %elseif part == "imag"
        %%
        %assign idxReIm = FLib_ReImIdx(idx,1)
        %%
      %else
        %%
        %assign idxReIm = FLib_ReImIdx(idx,-1)
        %%
      %endif
      %%
      %if varCategory >= 0
        %%
        %% data comes from a blocks input port
        %%
        %assign ValueLabel = LibBlockOutputSignal(varCategory, localUcv, lcv, idxReIm )
        %%
      %else
        %%
        %% data comes from a blocks parameter
        %%
        %%START_ASSERT
        %<LibReportFatalError("FixPt_HelperGetLValue used in unsupported way. Parameters can not be written to.")>
        %%END_ASSERT
        %%
      %endif
    %endif
    %%
    %return ValueLabel
    %%
%endfunction %% FixPt_HelperGetLValue
 
 
 
%%Function:FixPt_HelperInterpolateOutputEqualsDataPoint======================
%%
%function FixPt_HelperInterpolateOutputEqualsDataPoint(index,...
                             yLabel,yDT,yCategory,...
                             YData, yDataDT, yDataCategory,...
                             roundMode,satMode) Output
  %%
  %% set output equal to value in table
  %%
  %assign yDataIsComplex = FixPt_HelperVarIsComplex(YData, yDataCategory)
  %%
  %if yDataIsComplex
    %%
    %assign outLabel = FixPt_HelperGetLValue("", "",0, "real", yLabel, yCategory )
    %assign inLabel = FixPt_HelperGetRValue(index,"",0, "real", YData, yDataCategory)
    %%
    %<FixPt_Fix2FixAlwaysOutput(outLabel,yDT,inLabel,yDataDT,roundMode,satMode)>/
    %%
    %assign outLabel = FixPt_HelperGetLValue("", "",0, "imag", yLabel, yCategory )
    %assign inLabel = FixPt_HelperGetRValue(index,"",0, "imag", YData, yDataCategory)
    %%
    %<FixPt_Fix2FixAlwaysOutput(outLabel,yDT,inLabel,yDataDT,roundMode,satMode)>/
    %%
  %else
    %%
    %assign outLabel = FixPt_HelperGetLValue("", "",0, "", yLabel, yCategory )
    %assign inLabel = FixPt_HelperGetRValue(index,"",0, "", YData, yDataCategory)
    %%
    %<FixPt_Fix2FixAlwaysOutput(outLabel,yDT,inLabel,yDataDT,roundMode,satMode)>/
    %%
  %endif
%endfunction %% FixPt_HelperInterpolateOutputEqualsDataPoint
 
 
 
%%Function:LibIsPow2==========================================
%%
%%Abstract:
%%Determineifanumberisapowerof(plus)two.
%%Ifitisapoweroftwo,alsoreturntheexponent.
%%
%%NOTE:ThisisforusewiththestoredINTEGER,sonegative
%%powersoftwoareNOTrelavent!!!
%%
%%ThiscouldproduceerrorsifTLC'slargestintegertypehas
%%fewerbitsthanthetargetslong.
%%
%%returns
%%outValueVector(2)
%%
%%outValue[0]Booleantrueforpowof2
%%outValue[1]Numberpowof2exponent
%%
%function LibIsPow2(num) void
    %%
    %% set default return variable
    %%
    %assign outValue = [ 0, 0 ]
    %%
    %% only process inputs of TYPE == Number or Unsigned
    %%
    %if ( TYPE(num) == "Number" ) || ( TYPE(num) == "Unsigned" )
        %%
        %% recursively search for a match on a power of two
        %%
        %assign curPow2 = 1
        %%
        %foreach ipow = ( IntegerSizes.LongNumBits - 1 )
            %%
            %% stop search early if number is smaller than current pow2
            %%
            %if num < curPow2
                %%
                %break
                %%
            %endif
            %%
            %% stop search if match is found
            %%
            %if num == curPow2
                %%
                %assign outValue = [ 1, %<ipow> ]
                %%
                %break
                %%
            %endif
            %%
            %% get next power of two
            %%
            %assign curPow2 = curPow2 << 1
            %%
        %endforeach
        %%
    %endif
    %%
    %return outValue
    %%
%endfunction %% LibIsPow2
 
 
 
%function FixPt_IndexTrivial(ucv, lcv, idx) void
  %%
  %if TYPE(ucv) != "String"
    %%
    %assign ucvStr = "%<ucv>"
    %%
  %else
    %%
    %assign ucvStr = ucv
    %%
  %endif
  %%
  %return ( ucvStr == "" || ucvStr == "0" ) && lcv == "" && ISEQUAL(idx,0)
  %%
%endfunction %% FixPt_IndexTrivial
 
 
 
%%Function:FixPt_BiasSame==================================
%%
%%Abstract:Determineiftwodatatypesarethesame
%%
%function FixPt_BiasSame(aBias,bBias)
    %%
    %if aBias == bBias
        %%
        %return 1
        %%
    %endif
    %%
    %if aBias > bBias
        %%
        %assign berror = ( aBias - bBias )
        %%
    %else
        %%
        %assign berror = ( bBias - aBias )
        %%
    %endif
    %%
    %% 2^-33 = 1.164153218269348e-010
    %%
    %return ( berror < 1.164153218269348e-010 )
    %%
%endfunction %% FixPt_BiasSame
 
 
 
%%Function:FixPt_GetInputDataTypeWithBoolReplace======================================
%%
%%Abstract:
%%Forthespecifiedinputport,returnanaliastothecorresponding
%%DataTypesrecord
%%Ifboolean,replacewithuint8
%%
%function FixPt_GetInputDataTypeWithBoolReplace(portIdx) void
  %%
  %assign dataTypeIdx = LibGetDataTypeIdAliasedThruToFromId(LibBlockInputSignalDataTypeId(portIdx))
  %%
  %if dataTypeIdx == tSS_BOOLEAN
    %%
    %assign curDT = FixPt_GetDataTypeFromIndex(tSS_UINT8)
  %else
    %assign curDT = FixPt_GetDataTypeFromIndex(dataTypeIdx)
  %endif
  %%
  %return curDT
  %%
%endfunction %% FixPt_GetInputDataType
 
 
 
%%Function:FixPt_ParameterCouldBeInlined=============================================
%%
%%Thisfunctionsisonlyastopgapmeasure!!!!!
%%Thefunctionneedstodetermineifaparametersvaluecannotchange
%%atruntime.
%%Thecurrentversionworksforthemomentbecausefixedpointblockset
%%doesnotsupporttunableparametersyet(Feb29,2000).Withinapprox
%%threeweeks,fixedpointwillsupport(atleastsimple)tunableparameters.
%%ThisfunctionwillgiveWRONGresultsatthattime.
%%
%function FixPt_ParameterCouldBeInlined(param, ucv, lcv, idx) void
    %%
    %return ( !SLibBlockParameterIsTunable(param) && ( lcv == "" ) && ( ucv == "" ))
    %%
%endfunction
 
 
 
%function FixPt_UtilityNameAppendDTPair(utilityName,aDT,bDT) void
  %%
  %assign utilityName = utilityName + "_" + FixPt_helperUtilityNameAppendDT(aDT)
  %%
  %if !FixPt_SpecifiedContainerSame(aDT,bDT)
    %%
    %assign utilityName = utilityName + FixPt_helperUtilityNameAppendDT(bDT)
  %endif
  %%
  %assign ExPrec = bDT.FixedExp - aDT.FixedExp
  %if ExPrec < 0
    %assign utilityName = utilityName + "L"
    %assign utilityName = utilityName + STRING(-ExPrec)
  %elseif ExPrec > 0
    %assign utilityName = utilityName + "R"
    %assign utilityName = utilityName + STRING(ExPrec)
  %endif
  %%
  %if aDT.FracSlope != bDT.FracSlope
    %%
    %%START_ASSERT
    %<LibReportFatalError("FixPt_UtilityNameAppendDTPair used improperly. The fractional slopes of the two data types must be the same.")>
    %%END_ASSERT
    %%
  %endif
  %%
  %if aDT.Bias != bDT.Bias
    %%
    %%START_ASSERT
    %<LibReportFatalError("FixPt_UtilityNameAppendDTPair used improperly. The biases of the two data types must be the same.")>
    %%END_ASSERT
    %%
  %endif
  %%
  %return utilityName
  %%
%endfunction %% FixPt_UtilityNameAppendDTPair
 
 
%function FixPt_UtilityNameAppendMode(utilityName,roundMode,satMode) void
  %%
  %if satMode == "Saturate"
    %assign utilityName = utilityName + "_SAT"
  %else
    %%%assign utilityName = utilityName + "_WRAP"
  %endif
  %%
  %if roundMode == "Zero"
    %assign utilityName = utilityName + "_ZERO"
  %elseif roundMode == "Nearest"
    %assign utilityName = utilityName + "_NEAR"
  %elseif roundMode == "Ceiling"
    %assign utilityName = utilityName + "_CEILING"
  %elseif roundMode == "Floor"
    %% do not append name
    %%%assign utilityName = utilityName + "_FLOOR"
    %% do not append name
  %elseif roundMode == "Simplest"
    %assign utilityName = utilityName + "_SIMPLEST"
  %elseif roundMode == "Round"
    %assign utilityName = utilityName + "_ROUND"
  %elseif roundMode == "Convergent"
    %assign utilityName = utilityName + "_CONVERGENT"
  %elseif roundMode == ""
    %% do not append name
    %% rounding not relavent
    %%
  %else
    %assign utilityName = utilityName + "_ROUNDERROR"
  %endif
  %%
  %return utilityName
  %%
%endfunction %% FixPt_UtilityNameAppendDT
 
 
%endif %% _FIXPTLOOK_SUPPORT_