// File: /workspace/github_cpp_makefile_star2_O1/YiweiMao[P]tessDX/src/tessellator.cpp
// Function: CHWTessellator::QuadGeneratePoints(CHWTessellator::PROCESSED_TESS_FACTORS_QUAD const&)
void CHWTessellator::QuadGeneratePoints( const PROCESSED_TESS_FACTORS_QUAD& processedTessFactors )
{
    // Generate exterior ring edge points, clockwise from top-left
    int pointOffset = 0;
    int edge;
    for(edge = 0; edge < QUAD_EDGES; edge++ )
    {
        int parity = edge&0x1;
        int startPoint = 0;
        int endPoint = processedTessFactors.numPointsForOutsideEdge[edge] - 1;
        for(int p = startPoint; p < endPoint; p++,pointOffset++) // don't include end, since next edge starts with it.
        {
            FXP fxpParam;
            int q = ((edge==1)||(edge==2)) ? p : endPoint - p; // reverse order 
            SetTessellationParity(processedTessFactors.outsideTessFactorParity[edge]);
            PlacePointIn1D(processedTessFactors.outsideTessFactorCtx[edge],q,fxpParam);
            if( parity )
            {
                DefinePoint(/*U*/fxpParam,
                            /*V*/(edge == 3) ? FXP_ONE : 0,
                            /*pointStorageOffset*/pointOffset);
            }
            else
            {
                DefinePoint(/*U*/(edge == 2) ? FXP_ONE : 0,
                            /*V*/fxpParam,
                            /*pointStorageOffset*/pointOffset);
            }
        }
    }

    // Generate interior ring points, clockwise from (U==0,V==1) (bottom-left) spiralling toward center
    static const int startRing = 1;
    int minNumPointsForTessFactor = min(processedTessFactors.numPointsForInsideTessFactor[U],processedTessFactors.numPointsForInsideTessFactor[V]);
    int numRings = (minNumPointsForTessFactor >> 1);  // note for even tess we aren't counting center point here.
    for(int ring = startRing; ring < numRings; ring++)
    {
        int startPoint = ring;
        int endPoint[QUAD_AXES] = {processedTessFactors.numPointsForInsideTessFactor[U] - 1 - startPoint,
                                   processedTessFactors.numPointsForInsideTessFactor[V] - 1 - startPoint};

        for(edge = 0; edge < QUAD_EDGES; edge++ )
        {
            int parity[QUAD_AXES] = {edge&0x1,((edge+1)&0x1)};
            int perpendicularAxisPoint = (edge < 2) ? startPoint : endPoint[parity[0]];
            FXP fxpPerpParam;
            SetTessellationParity(processedTessFactors.insideTessFactorParity[parity[0]]);
            PlacePointIn1D(processedTessFactors.insideTessFactorCtx[parity[0]],perpendicularAxisPoint,fxpPerpParam);
            SetTessellationParity(processedTessFactors.insideTessFactorParity[parity[1]]);
            for(int p = startPoint; p < endPoint[parity[1]]; p++, pointOffset++) // don't include end: next edge starts with it. 
            {
                FXP fxpParam;
                int q = ((edge == 1)||(edge==2)) ? p : endPoint[parity[1]] - (p - startPoint);
                PlacePointIn1D(processedTessFactors.insideTessFactorCtx[parity[1]],q,fxpParam);
                if( parity[1] )
                {
                    DefinePoint(/*U*/fxpPerpParam,
                                /*V*/fxpParam,
                                /*pointStorageOffset*/pointOffset);
                }
                else
                {
                    DefinePoint(/*U*/fxpParam,
                                /*V*/fxpPerpParam,
                                /*pointStorageOffset*/pointOffset);
                }
            }
        }
    }
    // For even tessellation, the inner "ring" is degenerate - a row of points
    if( (processedTessFactors.numPointsForInsideTessFactor[U] > processedTessFactors.numPointsForInsideTessFactor[V]) && 
        (TESSELLATOR_PARITY_EVEN == processedTessFactors.insideTessFactorParity[V]) )
    {
        int startPoint = numRings;
        int endPoint = processedTessFactors.numPointsForInsideTessFactor[U] - 1 - startPoint;
        SetTessellationParity(processedTessFactors.insideTessFactorParity[U]);
        for( int p = startPoint; p <= endPoint; p++, pointOffset++ )
        {
            FXP fxpParam;
            PlacePointIn1D(processedTessFactors.insideTessFactorCtx[U],p,fxpParam);
            DefinePoint(/*U*/fxpParam,
                        /*V*/FXP_ONE_HALF, // middle
                        /*pointStorageOffset*/pointOffset);
        }
    }
    else if( (processedTessFactors.numPointsForInsideTessFactor[V] >= processedTessFactors.numPointsForInsideTessFactor[U]) && 
             (TESSELLATOR_PARITY_EVEN == processedTessFactors.insideTessFactorParity[U]) )
    {
        int startPoint = numRings;
        int endPoint;
        FXP fxpParam;
        endPoint = processedTessFactors.numPointsForInsideTessFactor[V] - 1 - startPoint;
        SetTessellationParity(processedTessFactors.insideTessFactorParity[V]);
        for( int p = endPoint; p >= startPoint; p--, pointOffset++ )
        {
            PlacePointIn1D(processedTessFactors.insideTessFactorCtx[V],p,fxpParam);
            DefinePoint(/*U*/FXP_ONE_HALF, // middle
                        /*V*/fxpParam,
                        /*pointStorageOffset*/pointOffset);
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, %r14
leaq 0x30(%rsi), %rax
movq %rax, 0x28(%rsp)
xorl %r13d, %r13d
movss 0xc38b3(%rip), %xmm0    # 0x4c6044
xorl %ebp, %ebp
movq %rsi, 0x30(%rsp)
movq %rdi, 0x18(%rsp)
movl 0xac(%r14,%r13,4), %ebx
cmpl $0x2, %ebx
jl 0x4028c9
movss %xmm0, 0x8(%rsp)
cmpq $0x3, %r13
je 0x4027c3
xorps %xmm1, %xmm1
movss %xmm1, 0x8(%rsp)
movss %xmm0, 0xc(%rsp)
cmpq $0x2, %r13
je 0x4027d8
xorps %xmm0, %xmm0
movss %xmm0, 0xc(%rsp)
leal -0x1(%r13), %eax
movl %eax, 0x38(%rsp)
leaq (,%r13,4), %rax
addq %r13, %rax
movq 0x28(%rsp), %rcx
leaq (%rcx,%rax,4), %rax
movq %rax, 0x20(%rsp)
movslq %ebp, %r15
shlq $0x3, %r15
addq 0x18(%rdi), %r15
movl $0x1, %r14d
subl %ebx, %r14d
decl %ebx
xorl %r12d, %r12d
cmpl $0x2, 0x38(%rsp)
movl %r12d, %edx
cmovael %ebx, %edx
movq 0x30(%rsp), %rax
movl 0x18(%rax,%r13,4), %eax
movl %eax, 0x4(%rdi)
movq 0x20(%rsp), %rsi
leaq 0x10(%rsp), %rcx
callq 0x4031d6
movl 0x10(%rsp), %eax
movl %eax, %ecx
shrl $0x10, %ecx
testb $0x1, %r13b
jne 0x402873
xorps %xmm1, %xmm1
cvtsi2ss %ecx, %xmm1
movzwl %ax, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss 0xc(%rsp), %xmm2
movss %xmm2, (%r15,%r12,8)
mulss 0xc37cf(%rip), %xmm0    # 0x4c603c
addss %xmm1, %xmm0
jmp 0x40289c
xorps %xmm0, %xmm0
cvtsi2ss %ecx, %xmm0
movzwl %ax, %eax
xorps %xmm1, %xmm1
cvtsi2ss %eax, %xmm1
mulss 0xc37b0(%rip), %xmm1    # 0x4c603c
addss %xmm0, %xmm1
movss %xmm1, (%r15,%r12,8)
movss 0x8(%rsp), %xmm0
movss %xmm0, 0x4(%r15,%r12,8)
incq %r12
decl %ebx
movl %r14d, %eax
addl %r12d, %eax
movq 0x18(%rsp), %rdi
jne 0x402812
addl %r12d, %ebp
movq 0x30(%rsp), %r14
movss 0xc377b(%rip), %xmm0    # 0x4c6044
incq %r13
cmpq $0x4, %r13
jne 0x40279d
movl 0xbc(%r14), %r8d
movl 0xc0(%r14), %esi
cmpl %esi, %r8d
movl %esi, %r12d
cmovll %r8d, %r12d
sarl %r12d
cmpl $0x2, %r12d
jl 0x402ac9
leaq 0x80(%r14), %rbx
movl $0x1, %r15d
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
movq %rbx, 0x60(%rsp)
movq %r12, 0x58(%rsp)
movl %esi, 0x44(%rsp)
movq %r8, 0x50(%rsp)
movl %r15d, %eax
notl %eax
leal (%r8,%rax), %ecx
movl %ecx, 0x10(%rsp)
addl %esi, %eax
movl %eax, 0x14(%rsp)
xorl %r13d, %r13d
movl %r15d, 0x28(%rsp)
movl %r13d, %eax
andl $0x1, %eax
movl %eax, %eax
movl %r15d, %edx
cmpl $0x2, %r13d
jb 0x402953
movl 0x10(%rsp,%rax,4), %edx
leal 0x1(%r13), %ecx
movl %ecx, 0xc(%rsp)
movl %ecx, %r12d
andl $0x1, %r12d
movl 0x28(%r14,%rax,4), %ecx
movl %ecx, 0x4(%rdi)
leaq (%rax,%rax,4), %rax
leaq (%rbx,%rax,4), %rsi
movq 0x18(%rsp), %rdi
leaq 0x4c(%rsp), %rcx
callq 0x4031d6
movq 0x18(%rsp), %rdi
leal (,%r12,4), %eax
movl 0x28(%r14,%rax), %ecx
movl %ecx, 0x4(%rdi)
movl 0x10(%rsp,%rax), %r14d
cmpl %r14d, %r15d
jge 0x402a8c
movl %r15d, %esi
movl %r12d, %eax
decl %r13d
movq %r13, 0x38(%rsp)
movl 0x4c(%rsp), %ecx
movzwl %cx, %edx
shrl $0x10, %ecx
xorps %xmm0, %xmm0
cvtsi2ss %ecx, %xmm0
leaq (%rax,%rax,4), %rax
xorps %xmm1, %xmm1
cvtsi2ss %edx, %xmm1
leaq (%rbx,%rax,4), %r13
mulss 0xc3662(%rip), %xmm1    # 0x4c603c
addss %xmm0, %xmm1
movss %xmm1, 0x20(%rsp)
movslq %ebp, %r15
shlq $0x3, %r15
addq 0x18(%rdi), %r15
movl %esi, %ebx
cmpl $0x2, 0x38(%rsp)
movl %r14d, %edx
cmovbl %ebx, %edx
movq %r13, %rsi
leaq 0x48(%rsp), %rcx
callq 0x4031d6
movl 0x48(%rsp), %eax
movl %eax, %ecx
shrl $0x10, %ecx
testl %r12d, %r12d
jne 0x402a41
xorps %xmm0, %xmm0
cvtsi2ss %ecx, %xmm0
movzwl %ax, %eax
xorps %xmm1, %xmm1
cvtsi2ss %eax, %xmm1
mulss 0xc360c(%rip), %xmm1    # 0x4c603c
addss %xmm0, %xmm1
movss %xmm1, (%r15)
movss 0x20(%rsp), %xmm0
jmp 0x402a69
xorps %xmm1, %xmm1
cvtsi2ss %ecx, %xmm1
movzwl %ax, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss 0x20(%rsp), %xmm2
movss %xmm2, (%r15)
mulss 0xc35d7(%rip), %xmm0    # 0x4c603c
addss %xmm1, %xmm0
movss %xmm0, 0x4(%r15)
incl %ebx
addq $0x8, %r15
incl %ebp
decl %r14d
movl 0x8(%rsp), %eax
addl %r14d, %eax
movq 0x18(%rsp), %rdi
jne 0x4029f1
movl 0xc(%rsp), %eax
movl %eax, %r13d
cmpl $0x4, %eax
movq 0x30(%rsp), %r14
movq 0x60(%rsp), %rbx
movl 0x28(%rsp), %r15d
jne 0x40293e
incl %r15d
decl 0x8(%rsp)
movq 0x58(%rsp), %r12
cmpl %r12d, %r15d
movl 0x44(%rsp), %esi
movq 0x50(%rsp), %r8
jne 0x402923
cmpl %esi, %r8d
setg %cl
movl 0x2c(%r14), %eax
testl %eax, %eax
sete %dl
testb %dl, %cl
je 0x402b7f
movl %r12d, %eax
notl %eax
addl %r8d, %eax
movl 0x28(%r14), %ecx
movl %ecx, 0x4(%rdi)
cmpl %eax, %r12d
jg 0x402c14
movq %r14, %r13
subq $-0x80, %r13
movq 0x18(%rdi), %rax
movslq %ebp, %rcx
leaq (%rax,%rcx,8), %rbx
addq $0x4, %rbx
subl %r12d, %r8d
subl %r12d, %r8d
movl %r12d, %r14d
xorl %r12d, %r12d
leaq 0x10(%rsp), %r15
leal (%r14,%r12), %edx
movq 0x18(%rsp), %rdi
movq %r13, %rsi
movq %r15, %rcx
movq %r8, %rbp
callq 0x4031d6
movss 0xc34fe(%rip), %xmm2    # 0x4c603c
movq %rbp, %r8
movl 0x10(%rsp), %eax
movl %eax, %ecx
shrl $0x10, %ecx
xorps %xmm0, %xmm0
cvtsi2ss %ecx, %xmm0
movzwl %ax, %eax
xorps %xmm1, %xmm1
cvtsi2ss %eax, %xmm1
mulss %xmm2, %xmm1
addss %xmm0, %xmm1
movss %xmm1, -0x4(%rbx,%r12,8)
movl $0x3f000000, (%rbx,%r12,8) # imm = 0x3F000000
incq %r12
cmpl %r12d, %r8d
jne 0x402b1f
jmp 0x402c14
cmpl %r8d, %esi
jl 0x402c14
cmpl $0x0, 0x28(%r14)
jne 0x402c14
movl %r12d, %ecx
notl %ecx
addl %esi, %ecx
movl %eax, 0x4(%rdi)
cmpl %r12d, %ecx
jl 0x402c14
addq $0x94, %r14
movq 0x18(%rdi), %rax
movslq %ebp, %rcx
leaq (%rax,%rcx,8), %rbx
addq $0x4, %rbx
subl %r12d, %esi
leaq 0x10(%rsp), %r15
decl %esi
movq 0x18(%rsp), %rdi
movl %esi, %ebp
movq %r14, %rsi
movl %ebp, %edx
movq %r15, %rcx
callq 0x4031d6
movss 0xc345e(%rip), %xmm2    # 0x4c603c
movl %ebp, %esi
movl 0x10(%rsp), %eax
movl $0x3f000000, -0x4(%rbx) # imm = 0x3F000000
movzwl %ax, %ecx
shrl $0x10, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
xorps %xmm1, %xmm1
cvtsi2ss %ecx, %xmm1
mulss %xmm2, %xmm1
addss %xmm0, %xmm1
movss %xmm1, (%rbx)
addq $0x8, %rbx
cmpl %r12d, %ebp
jg 0x402bc0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop