// File: /workspace/github_cpp_makefile_star2_O3/xbai0624[P]dnn/src/ConstructLayer.cpp
// Function: ConstructLayer::InitFilters()
void ConstructLayer::InitFilters()
{
    // clear previous filter
    __activeFlag.clear();

    // init filter 2d matrix, fill true value to all elements
    if(__type == LayerType::input)
    {
        if(__layerDimension == LayerDimension::_1D)
        {
            assert(__neurons.size() == 1); // only one kernel
            auto dim = __neurons[0].Dimension();
            Filter2D f(dim.first, dim.second); // default to true
            __activeFlag.push_back(f);
        }
        else if(__layerDimension == LayerDimension::_2D)
        {
            // 2D input layer need a fake filter with dimension (number_of_fake_neurons, 1), similar like 1D
            // this is just in case one directly connect a 2D input layer to a 1D fc layer
            //
            // since filters in 2D middle layers are not used, so it is safe to code like 1D case
            assert(__neurons.size() == 1); // only one kernel
            auto dim = __neurons[0].Dimension(); // for 2D layer, the fake neurons has also been initialized
            Filter2D f(dim.first, dim.second); // default to true
            __activeFlag.push_back(f);
        }
    }
    else if(__type == LayerType::output)
    {
        assert(__neurons.size() == 1); // only one kernel
        auto dim = __neurons[0].Dimension();
        assert(dim.second == 1); // only one collum
        Filter2D f(dim.first, dim.second); // default to true
        __activeFlag.push_back(f);
    }
    else if(__type == LayerType::fullyConnected)
    {
        assert(__neurons.size() == 1);
        auto dim = __neurons[0].Dimension();
        Filter2D f(dim.first, dim.second); // default to true
        __activeFlag.push_back(f);
    }
    else if(__type == LayerType::cnn || __type == LayerType::pooling)
    {
        size_t nKernels = __weightMatrix.size();
        for(size_t i=0;i<nKernels;i++)
        {
            auto dim = __weightMatrix[i].Dimension();
            Filter2D f(dim.first, dim.second); // default to true
            __activeFlag.push_back(f);
        }
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rdi, %r14
movq 0x108(%rdi), %r15
movq 0x110(%rdi), %r12
cmpq %r15, %r12
je 0x6adc
movq %r15, %rbx
movq %rbx, %rdi
callq 0x14654
addq $0x18, %rbx
cmpq %r12, %rbx
jne 0x6ac4
movq %r15, 0x110(%r14)
movl 0xc(%r14), %eax
cmpq $0x4, %rax
ja 0x6d06
leaq 0x108(%r14), %rbx
leaq 0x20620(%rip), %rcx     # 0x27118
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x68(%r14), %rax
subq 0x60(%r14), %rax
je 0x6d06
sarq $0x3, %rax
movabsq $-0x5555555555555555, %r12 # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %r12
cmpq $0x1, %r12
adcq $0x0, %r12
xorl %r13d, %r13d
leaq 0x8(%rsp), %r15
movq 0x60(%r14), %rdi
addq %r13, %rdi
callq 0x1abb8
movq %r15, %rdi
movq %rax, %rsi
callq 0x137e6
movq %rbx, %rdi
movq %r15, %rsi
callq 0x13878
movq %r15, %rdi
callq 0x14654
addq $0x18, %r13
decq %r12
jne 0x6b31
jmp 0x6d06
movq 0x40(%r14), %rax
movq 0x48(%r14), %rcx
subq %rax, %rcx
cmpq $0x18, %rcx
jne 0x6d33
movq (%rax), %rcx
movq 0x8(%rax), %rax
subq %rcx, %rax
je 0x6d14
movq 0x8(%rcx), %rdx
subq (%rcx), %rdx
cmpq $0x8, %rdx
jne 0x6d14
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rsi
leaq 0x8(%rsp), %r14
movl $0x1, %edx
movq %r14, %rdi
callq 0x137e6
movq %rbx, %rdi
movq %r14, %rsi
callq 0x13878
jmp 0x6cfc
movq 0x40(%r14), %rax
movq 0x48(%r14), %rcx
subq %rax, %rcx
cmpq $0x18, %rcx
jne 0x6d52
movq (%rax), %rcx
movq 0x8(%rax), %rax
subq %rcx, %rax
je 0x6c43
movq 0x8(%rcx), %rdx
subq (%rcx), %rdx
sarq $0x3, %rdx
jmp 0x6c45
movl 0x408(%r14), %eax
cmpl $0x1, %eax
je 0x6c74
testl %eax, %eax
jne 0x6d06
movq 0x40(%r14), %rax
movq 0x48(%r14), %rcx
subq %rax, %rcx
cmpq $0x18, %rcx
jne 0x6d71
movq (%rax), %rcx
movq 0x8(%rax), %rax
subq %rcx, %rax
je 0x6ca2
movq 0x8(%rcx), %rdx
subq (%rcx), %rdx
sarq $0x3, %rdx
jmp 0x6ca4
xorl %edx, %edx
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rsi
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x137e6
movq %rbx, %rdi
movq %r14, %rsi
callq 0x13878
jmp 0x6cfc
movq 0x40(%r14), %rax
movq 0x48(%r14), %rcx
subq %rax, %rcx
cmpq $0x18, %rcx
jne 0x6d90
movq (%rax), %rcx
movq 0x8(%rax), %rax
subq %rcx, %rax
je 0x6cd0
movq 0x8(%rcx), %rdx
subq (%rcx), %rdx
sarq $0x3, %rdx
jmp 0x6cd2
xorl %edx, %edx
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rsi
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x137e6
movq %rbx, %rdi
movq %r14, %rsi
callq 0x13878
jmp 0x6cfc
xorl %edx, %edx
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rsi
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x137e6
movq %rbx, %rdi
movq %r14, %rsi
callq 0x13878
leaq 0x8(%rsp), %rdi
callq 0x14654
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0x21360(%rip), %rdi     # 0x2807b
leaq 0x20a28(%rip), %rsi     # 0x2774a
leaq 0x20bed(%rip), %rcx     # 0x27916
movl $0x21d, %edx            # imm = 0x21D
callq 0x4160
leaq 0x20bc6(%rip), %rdi     # 0x27900
leaq 0x20a09(%rip), %rsi     # 0x2774a
leaq 0x20bce(%rip), %rcx     # 0x27916
movl $0x21b, %edx            # imm = 0x21B
callq 0x4160
leaq 0x20ba7(%rip), %rdi     # 0x27900
leaq 0x209ea(%rip), %rsi     # 0x2774a
leaq 0x20baf(%rip), %rcx     # 0x27916
movl $0x223, %edx            # imm = 0x223
callq 0x4160
leaq 0x20b88(%rip), %rdi     # 0x27900
leaq 0x209cb(%rip), %rsi     # 0x2774a
leaq 0x20b90(%rip), %rcx     # 0x27916
movl $0x208, %edx            # imm = 0x208
callq 0x4160
leaq 0x20b69(%rip), %rdi     # 0x27900
leaq 0x209ac(%rip), %rsi     # 0x2774a
leaq 0x20b71(%rip), %rcx     # 0x27916
movl $0x213, %edx            # imm = 0x213
callq 0x4160
jmp 0x6db7
jmp 0x6db7
jmp 0x6db7
jmp 0x6db7
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x14654
movq %rbx, %rdi
callq 0x43e0