// File: /workspace/github_cpp_makefile_star2_O2/CMU-SAFARI[P]ramulator/src/DDR4.cpp
// Function: ramulator::DDR4::init_prereq()
void DDR4::init_prereq()
{
    // RD
    prereq[int(Level::Rank)][int(Command::RD)] = [] (DRAM<DDR4>* node, Command cmd, int id) {
        switch (int(node->state)) {
            case int(State::PowerUp): return Command::MAX;
            case int(State::ActPowerDown): return Command::PDX;
            case int(State::PrePowerDown): return Command::PDX;
            case int(State::SelfRefresh): return Command::SRX;
            default: assert(false);
        }};
    prereq[int(Level::Bank)][int(Command::RD)] = [] (DRAM<DDR4>* node, Command cmd, int id) {
        switch (int(node->state)) {
            case int(State::Closed): return Command::ACT;
            case int(State::Opened):
                if (node->row_state.find(id) != node->row_state.end())
                    return cmd;
                else return Command::PRE;
            default: assert(false);
        }};

    // WR
    prereq[int(Level::Rank)][int(Command::WR)] = prereq[int(Level::Rank)][int(Command::RD)];
    prereq[int(Level::Bank)][int(Command::WR)] = prereq[int(Level::Bank)][int(Command::RD)];

    // REF
    prereq[int(Level::Rank)][int(Command::REF)] = [] (DRAM<DDR4>* node, Command cmd, int id) {
        for (auto bg : node->children)
            for (auto bank: bg->children) {
                if (bank->state == State::Closed)
                    continue;
                return Command::PREA;
            }
        return Command::REF;};

    // PD
    prereq[int(Level::Rank)][int(Command::PDE)] = [] (DRAM<DDR4>* node, Command cmd, int id) {
        switch (int(node->state)) {
            case int(State::PowerUp): return Command::PDE;
            case int(State::ActPowerDown): return Command::PDE;
            case int(State::PrePowerDown): return Command::PDE;
            case int(State::SelfRefresh): return Command::SRX;
            default: assert(false);
        }};

    // SR
    prereq[int(Level::Rank)][int(Command::SRE)] = [] (DRAM<DDR4>* node, Command cmd, int id) {
        switch (int(node->state)) {
            case int(State::PowerUp): return Command::SRE;
            case int(State::ActPowerDown): return Command::PDX;
            case int(State::PrePowerDown): return Command::PDX;
            case int(State::SelfRefresh): return Command::SRE;
            default: assert(false);
        }};
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
leaq 0x3c0(%rdi), %r14
movups 0x3c0(%rdi), %xmm0
movq %rsp, %r15
movaps %xmm0, (%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x3c0(%rdi)
movups 0x3d0(%rdi), %xmm0
leaq 0x1961(%rip), %rax      # 0xa3ce4
movq %rax, 0x3d0(%rdi)
movaps %xmm0, 0x10(%r15)
leaq 0x1912(%rip), %rax      # 0xa3ca8
movq %rax, 0x3d8(%rdi)
movq %r15, %rdi
callq 0x96b6a
leaq 0x6c0(%rbx), %r12
movups 0x6c0(%rbx), %xmm0
movaps %xmm0, (%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x6c0(%rbx)
movups 0x6d0(%rbx), %xmm0
leaq 0x1999(%rip), %rax      # 0xa3d68
movq %rax, 0x6d0(%rbx)
movaps %xmm0, 0x10(%r15)
leaq 0x191a(%rip), %rax      # 0xa3cfc
movq %rax, 0x6d8(%rbx)
movq %rsp, %r15
movq %r15, %rdi
callq 0x96b6a
leaq 0x3e0(%rbx), %rdi
movq %r14, %rsi
callq 0xa43cc
leaq 0x6e0(%rbx), %rdi
movq %r12, %rsi
callq 0xa43cc
movups 0x440(%rbx), %xmm0
movaps %xmm0, (%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x440(%rbx)
movups 0x450(%rbx), %xmm0
leaq 0x1999(%rip), %rax      # 0xa3dce
movq %rax, 0x450(%rbx)
movaps %xmm0, 0x10(%r15)
leaq 0x1938(%rip), %rax      # 0xa3d80
movq %rax, 0x458(%rbx)
movq %rsp, %r14
movq %r14, %rdi
callq 0x96b6a
movups 0x460(%rbx), %xmm0
movaps %xmm0, (%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x460(%rbx)
movups 0x470(%rbx), %xmm0
leaq 0x19a7(%rip), %rax      # 0xa3e24
movq %rax, 0x470(%rbx)
movaps %xmm0, 0x10(%r14)
leaq 0x1956(%rip), %rax      # 0xa3de6
movq %rax, 0x478(%rbx)
movq %rsp, %r14
movq %r14, %rdi
callq 0x96b6a
movups 0x4a0(%rbx), %xmm0
movaps %xmm0, (%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x4a0(%rbx)
movups 0x4b0(%rbx), %xmm0
leaq 0x19b5(%rip), %rax      # 0xa3e7a
movq %rax, 0x4b0(%rbx)
movaps %xmm0, 0x10(%r14)
leaq 0x1964(%rip), %rax      # 0xa3e3c
movq %rax, 0x4b8(%rbx)
movq %rsp, %rdi
callq 0x96b6a
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
nop