// File: /workspace/github_cpp_makefile_star2_O2/CMU-SAFARI[P]ramulator/src/ALDRAM.cpp
// Function: ramulator::ALDRAM::init_prereq()
void ALDRAM::init_prereq()
{
    // RD
    prereq[int(Level::Rank)][int(Command::RD)] = [] (DRAM<ALDRAM>* 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<ALDRAM>* 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;
                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<ALDRAM>* node, Command cmd, int id) {
        for (auto bank : node->children) {
            if (bank->state == State::Closed)
                continue;
            return Command::PREA;
        }
        return Command::REF;};

    // PD
    prereq[int(Level::Rank)][int(Command::PDE)] = [] (DRAM<ALDRAM>* 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<ALDRAM>* 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 0x1679(%rip), %rax      # 0x98a4c
movq %rax, 0x3d0(%rdi)
movaps %xmm0, 0x10(%r15)
leaq 0x162a(%rip), %rax      # 0x98a10
movq %rax, 0x3d8(%rdi)
movq %r15, %rdi
callq 0x96b6a
leaq 0x540(%rbx), %r12
movups 0x540(%rbx), %xmm0
movaps %xmm0, (%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x540(%rbx)
movups 0x550(%rbx), %xmm0
leaq 0x16b1(%rip), %rax      # 0x98ad0
movq %rax, 0x550(%rbx)
movaps %xmm0, 0x10(%r15)
leaq 0x1632(%rip), %rax      # 0x98a64
movq %rax, 0x558(%rbx)
movq %rsp, %r15
movq %r15, %rdi
callq 0x96b6a
leaq 0x3e0(%rbx), %rdi
movq %r14, %rsi
callq 0x990c8
leaq 0x560(%rbx), %rdi
movq %r12, %rsi
callq 0x990c8
movups 0x440(%rbx), %xmm0
movaps %xmm0, (%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x440(%rbx)
movups 0x450(%rbx), %xmm0
leaq 0x1693(%rip), %rax      # 0x98b18
movq %rax, 0x450(%rbx)
movaps %xmm0, 0x10(%r15)
leaq 0x1650(%rip), %rax      # 0x98ae8
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 0x16a1(%rip), %rax      # 0x98b6e
movq %rax, 0x470(%rbx)
movaps %xmm0, 0x10(%r14)
leaq 0x1650(%rip), %rax      # 0x98b30
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 0x16af(%rip), %rax      # 0x98bc4
movq %rax, 0x4b0(%rbx)
movaps %xmm0, 0x10(%r14)
leaq 0x165e(%rip), %rax      # 0x98b86
movq %rax, 0x4b8(%rbx)
movq %rsp, %rdi
callq 0x96b6a
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
nop