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

    // REFPB
    prereq[int(Level::Bank)][int(Command::REFPB)] = [] (DRAM<LPDDR3>* node, Command cmd, int id) {
      if (node->state == State::Closed) return Command::REFPB;
        else return Command::PRE;};

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

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

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
leaq 0x400(%rdi), %r14
movups 0x400(%rdi), %xmm0
movq %rsp, %r15
movaps %xmm0, (%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x400(%rdi)
movups 0x410(%rdi), %xmm0
leaq 0x177f(%rip), %rax      # 0xb126e
movq %rax, 0x410(%rdi)
movaps %xmm0, 0x10(%r15)
leaq 0x1730(%rip), %rax      # 0xb1232
movq %rax, 0x418(%rdi)
movq %r15, %rdi
callq 0x96b6a
leaq 0x5a0(%rbx), %r12
movups 0x5a0(%rbx), %xmm0
movaps %xmm0, (%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x5a0(%rbx)
movups 0x5b0(%rbx), %xmm0
leaq 0x17b5(%rip), %rax      # 0xb12f0
movq %rax, 0x5b0(%rbx)
movaps %xmm0, 0x10(%r15)
leaq 0x1738(%rip), %rax      # 0xb1286
movq %rax, 0x5b8(%rbx)
movq %rsp, %r15
movq %r15, %rdi
callq 0x96b6a
leaq 0x420(%rbx), %rdi
movq %r14, %rsi
callq 0xb18fe
leaq 0x5c0(%rbx), %rdi
movq %r12, %rsi
callq 0xb18fe
movups 0x480(%rbx), %xmm0
movaps %xmm0, (%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x480(%rbx)
movups 0x490(%rbx), %xmm0
leaq 0x1797(%rip), %rax      # 0xb1338
movq %rax, 0x490(%rbx)
movaps %xmm0, 0x10(%r15)
leaq 0x1754(%rip), %rax      # 0xb1308
movq %rax, 0x498(%rbx)
movq %rsp, %r14
movq %r14, %rdi
callq 0x96b6a
movups 0x640(%rbx), %xmm0
movaps %xmm0, (%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x640(%rbx)
movups 0x650(%rbx), %xmm0
leaq 0x177b(%rip), %rax      # 0xb1364
movq %rax, 0x650(%rbx)
movaps %xmm0, 0x10(%r14)
leaq 0x1754(%rip), %rax      # 0xb1350
movq %rax, 0x658(%rbx)
movq %rsp, %r14
movq %r14, %rdi
callq 0x96b6a
movups 0x4c0(%rbx), %xmm0
movaps %xmm0, (%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x4c0(%rbx)
movups 0x4d0(%rbx), %xmm0
leaq 0x1789(%rip), %rax      # 0xb13ba
movq %rax, 0x4d0(%rbx)
movaps %xmm0, 0x10(%r14)
leaq 0x1738(%rip), %rax      # 0xb137c
movq %rax, 0x4d8(%rbx)
movq %rsp, %r14
movq %r14, %rdi
callq 0x96b6a
movups 0x500(%rbx), %xmm0
movaps %xmm0, (%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x500(%rbx)
movups 0x510(%rbx), %xmm0
leaq 0x1797(%rip), %rax      # 0xb1410
movq %rax, 0x510(%rbx)
movaps %xmm0, 0x10(%r14)
leaq 0x1746(%rip), %rax      # 0xb13d2
movq %rax, 0x518(%rbx)
movq %rsp, %rdi
callq 0x96b6a
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
nop