// File: /workspace/github_cpp_makefile_star2_O2/CMU-SAFARI[P]ramulator/src/HBM.cpp
// Function: ramulator::HBM::init_prereq()
void HBM::init_prereq()
{
    // RD
    prereq[int(Level::Rank)][int(Command::RD)] = [] (DRAM<HBM>* 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<HBM>* 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<HBM>* 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;};

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

    // PD
    prereq[int(Level::Rank)][int(Command::PDE)] = [] (DRAM<HBM>* 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<HBM>* 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 0x408(%rdi), %r14
movups 0x408(%rdi), %xmm0
movq %rsp, %r15
movaps %xmm0, (%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x408(%rdi)
movups 0x418(%rdi), %xmm0
leaq 0x1613(%rip), %rax      # 0xade96
movq %rax, 0x418(%rdi)
movaps %xmm0, 0x10(%r15)
leaq 0x15c4(%rip), %rax      # 0xade5a
movq %rax, 0x420(%rdi)
movq %r15, %rdi
callq 0x96b6a
leaq 0x748(%rbx), %r12
movups 0x748(%rbx), %xmm0
movaps %xmm0, (%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x748(%rbx)
movups 0x758(%rbx), %xmm0
leaq 0x1649(%rip), %rax      # 0xadf18
movq %rax, 0x758(%rbx)
movaps %xmm0, 0x10(%r15)
leaq 0x15cc(%rip), %rax      # 0xadeae
movq %rax, 0x760(%rbx)
movq %rsp, %r15
movq %r15, %rdi
callq 0x96b6a
leaq 0x428(%rbx), %rdi
movq %r14, %rsi
callq 0xae562
leaq 0x768(%rbx), %rdi
movq %r12, %rsi
callq 0xae562
movups 0x488(%rbx), %xmm0
movaps %xmm0, (%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x488(%rbx)
movups 0x498(%rbx), %xmm0
leaq 0x1649(%rip), %rax      # 0xadf7e
movq %rax, 0x498(%rbx)
movaps %xmm0, 0x10(%r15)
leaq 0x15e8(%rip), %rax      # 0xadf30
movq %rax, 0x4a0(%rbx)
movq %rsp, %r14
movq %r14, %rdi
callq 0x96b6a
movups 0x7e8(%rbx), %xmm0
movaps %xmm0, (%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x7e8(%rbx)
movups 0x7f8(%rbx), %xmm0
leaq 0x162d(%rip), %rax      # 0xadfaa
movq %rax, 0x7f8(%rbx)
movaps %xmm0, 0x10(%r14)
leaq 0x1606(%rip), %rax      # 0xadf96
movq %rax, 0x800(%rbx)
movq %rsp, %r14
movq %r14, %rdi
callq 0x96b6a
movups 0x4c8(%rbx), %xmm0
movaps %xmm0, (%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x4c8(%rbx)
movups 0x4d8(%rbx), %xmm0
leaq 0x1639(%rip), %rax      # 0xadffe
movq %rax, 0x4d8(%rbx)
movaps %xmm0, 0x10(%r14)
leaq 0x15ea(%rip), %rax      # 0xadfc2
movq %rax, 0x4e0(%rbx)
movq %rsp, %r14
movq %r14, %rdi
callq 0x96b6a
movups 0x508(%rbx), %xmm0
movaps %xmm0, (%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x508(%rbx)
movups 0x518(%rbx), %xmm0
leaq 0x1647(%rip), %rax      # 0xae054
movq %rax, 0x518(%rbx)
movaps %xmm0, 0x10(%r14)
leaq 0x15f6(%rip), %rax      # 0xae016
movq %rax, 0x520(%rbx)
movq %rsp, %rdi
callq 0x96b6a
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
nop