%if EXISTS("_FIXPTLOOK_SUPPORT_") == 0
%assign _FIXPTLOOK_SUPPORT_ = 1
%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
%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
%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
%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
%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(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>)
%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
%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"
%<LibReportFatalError("FixPt_BreakPointInfoCast used improperly. Key fields were not numeric types as required.")>
%endif
%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
%function FixPt_getLegacyIsSigned(DT) void
%if !fxpIsDataTypeFixPt(DT)
%return 0
%else
%return DT.IsSigned
%endif
%endfunction
%function FixPt_getLegacyRequiredBits(DT) void
%if !fxpIsDataTypeFixPt(DT)
%return 0
%else
%return DT.RequiredBits
%endif
%endfunction
%function FixPt_CheckInputBreakpointDataTypes(u0DT,u0DataDT) void
%assign errStr = ""
%if !FixPt_BiasSame(u0DT.Bias,u0DataDT.Bias)
%assign errStr = errStr + " Input and breakpoints have different biases."
%endif
%if !FixPt_FracSlopesSame( u0DT.FracSlope, u0DataDT.FracSlope )
%assign errStr = errStr + " Input and breakpoints have different fractional slopes."
%endif
%if ( FixPt_getLegacyIsSigned">FixPt_getLegacyIsSigned(u0DT) && !FixPt_getLegacyIsSigned">FixPt_getLegacyIsSigned(u0DataDT) )
%assign errStr = errStr + " Input is signed, but breakpoints are unsigned."
%elseif ( !FixPt_getLegacyIsSigned">FixPt_getLegacyIsSigned(u0DT) && FixPt_getLegacyIsSigned">FixPt_getLegacyIsSigned(u0DataDT) )
%assign errStr = errStr + " Input is unsigned, but breakpoints are signed."
%endif
%if ( u0DT.FixedExp > u0DataDT.FixedExp )
%assign errStr = errStr + " Input has less precision than breakpoints."
%endif
%if ( u0DT.FixedExp+FixPt_getLegacyRequiredBits">FixPt_getLegacyRequiredBits(u0DT) < u0DataDT.FixedExp+FixPt_getLegacyRequiredBits">FixPt_getLegacyRequiredBits(u0DataDT) )
%assign errStr = errStr + " Input has less range than breakpoints."
%endif
%if errStr != ""
%assign errStr = "Input and its breakpoints have incompatible data types and/or scaling." + errStr
%<LibReportFatalError(errStr)>
%endif
%endfunction
%function FixPt_IndexSearchProperUseCheck(iLeftLabel,iRghtLabel,u0DT,u0DataDT,searchType) void
%assign improperUse = 0
%if ( searchType == "Below" ) || ( searchType == "Near" )
%if ( iLeftLabel == "" )
%assign improperUse = 1
%endif
%elseif searchType == "Above"
%if ( iRghtLabel == "" )
%assign improperUse = 2
%endif
%else
%assign improperUse = 3
%endif
%<FixPt_CheckInputBreakpointDataTypes(u0DT,u0DataDT)>/
%if improperUse != 0
%<LibReportFatalError("FixPt_IndexSearch used improperly.")>
%endif
%endfunction
%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
%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
%function FixPt_HelperVarHiIndex(varSource, varCategory) void
%if TYPE(varCategory) == "String"
%<LibReportFatalError("FixPt_HelperVarHiIndex used in unsupported way.")>
%elseif varCategory >= 0
%assign varSize = LibBlockInputSignalWidth(varCategory)
%if TYPE(varSize) == "Vector"
%assign retSize = varSize[1] - 1
%else
%assign retSize = varSize - 1
%endif
%else
%assign varSize = LibBlockParameterSize(varSource)
%assign retSize = varSize[1] - 1
%endif
%assign retSize = CAST("Unsigned", %<retSize>)
%return retSize
%endfunction
%function FixPt_HelperVarIsComplex(varSource, varCategory) void
%if TYPE(varCategory) == "String"
%if varCategory == "real pointer to complex"
%assign varIsComplex = 1
%else
%assign varIsComplex = 0
%endif
%elseif varCategory >= 0
%assign varIsComplex = LibBlockInputSignalIsComplex(varCategory)
%else
%assign varIsComplex = LibBlockParameterIsComplex(varSource)
%endif
%return varIsComplex
%endfunction
%function FixPt_HelperGetVarValue(ucv,lcv,idx,part,...
varSource, varCategory) void
%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)
%<LibReportFatalError("FixPt_HelperGetVarValue used in unsupported way.")>
%endif
%if part == "real"
%assign ValueLabel = "%<varSource>.re"
%elseif part == "imag"
%assign ValueLabel = "%<varSource>.im"
%else
%assign ValueLabel = varSource
%endif
%else
%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
%<LibReportFatalError("FixPt_HelperGetVarValue used in unsupported way.")>
%endif
%endif
%return ValueLabel
%endfunction
%function FixPt_HelperGetVarPtr(ucv,lcv,idx,part,...
varSource, varCategory) void
%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)
%<LibReportFatalError("FixPt_HelperGetVarPtr used in unsupported way.")>
%endif
%if part == "real"
%assign ValueLabel = "(&(%<varSource>.re))"
%elseif part == "imag"
%assign ValueLabel = "(&(%<varSource>.im))"
%else
%assign ValueLabel = "(&(%<varSource>))"
%endif
%else
%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
%<LibReportFatalError("FixPt_HelperGetVarPtr used in unsupported way.")>
%endif
%endif
%endif
%return ValueLabel
%endfunction
%function FixPt_HelperGetRValue(ucv,lcv,idx,part,...
varSource, varCategory) void
%if TYPE(varCategory) == "String"
%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
%assign ValueLabel = LibBlockInputSignal(varCategory, localUcv, lcv, idxReIm )
%else
%assign ValueLabel = LibBlockParameter(varSource, localUcv, lcv, idxReIm)
%endif
%endif
%return ValueLabel
%endfunction
%function FixPt_HelperGetRValuePtr(ucv,lcv,idx,part,...
varSource, varCategory) void
%if TYPE(varCategory) == "String"
%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
%assign ValueLabel = LibBlockInputSignalAddr(varCategory, localUcv, lcv, idxReIm )
%else
%assign nRows = SIZE(varSource.Value, 0)
%if SIZE(varSource.Value, 0) > 1
%if FixPt_IndexTrivial(localUcv, lcv, idx)
%assign ValueLabel = LibBlockMatrixParameterBaseAddr(varSource)
%else
%<LibReportFatalError("For matrix parameters, only support getting the base address.")>
%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
%function FixPt_HelperGetLValue(ucv,lcv,idx,part,...
varSource, varCategory) void
%if TYPE(varCategory) == "String"
%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
%assign ValueLabel = LibBlockOutputSignal(varCategory, localUcv, lcv, idxReIm )
%else
%<LibReportFatalError("FixPt_HelperGetLValue used in unsupported way. Parameters can not be written to.")>
%endif
%endif
%return ValueLabel
%endfunction
%function FixPt_HelperInterpolateOutputEqualsDataPoint(index,...
yLabel,yDT,yCategory,...
YData, yDataDT, yDataCategory,...
roundMode,satMode) Output
%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
%function LibIsPow2(num) void
%assign outValue = [ 0, 0 ]
%if ( TYPE(num) == "Number" ) || ( TYPE(num) == "Unsigned" )
%assign curPow2 = 1
%foreach ipow = ( IntegerSizes.LongNumBits - 1 )
%if num < curPow2
%break
%endif
%if num == curPow2
%assign outValue = [ 1, %<ipow> ]
%break
%endif
%assign curPow2 = curPow2 << 1
%endforeach
%endif
%return outValue
%endfunction
%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
%function FixPt_BiasSame(aBias,bBias)
%if aBias == bBias
%return 1
%endif
%if aBias > bBias
%assign berror = ( aBias - bBias )
%else
%assign berror = ( bBias - aBias )
%endif
%return ( berror < 1.164153218269348e-010 )
%endfunction
%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
%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
%<LibReportFatalError("FixPt_UtilityNameAppendDTPair used improperly. The fractional slopes of the two data types must be the same.")>
%endif
%if aDT.Bias != bDT.Bias
%<LibReportFatalError("FixPt_UtilityNameAppendDTPair used improperly. The biases of the two data types must be the same.")>
%endif
%return utilityName
%endfunction
%function FixPt_UtilityNameAppendMode(utilityName,roundMode,satMode) void
%if satMode == "Saturate"
%assign utilityName = utilityName + "_SAT"
%else
%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"
%elseif roundMode == "Simplest"
%assign utilityName = utilityName + "_SIMPLEST"
%elseif roundMode == "Round"
%assign utilityName = utilityName + "_ROUND"
%elseif roundMode == "Convergent"
%assign utilityName = utilityName + "_CONVERGENT"
%elseif roundMode == ""
%else
%assign utilityName = utilityName + "_ROUNDERROR"
%endif
%return utilityName
%endfunction
%endif