// File: /workspace/github_cpp_makefile_star2_O1/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 0x6ba4
movq %r15, %rbx
movq %rbx, %rdi
callq 0x14788
addq $0x18, %rbx
cmpq %r12, %rbx
jne 0x6b8c
movq %r15, 0x110(%r14)
movl 0xc(%r14), %eax
cmpq $0x4, %rax
ja 0x6df1
leaq 0x108(%r14), %rbx
leaq 0x20558(%rip), %rcx     # 0x27118
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x68(%r14), %rax
subq 0x60(%r14), %rax
je 0x6df1
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 0x1ac7c
movq %r15, %rdi
movq %rax, %rsi
callq 0x13938
movq %rbx, %rdi
movq %r15, %rsi
callq 0x139e8
movq %r15, %rdi
callq 0x14788
addq $0x18, %r13
decq %r12
jne 0x6bf9
jmp 0x6df1
movq 0x40(%r14), %rcx
movq 0x48(%r14), %rax
subq %rcx, %rax
cmpq $0x18, %rax
jne 0x6dff
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
je 0x6d21
sarq $0x3, %rcx
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rsi
movq 0x8(%rax), %rcx
subq (%rax), %rcx
cmpq $0x8, %rcx
sete %al
jmp 0x6d25
movq 0x40(%r14), %rcx
movq 0x48(%r14), %rax
subq %rcx, %rax
cmpq $0x18, %rax
jne 0x6e1e
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
je 0x6d4f
sarq $0x3, %rcx
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rsi
movq 0x8(%rax), %rdx
subq (%rax), %rdx
sarq $0x3, %rdx
jmp 0x6d53
movl 0x408(%r14), %eax
cmpl $0x1, %eax
je 0x6d6d
testl %eax, %eax
jne 0x6df1
movq 0x40(%r14), %rcx
movq 0x48(%r14), %rax
subq %rcx, %rax
cmpq $0x18, %rax
jne 0x6e5c
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
je 0x6dad
sarq $0x3, %rcx
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rsi
movq 0x8(%rax), %rdx
subq (%rax), %rdx
sarq $0x3, %rdx
jmp 0x6db1
xorl %esi, %esi
xorl %eax, %eax
testb %al, %al
je 0x6e3d
leaq 0x8(%rsp), %r14
movl $0x1, %edx
movq %r14, %rdi
callq 0x13938
movq %rbx, %rdi
movq %r14, %rsi
callq 0x139e8
jmp 0x6de7
xorl %esi, %esi
xorl %edx, %edx
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x13938
movq %rbx, %rdi
movq %r14, %rsi
callq 0x139e8
jmp 0x6de7
movq 0x40(%r14), %rcx
movq 0x48(%r14), %rax
subq %rcx, %rax
cmpq $0x18, %rax
jne 0x6e7b
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
je 0x6dcb
sarq $0x3, %rcx
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rsi
movq 0x8(%rax), %rdx
subq (%rax), %rdx
sarq $0x3, %rdx
jmp 0x6dcf
xorl %esi, %esi
xorl %edx, %edx
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x13938
movq %rbx, %rdi
movq %r14, %rsi
callq 0x139e8
jmp 0x6de7
xorl %esi, %esi
xorl %edx, %edx
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x13938
movq %rbx, %rdi
movq %r14, %rsi
callq 0x139e8
leaq 0x8(%rsp), %rdi
callq 0x14788
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0x20b39(%rip), %rdi     # 0x2793f
leaq 0x2093d(%rip), %rsi     # 0x2774a
leaq 0x20b41(%rip), %rcx     # 0x27955
movl $0x21b, %edx            # imm = 0x21B
callq 0x4160
leaq 0x20b1a(%rip), %rdi     # 0x2793f
leaq 0x2091e(%rip), %rsi     # 0x2774a
leaq 0x20b22(%rip), %rcx     # 0x27955
movl $0x223, %edx            # imm = 0x223
callq 0x4160
leaq 0x21276(%rip), %rdi     # 0x280ba
leaq 0x208ff(%rip), %rsi     # 0x2774a
leaq 0x20b03(%rip), %rcx     # 0x27955
movl $0x21d, %edx            # imm = 0x21D
callq 0x4160
leaq 0x20adc(%rip), %rdi     # 0x2793f
leaq 0x208e0(%rip), %rsi     # 0x2774a
leaq 0x20ae4(%rip), %rcx     # 0x27955
movl $0x208, %edx            # imm = 0x208
callq 0x4160
leaq 0x20abd(%rip), %rdi     # 0x2793f
leaq 0x208c1(%rip), %rsi     # 0x2774a
leaq 0x20ac5(%rip), %rcx     # 0x27955
movl $0x213, %edx            # imm = 0x213
callq 0x4160
jmp 0x6ea2
jmp 0x6ea2
jmp 0x6ea2
jmp 0x6ea2
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x14788
movq %rbx, %rdi
callq 0x43e0
nop