%%
%%dspgivensrot.tlc
%%
%%Copyright1995-2014TheMathWorks,Inc.
%%
 
%if EXISTS("_DSPGIVENSROTLIB_") == 0
%assign _DSPGIVENSROTLIB_ = 1
 
%if !EXISTS("dspGivensRotUtils")
  %createrecord dspGivensRotUtils { ...
  NothingMacro 1}
%endif
 
%function dspGivensRot(dTypeIdentifier, xptr, yptr, cptr, sptr) Output
  %%
  %if ((dTypeIdentifier == "D") || (dTypeIdentifier == "Z"))
    %assign utilityName = "rotg"
    %assign ptrLabel = "real_T*"
    %assign valLabel = "real_T"
    %assign constLabel = ""
    %assign CHYPOT = "CHYPOT"
    %assign fabs = "fabs"
  %else
    %assign utilityName = "rotg32"
    %assign ptrLabel = "real32_T*"
    %assign valLabel = "real32_T"
    %assign constLabel = "F"
    %assign CHYPOT = "CHYPOT32"
    %assign fabs = "fabsf"
  %endif
   
  %% Register utility name in the Shared Code Manager
  %if SLibInBlockScope()
    %assign block = SLibGetCurrentBlock()
  %else
    %assign block = ""
  %endif
  %assign utilityName = SLibRegisterSharedUtility(block, utilityName)
   
  %<FcnTrackSharedUtilHeaderFileUsage(utilityName + ".h", TLC_FALSE)>
  %<utilityName>(%<xptr>, %<yptr>, %<cptr>, %<sptr>)
  %%
  %if !(ISFIELD(dspGivensRotUtils, utilityName))
    %%
    %<LibPushEmptyStackSharedUtils()>/
    %%
    %% register utility
    %%
    %assign tmpRet = SETFIELD(dspGivensRotUtils,utilityName,1)
    %%
    %% utility function prototype
    %%
    %assign funcDeclarationRoot = "void %<utilityName>(%<ptrLabel> x, %<ptrLabel> y, %<ptrLabel> c, %<ptrLabel> s)"
    %openfile funcProto
      %<funcDeclarationRoot>;
    %closefile funcProto
    %%
    %% utility definition
    %%
    %openfile utilityDef
    #include "dsp_rt.h"
    %<funcDeclarationRoot>
    {
        %<valLabel> rho, r, z, absx, absy;
        rho = ((absx = %<fabs>(*x)) > (absy = %<fabs>(*y))) ? *x : *y;
        %<CHYPOT>(*x, *y, r);
        r = (rho > 0.0%<constLabel>) ? r : -r;
        *c = (r == 0.0%<constLabel>) ? 1.0%<constLabel> : *x / r;
        *s = (r == 0.0%<constLabel>) ? 0.0%<constLabel> : *y / r;
        z = (absx > absy) ? *s : 1.0%<constLabel>;
        z = (absy >= absx && *c != 0.0%<constLabel>) ? 1.0%<constLabel> / *c : z;
        *x = r;
        *y = z;
    }
    %closefile utilityDef
    %%
    %<SLibAddMathIncludeForUtilsSourceCode(utilityDef)>
    %<SLibDumpUtilsSourceCodeAndCacheFunctionPrototype(utilityName,funcProto,utilityDef)>/
    %%
    %assign GSUStackBuf = LibPopStackSharedUtilsIncludes()
    %%
  %endif
  
%endfunction %% dspGivensRot
 
%endif %% _DSPGIVENSROTLIB_
  
%%[EOF]dspgivensrot.tlc