// File: /workspace/github_cpp_makefile_star2_O1/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 $0x58, %rsp
movq %rdi, %rbx
xorps %xmm4, %xmm4
ucomiss %xmm4, %xmm0
jbe 0x40539a
ucomiss %xmm4, %xmm1
jbe 0x40539a
ucomiss %xmm4, %xmm2
jbe 0x40539a
movd %xmm0, %eax
movss 0xc0dc7(%rip), %xmm5    # 0x4c6044
movaps %xmm5, %xmm7
testl $0x7fffff, %eax         # imm = 0x7FFFFF
notl %eax
jne 0x40528c
movaps %xmm0, %xmm7
movss %xmm3, 0x1c(%rsp)
testl $0x7f800000, %eax       # imm = 0x7F800000
je 0x40529c
movaps %xmm0, %xmm7
cmpltss %xmm5, %xmm0
movd %xmm1, %eax
movaps %xmm5, %xmm4
testl $0x7fffff, %eax         # imm = 0x7FFFFF
notl %eax
jne 0x4052b4
movaps %xmm1, %xmm4
movaps %xmm0, %xmm6
andnps %xmm7, %xmm6
andps %xmm5, %xmm0
testl $0x7f800000, %eax       # imm = 0x7F800000
je 0x4052c7
movaps %xmm1, %xmm4
orps %xmm0, %xmm6
cmpltss %xmm5, %xmm1
movaps %xmm1, %xmm3
andnps %xmm4, %xmm3
andps %xmm5, %xmm1
movd %xmm2, %eax
movaps %xmm5, %xmm0
testl $0x7fffff, %eax         # imm = 0x7FFFFF
notl %eax
jne 0x4052eb
movaps %xmm2, %xmm0
orps %xmm1, %xmm3
testl $0x7f800000, %eax       # imm = 0x7F800000
je 0x4052f8
movaps %xmm2, %xmm0
cmpltss %xmm5, %xmm2
movaps %xmm2, %xmm1
andnps %xmm0, %xmm1
andps %xmm5, %xmm2
orps %xmm1, %xmm2
movss %xmm6, 0x94(%rbx)
movss %xmm3, 0x98(%rbx)
movss %xmm2, 0x9c(%rbx)
movaps %xmm6, 0x30(%rsp)
movss %xmm6, 0x10(%rsp)
movaps %xmm3, 0x20(%rsp)
movss %xmm3, 0x14(%rsp)
movaps %xmm2, 0x40(%rsp)
movss %xmm2, 0x18(%rsp)
movl 0x6c(%rbx), %ebp
cmpl $0x2, %ebp
jae 0x4053c8
xorl %r15d, %r15d
leaq (%rsp,%r15), %r14
addq $0x10, %r14
testb $0x1, %bpl
je 0x405374
movl (%r14), %eax
testl $0x7fffff, %eax         # imm = 0x7FFFFF
je 0x405383
andl $0x7f800000, %eax       # imm = 0x7F800000
addl $0x800000, %eax         # imm = 0x800000
movl %eax, (%r14)
jmp 0x405383
movss (%r14), %xmm0
callq 0x4010c8
movss %xmm0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x40518c
addq $0x4, %r15
cmpq $0xc, %r15
jne 0x40534d
jmp 0x4053e5
movss %xmm0, 0x94(%rbx)
movss %xmm1, 0x98(%rbx)
movss %xmm2, 0x9c(%rbx)
movl $0x0, 0xa0(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x7c(%rbx)
jmp 0x405637
xorl %r14d, %r14d
leaq (%rsp,%r14), %rsi
addq $0x10, %rsi
movq %rbx, %rdi
callq 0x40518c
addq $0x4, %r14
cmpq $0xc, %r14
jne 0x4053cb
movl 0x74(%rbx), %r15d
cmpl $0x2, %r15d
je 0x405461
cmpl $0x1, %r15d
movaps 0x40(%rsp), %xmm3
movaps 0x30(%rsp), %xmm4
je 0x40542a
testl %r15d, %r15d
jne 0x405480
movaps %xmm4, %xmm0
cmpunordss %xmm4, %xmm0
movaps %xmm0, %xmm1
movaps 0x20(%rsp), %xmm2
andps %xmm2, %xmm1
minss %xmm4, %xmm2
andnps %xmm2, %xmm0
orps %xmm1, %xmm0
movaps %xmm3, %xmm1
minss %xmm0, %xmm1
jmp 0x40544e
movaps %xmm4, %xmm0
cmpunordss %xmm4, %xmm0
movaps %xmm0, %xmm1
movaps 0x20(%rsp), %xmm2
andps %xmm2, %xmm1
maxss %xmm4, %xmm2
andnps %xmm2, %xmm0
orps %xmm1, %xmm0
movaps %xmm3, %xmm1
maxss %xmm0, %xmm1
cmpunordss %xmm0, %xmm0
movaps %xmm0, %xmm2
andnps %xmm1, %xmm2
andps %xmm3, %xmm0
orps %xmm2, %xmm0
jmp 0x40547a
movaps 0x30(%rsp), %xmm0
addss 0x20(%rsp), %xmm0
addss 0x40(%rsp), %xmm0
divss 0xc0be6(%rip), %xmm0    # 0x4c6060
movss %xmm0, 0xc(%rsp)
movd 0x1c(%rsp), %xmm1
movd %xmm1, %ecx
movl %ecx, %eax
notl %eax
testl $0x7f800000, %eax       # imm = 0x7F800000
sete %al
testl $0x7fffff, %ecx         # imm = 0x7FFFFF
setne %cl
xorps %xmm0, %xmm0
ucomiss %xmm1, %xmm0
ja 0x4054bf
andb %cl, %al
jne 0x4054bf
ucomiss 0xc0b92(%rip), %xmm1    # 0x4c6044
movaps %xmm1, %xmm0
jbe 0x4054bf
movss 0xc0b85(%rip), %xmm0    # 0x4c6044
minss 0xc0b7d(%rip), %xmm0    # 0x4c6044
leaq 0xc(%rsp), %r14
mulss (%r14), %xmm0
movss %xmm0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x40518c
movss (%r14), %xmm0
movss %xmm0, 0xa0(%rbx)
testl %ebp, %ebp
je 0x40551c
cmpl $0x1, %ebp
jne 0x40554e
movl 0xc(%rsp), %eax
testl $0x7fffff, %eax         # imm = 0x7FFFFF
movaps 0x40(%rsp), %xmm2
movaps 0x30(%rsp), %xmm3
je 0x405531
andl $0x7f800000, %eax       # imm = 0x7F800000
addl $0x800000, %eax         # imm = 0x800000
movl %eax, 0xc(%rsp)
jmp 0x405531
callq 0x4010c8
movss %xmm0, 0xc(%rsp)
movaps 0x40(%rsp), %xmm2
movaps 0x30(%rsp), %xmm3
movss 0xc(%rsp), %xmm0
cvttss2si %xmm0, %ecx
ucomiss 0xc0b02(%rip), %xmm0    # 0x4c6044
setp %dl
setne %al
orb %dl, %al
andb %cl, %al
jmp 0x40555f
cmpl $0x1, 0x60(%rbx)
sete %al
movaps 0x40(%rsp), %xmm2
movaps 0x30(%rsp), %xmm3
testb %al, %al
je 0x405602
movss 0xc0af1(%rip), %xmm0    # 0x4c6060
ucomiss 0xc(%rsp), %xmm0
jbe 0x405602
cmpl $0x1, %r15d
jne 0x4055b7
movaps %xmm2, %xmm0
movaps 0x20(%rsp), %xmm4
maxss %xmm4, %xmm0
cmpunordss %xmm4, %xmm4
movaps %xmm4, %xmm1
andps %xmm2, %xmm1
andnps %xmm0, %xmm4
orps %xmm1, %xmm4
movaps %xmm4, %xmm0
maxss %xmm3, %xmm0
cmpunordss %xmm3, %xmm3
movaps %xmm3, %xmm1
andps %xmm4, %xmm1
andnps %xmm0, %xmm3
orps %xmm1, %xmm3
jmp 0x4055c9
addss 0x20(%rsp), %xmm3
addss %xmm2, %xmm3
divss 0xc0a97(%rip), %xmm3    # 0x4c6060
minss 0xc0a8f(%rip), %xmm3    # 0x4c6060
leaq 0xc(%rsp), %r14
movss %xmm3, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x40518c
movss (%r14), %xmm0
movss %xmm0, 0xa0(%rbx)
testl %ebp, %ebp
jne 0x405602
callq 0x4010c8
movss %xmm0, 0xc(%rsp)
movss 0x10(%rsp), %xmm0
movss %xmm0, 0x7c(%rbx)
movss 0x14(%rsp), %xmm0
movss %xmm0, 0x80(%rbx)
movss 0x18(%rsp), %xmm0
movss %xmm0, 0x84(%rbx)
movss 0xc(%rsp), %xmm0
movss %xmm0, 0x88(%rbx)
addq $0x58, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq