%% 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 "C" %% 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 "real_T" %case "const real_T *" %case "real32_T" %case "const real32_T *" %assign zeroClip = 1 %assign maxClip = 1 %break %case "int8_T" %case "const int8_T *" %assign zeroClip = 1 %if maxIdx < INT8MAX %assign maxClip = 1 %endif %break %case "boolean_T" %case "const boolean_T *" %if maxIdx < 1 %assign maxClip = 1 %endif %break %case "uint8_T" %case "const uint8_T *" %if maxIdx < UINT8MAX %assign maxClip = 1 %endif %break %case "int16_T" %case "const int16_T *" %assign zeroClip = 1 %if maxIdx < INT16MAX %assign maxClip = 1 %endif %break %case "uint16_T" %case "const uint16_T *" %if maxIdx < UINT16MAX %assign maxClip = 1 %endif %break %case "int_T" %case "const int_T *" %assign zeroClip = 1 %if maxIdx < INT32MAX %assign maxClip = 1 %endif %break %case "uint_T" %case "const uint_T *" %if maxIdx < UINTMAX %assign maxClip = 1 %endif %break %case "int32_T" %case "const int32_T *" %assign zeroClip = 1 %if maxIdx < INT32MAX %assign maxClip = 1 %endif %break %case "uint32_T" %case "const uint32_T *" %if maxIdx < UINT32MAX %assign maxClip = 1 %endif %break %endswitch %% %% %if zeroClip == 1 && maxClip == 1 %assign clipCode = "u = (u < 0) ? 0 : ((u > %) ? % : u);" %elseif zeroClip == 0 && maxClip == 1 %assign clipCode = "u = (u > %) ? % : u;" %elseif zeroClip == 1 && maxClip == 0 %assign clipCode = "u = (u < 0) ? 0 : u;" %else %assign clipCode = "" %endif %return clipCode %endfunction %% Function: FcnTypeMaxVal ====================================================== %% Abstract: %% Calculate max value for the type given. %% %function FcnTypeMaxVal(typename) void %switch typename %case "real_T" %case "const real_T *" %case "real32_T" %case "const real32_T *" %assign maxVal = inf %break %case "int8_T" %case "const int8_T *" %assign maxVal = INT8MAX %break %case "uint8_T" %case "const uint8_T *" %assign maxVal = UINT8MAX %break %case "int16_T" %case "const int16_T *" %assign maxVal = INT16MAX %break %case "uint16_T" %case "const uint16_T *" %assign maxVal = UINT16MAX %break %case "int_T" %case "const int_T *" %assign maxVal = INT32MAX %break %case "uint_T" %case "const uint_T *" %assign maxVal = UINTMAX %break %case "int32_T" %case "const int32_T *" %assign maxVal = INT32MAX %break %case "uint32_T" %case "const uint32_T *" %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 "real_T" %case "const real_T *" %case "real32_T" %case "const real32_T *" %assign okType = "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 %if SIZE(dRollRegions,1) == 1 %assign needEnd = 1 { %else %assign needEnd = 0 %endif %assign uType = "int_T" %% %% 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; %foreach portIdx = numInputIndices %if portIdx == 0 %assign eqStr = "=" %else %assign eqStr = "+=" %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", %) %% xxx use ..DataType() to use tSS_DOUBLE %assign uType = FcnForceIntType(LibBlockInputSignalDataTypeName(0,"")) %assign clipCode = FcnGenClipCode(uType,maxIdx) %if SIZE(clipCode,1) > 0 && SFcnParamSettings.clipFlag < 3 %if SIZE(dRollRegions,1) == 1 %assign needEnd = 1 { %else %assign needEnd = 0 %endif %if uType == LibBlockInputSignalDataTypeName(0,"") % u = %; %else % u = (%)%; %endif % %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) % = %; %endroll %else %% %% No roll, copying multiple table elements for scalar inputs %% %% Process Input(s) %% %if numInputIndices > 1 %assign needEnd = 1 { %assign uType = "int_T" % u; % tableOffset; %foreach portIdx = numInputIndices %if portIdx == 0 %assign eqStr = "=" %else %assign eqStr = "+=" %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 = FcnForceIntType(LibBlockInputSignalDataTypeName(0,"")) %assign clipCode = FcnGenClipCode(uType,maxIdx) %assign needEnd = 0 %if SIZE(clipCode,1) > 0 && SFcnParamSettings.clipFlag < 3 %assign needEnd = 1 { %if uType == LibBlockInputSignalDataTypeName(0,"") % u = %; %else % u = (%)%; %endif % %if numElements > 1 %assign tableOffset = "%*u" %else %assign tableOffset = "u" %endif %else %if numElements > 1 %assign tableOffset = "%*%" %else %assign tableOffset = u %endif %endif %endif %% %% Process Output %% %if numInputIndices > 1 %assign tOffset = "tableOffset" %else %assign tOffset = tableOffset %endif %if SFcnParamSettings.tabIsInput == 1 %assign tabContigFlag = ParamSettings.InputContiguous[tablePortIdx] %else %assign tabContigFlag = "yes" %endif %if tabContigFlag == "yes" %assign yPtr = LibBlockOutputSignalAddr(0, "", "", 0) %if SFcnParamSettings.tabIsInput == 0 %assign tablePtr = LibBlockParameterAddr(table, "%", "", 0) %else %assign tablePtr = LibBlockInputSignalAddr(tablePortIdx,"%","",0) %endif (void) memcpy( (void *)%, (void *)%, % ); %else %% %% handle discontiguous input tables with element-by-element copy %% %assign pRollRegs = [0:%] %assign rollVarString = "[\"u%\", \"Y\"]" %assign rollVars = % %roll sigIdx = pRollRegs, lcv = RollThreshold, block, ... "Roller", rollVars %if "%" == "" %assign idxExpression = "%" %else %assign idxExpression = "%+%" %endif %assign y = LibBlockOutputSignal(0, "", lcv, sigIdx) %assign utab = LibBlockInputSignal(tablePortIdx, "%", ... lcv, sigIdx) % = %; %endroll %endif %endif %% %% %if needEnd == 1 } %endif %endfunction