%% File : sfun_nddirectlook.tlc generated from sfun_nddirectlook.ttlc revsion 1.5 %% $Date: 2000/09/29 17:55:19 $ %% %% Rob Aberg, 24-Jul-1999 %% Copyright 1990-2000 The MathWorks, Inc. %% %% Abstract: N-D Direct Lookup Table block target file %implements sfun_nddirectlook "Ada" %% Function: FcnGenClipCode ====================================================== %% Abstract: %% Calculate the min and max for the type given and %% generate clip code for variable u if needed. %% %function FcnGenClipCode(typename,maxIdx) void %assign maxClip = 0 %assign zeroClip = 0 %% %% NOTE: commonsetup.tlc (ada) uses lower case type names %% which are upcased in the indenter. %% NOTE: inputs are never complex. %% %% xxx(enhancement) convert to use e.g., tSS_DOUBLE %switch typename %case "TMW_Types.real_T" %case "TMW_Types.real_T_Array" %case "TMW_Types.real32_T" %case "TMW_Types.real32_T_Array" %assign zeroClip = 1 %assign maxClip = 1 %break %case "TMW_Types.int8_T" %case "TMW_Types.int8_T_Array" %assign zeroClip = 1 %if maxIdx < INT8MAX %assign maxClip = 1 %endif %break %case "TMW_Types.boolean_T" %case "TMW_Types.boolean_T_Array" %if maxIdx < 1 %assign maxClip = 1 %endif %break %case "TMW_Types.uint8_T" %case "TMW_Types.uint8_T_Array" %if maxIdx < UINT8MAX %assign maxClip = 1 %endif %break %case "TMW_Types.int16_T" %case "TMW_Types.int16_T_Array" %assign zeroClip = 1 %if maxIdx < INT16MAX %assign maxClip = 1 %endif %break %case "TMW_Types.uint16_T" %case "TMW_Types.uint16_T_Array" %if maxIdx < UINT16MAX %assign maxClip = 1 %endif %break %case "TMW_Types.int_T" %case "TMW_Types.int_T_Array" %assign zeroClip = 1 %if maxIdx < INT32MAX %assign maxClip = 1 %endif %break %case "TMW_Types.uint_T" %case "TMW_Types.uint_T_Array" %if maxIdx < UINTMAX %assign maxClip = 1 %endif %break %case "Integer" %case "TMW_Types.int32_T" %case "TMW_Types.int32_T_Array" %assign zeroClip = 1 %if maxIdx < INT32MAX %assign maxClip = 1 %endif %break %case "TMW_Types.uint32_T" %case "TMW_Types.uint32_T_Array" %if maxIdx < UINT32MAX %assign maxClip = 1 %endif %break %endswitch %% %% %if zeroClip == 1 && maxClip == 1 %assign clipCode = "if (u < 0) then\n u := 0;\n " %assign clipCode = clipCode + "elsif (u > %) then\n " %assign clipCode = clipCode + "u := %;\n end if;" %elseif zeroClip == 0 && maxClip == 1 %assign clipCode = "if (u > %) then\n u := %;\n end if;" %elseif zeroClip == 1 && maxClip == 0 %assign clipCode = "if (u < 0) then\n u := 0;\n end if;" %else %assign clipCode = "" %endif %return clipCode %endfunction %% Function: FcnTypeMaxVal ====================================================== %% Abstract: %% Calculate max value for the type given. %% %function FcnTypeMaxVal(typename) void %switch typename %case "TMW_Types.real_T" %case "TMW_Types.real_T_Array" %case "TMW_Types.real32_T" %case "TMW_Types.real32_T_Array" %assign maxVal = inf %break %case "TMW_Types.int8_T" %case "TMW_Types.int8_T_Array" %assign maxVal = INT8MAX %break %case "TMW_Types.uint8_T" %case "TMW_Types.uint8_T_Array" %assign maxVal = UINT8MAX %break %case "TMW_Types.int16_T" %case "TMW_Types.int16_T_Array" %assign maxVal = INT16MAX %break %case "TMW_Types.uint16_T" %case "TMW_Types.uint16_T_Array" %assign maxVal = UINT16MAX %break %case "TMW_Types.int_T" %case "TMW_Types.int_T_Array" %assign maxVal = INT32MAX %break %case "TMW_Types.uint_T" %case "TMW_Types.uint_T_Array" %assign maxVal = UINTMAX %break %case "TMW_Types.int32_T" %case "TMW_Types.int32_T_Array" %assign maxVal = INT32MAX %break %case "TMW_Types.uint32_T" %case "TMW_Types.uint32_T_Array" %assign maxVal = UINT32MAX %break %endswitch %return maxVal %endfunction %% Function: FcnForceIntType ====================================================== %% Abstract: %% If input type is floating point, use int_T, otherwise just return input %% %function FcnForceIntType(typeName) void %switch typeName %case "TMW_Types.real_T" %case "TMW_Types.real_T_Array" %case "TMW_Types.real32_T" %case "TMW_Types.real32_T_Array" %assign okType = "TMW_Types.int_T" %break %default %assign okType = typeName %endswitch %return okType %endfunction %% Function: Outputs ========================================================== %% Abstract: %% Use memcpy for > 1 element, array ref for 1 element outputs. %% %function Outputs(block, system) Output %if SFcnParamSettings.tabIsInput == 1 %assign numInputIndices = NumDataInputPorts - 1 %assign tablePortIdx = NumDataInputPorts - 1 %else %assign numInputIndices = NumDataInputPorts %endif %assign outputDTId = LibBlockOutputSignalDataTypeId(0) %% %% the table is complex if the output is complex, %% regardless of whether the table is a parameter %% or an input %% %assign tableIsComplex = LibBlockOutputSignalIsComplex(0) %assign bytesPerElement = SLibGetDataTypeSizeFromId( outputDTId ) * ... (tableIsComplex+1) %assign numOutputDims = CAST("Number",SFcnParamSettings.numTDims - numInputIndices) %assign dimSize = SFcnParamSettings.tabDims %foreach idx = SFcnParamSettings.numTDims %if idx == 0 %assign dimSize[0] = 1 %else %assign dimSize[idx] = dimSize[idx-1] * SFcnParamSettings.tabDims[idx-1] %endif %endforeach %% %assign numOutputBytes = bytesPerElement * dimSize[numOutputDims] -- (LookupNDDirect) Block: % %assign ND = "%-dimensional" %assign needOpen = 0 %assign needEnd = 0 %switch numOutputDims %case 0 %if LibBlockOutputSignalWidth(0) == 1 %assign oShape = "a Scalar" %else %assign needOpen = 1 %assign oShape = "% Scalars" %endif %break %case 1 %assign oShape = "a Column" %break %case 2 %assign oShape = "a 2-D Matrix" %endswitch -- % Direct Look-Up Table returning % %if numOutputDims == 0 %% %% block can roll %% %if SFcnParamSettings.tabIsInput == 1 %% %% generate roll variables string %% %assign rollVarString = "[" %foreach idx = numInputIndices %assign rollVarString = rollVarString + "\"u%\", " %endforeach %assign rollVarString = rollVarString + "\"Y\"]" %assign rollVars = % %% %% generate roll region from intersection of inputs xxx %% %assign dRollRegions = DataInputPort[0].RollRegions %foreach idx = numInputIndices %if SIZE(DataInputPort[idx].RollRegions,1) > SIZE(dRollRegions,1) %assign dRollRegions = DataInputPort[idx].RollRegions %endif %endforeach %else %% %% generic roll %% %assign rollVars = ["U","Y"] %assign dRollRegions = RollRegions %endif %% %roll sigIdx=dRollRegions, lcv=1, block, "Roller", rollVars %if numInputIndices > 1 declare %assign uType = "Integer" %% %% Do we need the clipping temp var? find out here %% %assign needU = 0 %foreach portIdx = numInputIndices %assign maxIdx = CAST("Number", ... %) %% xxx clip on ...DataType and switch on tSS_DOUBLE %assign iType = LibBlockInputSignalDataTypeName(portIdx,"") %assign clipCode = FcnGenClipCode(iType,maxIdx) %if SIZE(clipCode,1) > 0 %assign needU = 1 %endif %endforeach %if needU == 1 u : %; %endif tableOffset : %; begin %foreach portIdx = numInputIndices %if portIdx == 0 %assign eqStr = ":=" %else %assign eqStr = ":= tableOffset +" %endif %assign u = LibBlockInputSignal(portIdx, "", lcv, sigIdx) %assign maxIdx = CAST("Number", ... %) %assign numElements = CAST("Number", %) %% xxx use ..DataType() for clip code calc %assign iType = LibBlockInputSignalDataTypeName(portIdx,"") %assign clipCode = FcnGenClipCode(iType,maxIdx) %if SIZE(clipCode,1) > 0 && SFcnParamSettings.clipFlag < 3 u := %(%); % %if numElements > 1 tableOffset % % * u; %else tableOffset % u; %endif %else %if numElements > 1 tableOffset % % * %(%); %else tableOffset % %(%); %endif %endif %endforeach %if SFcnParamSettings.tabIsInput == 0 %assign tableValue = LibBlockParameter(table, "tableOffset", "", 0) %else %assign tableValue = LibBlockInputSignal(tablePortIdx, "tableOffset", "", 0) %endif %else %% %% only one input, clip if necessary, if not use it directly %% %assign u = LibBlockInputSignal(0, "", lcv, sigIdx) %assign maxIdx = CAST("Number", %) %assign numElements = CAST("Number", %) %assign uType = "Integer" %assign clipCode = FcnGenClipCode(uType,maxIdx) %if SIZE(clipCode,1) > 0 && SFcnParamSettings.clipFlag < 3 declare u : % := %(%); begin % %assign tableOffset = "u" %else %assign tableOffset = "%(%)" %endif %if SFcnParamSettings.tabIsInput == 0 %assign tableValue = LibBlockParameter(table, tableOffset, "", 0) %else %assign tableValue = LibBlockInputSignal(tablePortIdx, tableOffset, "", 0) %endif %endif %assign y = LibBlockOutputSignal(0, "", lcv, sigIdx) % := %; end; %endroll %else %% %% No roll, copying multiple table elements for scalar inputs %% %% Process Input(s) %% %if numInputIndices > 1 %assign needEnd = 1 declare %assign uType = "Integer" u : %; tableOffset : %; begin %foreach portIdx = numInputIndices %if portIdx == 0 %assign eqStr = ":=" %else %assign eqStr = ":= tableOffset +" %endif %assign u = LibBlockInputSignal(portIdx, "", "", 0) %assign maxIdx = CAST("Number", ... %) %assign numElements = CAST("Number", %) %% xxx DataType() to use tSS_DOUBLE %assign iType = FcnForceIntType(LibBlockInputSignalDataTypeName(0,"")) %assign clipCode = FcnGenClipCode(iType,maxIdx) %if SIZE(clipCode,1) > 0 && SFcnParamSettings.clipFlag < 3 u := %(%); % %if numElements > 1 tableOffset % % * u; %else tableOffset % u; %endif %else %if numElements > 1 tableOffset % % * %(%); %else tableOffset % %(%); %endif %endif %endforeach %else %% %% just one index into table %% %assign u = LibBlockInputSignal(0, "", "", 0) %assign maxIdx = CAST("Number", %) %assign numElements = CAST("Number", %) %assign uType = "Integer" %assign clipCode = FcnGenClipCode(uType,maxIdx) %assign needEnd = 0 %if SIZE(clipCode,1) > 0 && SFcnParamSettings.clipFlag < 3 %assign needEnd = 1 declare u : % := %(%); begin % %if numElements > 1 %assign tableOffset = "%*u" %else %assign tableOffset = "u" %endif %else %if numElements > 1 %assign tableOffset = "%*Integer(%)" %else %assign tableOffset = u %endif %endif %endif %% %% Process Output %% %if numInputIndices > 1 %assign tOffset = "tableOffset" %else %assign tOffset = tableOffset %endif %assign pRollRegs = [0:%] %assign rollVars = ["Y","tlcTable"] %% %% Roll over Y and the table. %% %roll sigIdx = pRollRegs, lcv = RollThreshold, block, ... "Roller", rollVars %% %if "%" == "" %assign idxExpression = "%" %else %assign idxExpression = "%+%" %endif %% %if sigIdx == 0 %assign sigIdxPlusStr = "" %else %assign sigIdxPlusStr = "+%" %endif %% %if LibBlockOutputSignalIsComplex(0) == 1 %assign yr = LibBlockOutputSignal(0, "", lcv, "%%") %assign yi = LibBlockOutputSignal(0, "", lcv, "%%") %if SFcnParamSettings.tabIsInput == 0 %assign tlcTabler = LibBlockParameter(table, ... "%%", "", "%0") %assign tlcTablei = LibBlockParameter(table, ... "%%", "", "%0") %else %assign tlcTabler = LibBlockInputSignal(tablePortIdx,... "%", "", "%%") %assign tlcTablei = LibBlockInputSignal(tablePortIdx,... "%", "", "%%") %endif % := %; % := %; %else %% not complex %assign y = LibBlockOutputSignal(0, "", lcv, sigIdx) %if SFcnParamSettings.tabIsInput == 0 %assign tlcTable = LibBlockParameter(table, ... "%%", "", 0) %else %assign tlcTable = LibBlockInputSignal(tablePortIdx, ... "%", "", sigIdx) %endif % := %; %endif %endroll %endif %% %% %if needEnd == 1 end; %endif %endfunction