// File: CMU-SAFARI[P]ramulator/src/SALP.cpp
// Function: ramulator::SALP::init_rowhit()
void SALP::init_rowhit()
{
    switch(int(type)) {
        case int(Type::SALP_1):
            // RD
            rowhit[int(Level::SubArray)][int(Command::RD)] = [] (DRAM<SALP>* node, Command cmd, int id) {
              switch (int(node->state)) {
                case int(State::Closed): return false;
                case int(State::Opened):
                  if (node->row_state.find(id) != node->row_state.end())  return true;
                  else return false;
                default: assert(false);
              }
            };
            // WR
            rowhit[int(Level::SubArray)][int(Command::WR)] = rowhit[int(Level::SubArray)][int(Command::RD)];
            break;
        case int(Type::SALP_2):
            // RD
            rowhit[int(Level::SubArray)][int(Command::RD)] = [] (DRAM<SALP>* node, Command cmd, int id) {
                switch (int(node->state)){
                    case int(State::Closed): return false;
                    case int(State::Opened):
                        if (node->row_state.find(id) != node->row_state.end()) return true;
                        else return false;
                    default: assert(false);
                }};
            // WR
            rowhit[int(Level::SubArray)][int(Command::WR)] = rowhit[int(Level::SubArray)][int(Command::RD)];
            break;
        case int(Type::MASA):
            // RD
            rowhit[int(Level::SubArray)][int(Command::RD)] = [] (DRAM<SALP>* node, Command cmd, int id) {
                switch (int(node->state)){
                    case int(State::Closed): return false;
                    case int(State::Opened):
                        // opened but not selected still counts as a row hit
                        if (node->row_state.find(id) != node->row_state.end()) return true;
                        else return false;
                    case int(State::Selected):
                        if (node->row_state.find(id) != node->row_state.end()) return true;
                        else return false;
                    default: assert(false);
                }};
            // WR
            rowhit[int(Level::SubArray)][int(Command::WR)] = rowhit[int(Level::SubArray)][int(Command::RD)];
            break;
        default: assert(false);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
movl 0x20(%rax), %eax
movl %eax, -0x10(%rbp)
testl %eax, %eax
je 0x20410b
jmp 0x2040f0
movl -0x10(%rbp), %eax
subl $0x1, %eax
je 0x204168
jmp 0x2040fa
movl -0x10(%rbp), %eax
subl $0x2, %eax
je 0x2041c2
jmp 0x20421c
movq -0x18(%rbp), %rdi
addq $0xcd0, %rdi            # imm = 0xCD0
addq $0x540, %rdi            # imm = 0x540
addq $0x80, %rdi
leaq -0x9(%rbp), %rsi
callq 0x206a80
movq -0x18(%rbp), %rdi
movq %rdi, %rsi
addq $0xcd0, %rsi            # imm = 0xCD0
addq $0x540, %rsi            # imm = 0x540
addq $0x80, %rsi
addq $0xcd0, %rdi            # imm = 0xCD0
addq $0x540, %rdi            # imm = 0x540
addq $0xa0, %rdi
callq 0x212320
jmp 0x20423b
movq -0x18(%rbp), %rdi
addq $0xcd0, %rdi            # imm = 0xCD0
addq $0x540, %rdi            # imm = 0x540
addq $0x80, %rdi
leaq -0xa(%rbp), %rsi
callq 0x206ad0
movq -0x18(%rbp), %rdi
movq %rdi, %rsi
addq $0xcd0, %rsi            # imm = 0xCD0
addq $0x540, %rsi            # imm = 0x540
addq $0x80, %rsi
addq $0xcd0, %rdi            # imm = 0xCD0
addq $0x540, %rdi            # imm = 0x540
addq $0xa0, %rdi
callq 0x212320
jmp 0x20423b
movq -0x18(%rbp), %rdi
addq $0xcd0, %rdi            # imm = 0xCD0
addq $0x540, %rdi            # imm = 0x540
addq $0x80, %rdi
leaq -0xb(%rbp), %rsi
callq 0x206b20
movq -0x18(%rbp), %rdi
movq %rdi, %rsi
addq $0xcd0, %rsi            # imm = 0xCD0
addq $0x540, %rsi            # imm = 0x540
addq $0x80, %rsi
addq $0xcd0, %rdi            # imm = 0xCD0
addq $0x540, %rdi            # imm = 0x540
addq $0xa0, %rdi
callq 0x212320
jmp 0x20423b
leaq 0x4b93e(%rip), %rdi     # 0x24fb61
leaq 0x5e9ab(%rip), %rsi     # 0x262bd5
movl $0x10f, %edx            # imm = 0x10F
leaq 0x5ea20(%rip), %rcx     # 0x262c56
callq 0xc280
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)