// File: /workspace/github_cpp_makefile_star2_O2/YiweiMao[P]tessDX/src/tessellator.cpp
// Function: CHLSLTessellator::TriHLSLProcessTessFactors(float, float, float, float)
void CHLSLTessellator::TriHLSLProcessTessFactors( float tessFactor_Ueq0, float tessFactor_Veq0, float tessFactor_Weq0, 
                                  float insideTessFactorScale )
{
    if( !(tessFactor_Ueq0 > 0) || // NaN will pass
        !(tessFactor_Veq0 > 0) ||
        !(tessFactor_Weq0 > 0) )
    {
        m_LastUnRoundedComputedTessFactors[0] = tessFactor_Ueq0;
        m_LastUnRoundedComputedTessFactors[1] = tessFactor_Veq0;
        m_LastUnRoundedComputedTessFactors[2] = tessFactor_Weq0;
        m_LastUnRoundedComputedTessFactors[3] = 
        m_LastComputedTessFactors[0] = 
        m_LastComputedTessFactors[1] = 
        m_LastComputedTessFactors[2] = 
        m_LastComputedTessFactors[3] = 0;
        return;
    }

    CleanupFloatTessFactor(tessFactor_Ueq0); // clamp to [1.0f..INF], NaN->1.0f
    CleanupFloatTessFactor(tessFactor_Veq0);
    CleanupFloatTessFactor(tessFactor_Weq0);

    // Save off TessFactors so they can be returned to app
    m_LastUnRoundedComputedTessFactors[0] = tessFactor_Ueq0;
    m_LastUnRoundedComputedTessFactors[1] = tessFactor_Veq0;
    m_LastUnRoundedComputedTessFactors[2] = tessFactor_Weq0;

    // Process outside TessFactors
    float outsideTessFactor[TRI_EDGES] = {tessFactor_Ueq0, tessFactor_Veq0, tessFactor_Weq0};
    int edge;
    if( Pow2Partitioning() || IntegerPartitioning() )
    {
        for( edge = 0; edge < TRI_EDGES; edge++ )
        {
            RoundUpTessFactor(outsideTessFactor[edge]); // for pow2 this rounds to pow2
            ClampTessFactor(outsideTessFactor[edge]); // clamp unbounded user input based on tessellation mode
        }
    }
    else
    {
        for( edge = 0; edge < TRI_EDGES; edge++ )
        {
            ClampTessFactor(outsideTessFactor[edge]); // clamp unbounded user input based on tessellation mode
        }
    }
    
    // Compute inside TessFactor
    float insideTessFactor;
    switch( m_insideTessFactorReduction )
    {
    case D3D11_TESSELLATOR_REDUCTION_MIN:
        insideTessFactor = fmin(fmin(tessFactor_Ueq0,tessFactor_Veq0),tessFactor_Weq0);
        break;
    case D3D11_TESSELLATOR_REDUCTION_MAX:
        insideTessFactor = fmax(fmax(tessFactor_Ueq0,tessFactor_Veq0),tessFactor_Weq0);
        break;
    case D3D11_TESSELLATOR_REDUCTION_AVERAGE:
        insideTessFactor = (tessFactor_Ueq0 + tessFactor_Veq0 + tessFactor_Weq0) / 3;
        break;
    }

    // Scale inside TessFactor based on user scale factor.
    ClampFloatTessFactorScale(insideTessFactorScale); // clamp scale value to [0..1], NaN->0
    insideTessFactor = insideTessFactor*fmin(FLOAT_ONE,insideTessFactorScale);

    ClampTessFactor(insideTessFactor); // clamp reduction + scale result that is based on unbounded user input
    m_LastUnRoundedComputedTessFactors[3] = insideTessFactor;// Save off TessFactors so they can be returned to app
    TESSELLATOR_PARITY parity;
    if( Pow2Partitioning() || IntegerPartitioning() )
    {
        RoundUpTessFactor(insideTessFactor);
        parity = (isEven(insideTessFactor) || (FLOAT_ONE == insideTessFactor))
                                        ? TESSELLATOR_PARITY_EVEN : TESSELLATOR_PARITY_ODD;
    }
    else
    {
        parity = m_originalParity;
    }

    if( (TESSELLATOR_PARITY_ODD == parity) &&
        (insideTessFactor < FLOAT_THREE))
    {
        // To prevent snapping on edges, the "picture frame" comes
        // in using avg or max (and ignore inside TessFactor scaling) until it is at least 3.
        if(D3D11_TESSELLATOR_REDUCTION_MAX == m_insideTessFactorReduction)
        {
            insideTessFactor = fmin(FLOAT_THREE,fmax(tessFactor_Ueq0,fmax(tessFactor_Veq0,tessFactor_Weq0)));
        }
        else
        {
            insideTessFactor = fmin(FLOAT_THREE,(tessFactor_Ueq0 + tessFactor_Veq0 + tessFactor_Weq0) / 3);
        }
        ClampTessFactor(insideTessFactor); // clamp reduction result that is based on unbounded user input
        m_LastUnRoundedComputedTessFactors[3] = insideTessFactor;// Save off TessFactors so they can be returned to app
        if( IntegerPartitioning())
        {
            RoundUpTessFactor(insideTessFactor);
        }
    }

    // Save off TessFactors so they can be returned to app
    m_LastComputedTessFactors[0] = outsideTessFactor[Ueq0];
    m_LastComputedTessFactors[1] = outsideTessFactor[Veq0];
    m_LastComputedTessFactors[2] = outsideTessFactor[Weq0];
    m_LastComputedTessFactors[3] = insideTessFactor;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movss %xmm3, 0x1c(%rsp)
xorps %xmm3, %xmm3
ucomiss %xmm3, %xmm0
jbe 0x404bfd
ucomiss %xmm3, %xmm1
jbe 0x404bfd
ucomiss %xmm3, %xmm2
jbe 0x404bfd
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movaps 0xc05c1(%rip), %xmm1    # 0x4c50f0
movd %xmm2, %eax
movss 0xc0509(%rip), %xmm5    # 0x4c5044
movaps %xmm5, %xmm3
testl $0x7fffff, %eax         # imm = 0x7FFFFF
notl %eax
jne 0x404b4a
movaps %xmm2, %xmm3
movaps %xmm0, %xmm4
cmpltps %xmm1, %xmm4
movaps %xmm4, %xmm7
testl $0x7f800000, %eax       # imm = 0x7F800000
je 0x404b5e
movaps %xmm2, %xmm3
movaps %xmm2, %xmm6
cmpltss %xmm5, %xmm6
movaps %xmm6, %xmm4
andnps %xmm3, %xmm4
andps %xmm5, %xmm6
orps %xmm4, %xmm6
movaps 0xc0587(%rip), %xmm2    # 0x4c5100
movaps %xmm0, %xmm3
andps %xmm2, %xmm3
pcmpeqd %xmm2, %xmm3
movaps 0xc0586(%rip), %xmm2    # 0x4c5110
andps %xmm0, %xmm2
xorps %xmm4, %xmm4
pcmpeqd %xmm2, %xmm4
pandn %xmm3, %xmm4
orps %xmm4, %xmm7
andps %xmm7, %xmm1
andnps %xmm0, %xmm7
orps %xmm1, %xmm7
movlps %xmm7, 0x94(%rbx)
movss %xmm6, 0x9c(%rbx)
movaps %xmm7, 0x30(%rsp)
movlps %xmm7, 0x10(%rsp)
movaps %xmm6, 0x20(%rsp)
movss %xmm6, 0x18(%rsp)
movl 0x6c(%rbx), %ebp
cmpl $0x2, %ebp
jae 0x404c28
xorl %r15d, %r15d
cmpq $0xc, %r15
je 0x404c47
leaq (%rsp,%r15), %r14
addq $0x10, %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x404a02
movq %rbx, %rdi
movq %r14, %rsi
callq 0x404a38
addq $0x4, %r15
jmp 0x404bd3
movss %xmm0, 0x94(%rbx)
movss %xmm1, 0x98(%rbx)
movss %xmm2, 0x9c(%rbx)
andl $0x0, 0xa0(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x7c(%rbx)
jmp 0x404de4
xorl %r14d, %r14d
cmpq $0xc, %r14
je 0x404c47
leaq (%rsp,%r14), %rsi
addq $0x10, %rsi
movq %rbx, %rdi
callq 0x404a38
addq $0x4, %r14
jmp 0x404c2b
movl 0x74(%rbx), %r15d
movaps 0x30(%rsp), %xmm0
movaps %xmm0, %xmm1
shufps $0x55, %xmm0, %xmm1     # xmm1 = xmm1[1,1],xmm0[1,1]
cmpl $0x2, %r15d
movaps %xmm1, 0x50(%rsp)
je 0x404c99
cmpl $0x1, %r15d
je 0x404c88
testl %r15d, %r15d
jne 0x404cb0
movaps 0x30(%rsp), %xmm0
movaps 0x50(%rsp), %xmm1
callq 0x410d40
movaps 0x20(%rsp), %xmm1
callq 0x410d40
jmp 0x404cab
callq 0x410d00
movaps 0x20(%rsp), %xmm1
callq 0x410d00
jmp 0x404cab
addss %xmm1, %xmm0
addss 0x20(%rsp), %xmm0
divss 0xc03ad(%rip), %xmm0    # 0x4c5058
movaps %xmm0, 0x40(%rsp)
leaq 0x1c(%rsp), %r14
movq %r14, %rsi
callq 0x404a88
movss (%r14), %xmm0
minss 0xc037a(%rip), %xmm0    # 0x4c5044
mulss 0x40(%rsp), %xmm0
leaq 0xc(%rsp), %r14
movss %xmm0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x404a38
movss (%r14), %xmm0
movss %xmm0, 0xa0(%rbx)
cmpl $0x1, %ebp
ja 0x404d23
leaq 0xc(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x404a02
movss (%r14), %xmm0
cvttss2si %xmm0, %ecx
ucomiss 0xc032d(%rip), %xmm0    # 0x4c5044
setp %dl
setne %al
orb %dl, %al
andb %cl, %al
jmp 0x404d2a
cmpl $0x1, 0x60(%rbx)
sete %al
testb %al, %al
je 0x404dc3
movss 0xc031e(%rip), %xmm1    # 0x4c5058
ucomiss %xmm0, %xmm1
jbe 0x404dc3
cmpl $0x1, %r15d
jne 0x404d67
movaps 0x50(%rsp), %xmm0
movaps 0x20(%rsp), %xmm1
callq 0x410d00
movaps %xmm0, %xmm1
movaps 0x30(%rsp), %xmm0
callq 0x410d00
jmp 0x404d80
movaps 0x30(%rsp), %xmm0
addss 0x50(%rsp), %xmm0
addss 0x20(%rsp), %xmm0
divss 0xc02d8(%rip), %xmm0    # 0x4c5058
minss 0xc02d0(%rip), %xmm0    # 0x4c5058
leaq 0xc(%rsp), %r14
movss %xmm0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x404a38
movss (%r14), %xmm0
movss %xmm0, 0xa0(%rbx)
testl %ebp, %ebp
jne 0x404dc3
leaq 0xc(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x404a02
movss (%r14), %xmm0
movsd 0x10(%rsp), %xmm1
movsd %xmm1, 0x7c(%rbx)
movss 0x18(%rsp), %xmm1
movss %xmm1, 0x84(%rbx)
movss %xmm0, 0x88(%rbx)
addq $0x68, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop