// File: /workspace/github_cpp_makefile_star2_O2/CMU-SAFARI[P]ramulator/src/DSARP.cpp
// Function: ramulator::DSARP::DSARP(ramulator::DSARP::Org, ramulator::DSARP::Speed, ramulator::DSARP::Type, int)
DSARP::DSARP(Org org, Speed speed, Type type, int n_sa) :
  type(type),
  org_entry(org_table[int(org)]),
  speed_entry(speed_table[int(speed)]),
  read_latency(speed_entry.nCL + speed_entry.nBL),
  n_sa(n_sa)
{
  init_speed();
  init_prereq();
  init_rowhit(); // SAUGATA: added row hit function
  init_rowopen();
  init_lambda();
  init_timing();

  // All mechanisms are built on top of REFpb, except for REFab
  b_ref_rank = false;
  switch(int(type)){
    case int(Type::REFAB):
      standard_name = "REFAB";
      b_ref_rank = true;
      break;
    case int(Type::REFPB): standard_name = "REFPB"; break;
    case int(Type::DARP):  standard_name = "DARP"; break;
    case int(Type::SARP):  standard_name = "SARP"; break;
    case int(Type::DSARP): standard_name = "DSARP"; break;
  }

  // Update the SA count (is power of 2, within [1, 128]) and row count
  assert(n_sa && n_sa <= 128 && (n_sa & (n_sa-1)) == 0);
  org_entry.count[int(Level::SubArray)] = n_sa;
  long tmp = long(org_entry.dq) * org_entry.count[int(Level::Bank)] *
    n_sa * org_entry.count[int(Level::Column)];
  org_entry.count[int(Level::Row)] = long(org_entry.size) * (1<<20) / tmp;

  // Change the translation for refresh requests
  if (!b_ref_rank)
    translate[int(Request::Type::REFRESH)] = Command::REFPB;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r8d, %ebp
movl %ecx, %r13d
movl %edx, %r15d
movl %esi, %r12d
movq %rdi, %rbx
movl %ecx, (%rdi)
addq $0x8, %rdi
leaq 0x35c96(%rip), %rsi     # 0xdb170
leaq 0x17(%rsp), %rdx
callq 0x10eea
leaq 0x28(%rbx), %rdi
leaq 0x35c85(%rip), %rsi     # 0xdb174
leaq 0x16(%rsp), %rdx
callq 0x10eea
leaq 0x48(%rbx), %rdi
leaq 0x2d5cb(%rip), %rsi     # 0xd2acf
leaq 0x15(%rsp), %rdx
callq 0x10eea
leaq 0x68(%rbx), %rdi
leaq 0x35c5f(%rip), %rsi     # 0xdb178
leaq 0x14(%rsp), %rdx
callq 0x10eea
leaq 0x88(%rbx), %rdi
leaq 0x2c671(%rip), %rsi     # 0xd1ba2
leaq 0x13(%rsp), %rdx
callq 0x10eea
leaq 0xa8(%rbx), %rdi
leaq 0x35c32(%rip), %rsi     # 0xdb17b
leaq 0x12(%rsp), %rdx
callq 0x10eea
leaq 0xc8(%rbx), %rdi
leaq 0x35c1e(%rip), %rsi     # 0xdb17f
leaq 0x11(%rsp), %rdx
callq 0x10eea
leaq 0xe8(%rbx), %rdi
leaq 0x3ed6e(%rip), %rsi     # 0xe42e7
leaq 0x10(%rsp), %rdx
callq 0x10eea
leaq 0x108(%rbx), %rdi
leaq 0x39376(%rip), %rsi     # 0xde907
leaq 0xf(%rsp), %rdx
callq 0x10eea
leaq 0x128(%rbx), %rdi
leaq 0x35bda(%rip), %rsi     # 0xdb183
leaq 0xe(%rsp), %rdx
callq 0x10eea
leaq 0x148(%rbx), %rdi
leaq 0x35bc6(%rip), %rsi     # 0xdb187
leaq 0xd(%rsp), %rdx
callq 0x10eea
leaq 0x168(%rbx), %rdi
leaq 0x35bb2(%rip), %rsi     # 0xdb18b
leaq 0xc(%rsp), %rdx
callq 0x10eea
movl %r15d, %r14d
leaq 0x188(%rbx), %rdi
leaq 0x35b9b(%rip), %rsi     # 0xdb18f
leaq 0xb(%rsp), %rdx
callq 0x10eea
movups 0x38d87(%rip), %xmm0    # 0xde38c
movups %xmm0, 0x1c8(%rbx)
movups 0x38d69(%rip), %xmm0    # 0xde37c
movups %xmm0, 0x1b8(%rbx)
movups 0x38d4b(%rip), %xmm0    # 0xde36c
movups %xmm0, 0x1a8(%rbx)
movl $0x1, 0x1d8(%rbx)
movups 0x3953b(%rip), %xmm0    # 0xdeb74
movups %xmm0, 0x1dc(%rbx)
movq $0x6, 0x1ec(%rbx)
movups 0x3953a(%rip), %xmm0    # 0xdeb8c
movups %xmm0, 0x1f4(%rbx)
movq $0xb, 0x204(%rbx)
leaq 0x210(%rbx), %rdi
leaq 0x3060(%rbx), %r15
movl $0x2e50, %edx           # imm = 0x2E50
xorl %esi, %esi
callq 0xb1d0
leaq 0x38d1b(%rip), %rsi     # 0xde3a0
pushq $0x18
popq %rcx
movq %r15, %rdi
rep  movsl (%rsi), %es:(%rdi)
movslq %r12d, %rax
shlq $0x5, %rax
movups 0x3060(%rbx,%rax), %xmm0
movups 0x3070(%rbx,%rax), %xmm1
movups %xmm1, 0x30d0(%rbx)
movups %xmm0, 0x30c0(%rbx)
movabsq $0x1000000000, %rax     # imm = 0x1000000000
movq %rax, 0x30e0(%rbx)
movl $0x20, 0x30e8(%rbx)
leaq 0x30f0(%rbx), %rdi
leaq 0x38d25(%rip), %rsi     # 0xde400
pushq $0x10
popq %rax
movq %rax, %rcx
rep  movsq (%rsi), %es:(%rdi)
leaq 0x3170(%rbx), %rdi
movslq %r14d, %rcx
shlq $0x7, %rcx
leaq (%rbx,%rcx), %rsi
addq $0x30f0, %rsi           # imm = 0x30F0
movq %rax, %rcx
rep  movsq (%rsi), %es:(%rdi)
movl 0x3188(%rbx), %eax
addl 0x3194(%rbx), %eax
movl %eax, 0x31f0(%rbx)
movl %ebp, 0x31f4(%rbx)
movabsq $0x3ff2353f7ced9168, %rax # imm = 0x3FF2353F7CED9168
movq %rax, 0x3200(%rbx)
movq %rbx, %rdi
callq 0xa59de
movq %rbx, %rdi
callq 0xa5a7a
movq %rbx, %rdi
callq 0xa5cd8
movq %rbx, %rdi
callq 0xa5d46
movq %rbx, %rdi
callq 0xa5db4
movq %rbx, %rdi
callq 0xa628c
movb $0x0, 0x31f8(%rbx)
cmpl $0x4, %r13d
ja 0xa57c4
movl %r13d, %eax
leaq 0x38be5(%rip), %rcx     # 0xde358
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
leaq 0x39186(%rip), %rsi     # 0xde907
jmpq *%rax
leaq 0x90f1e(%rip), %rdi     # 0x1366a8
leaq 0x3917c(%rip), %rsi     # 0xde90d
callq 0xb510
movb $0x1, 0x31f8(%rbx)
jmp 0xa57c4
leaq 0x2bc28(%rip), %rsi     # 0xd13ce
jmp 0xa57b8
leaq 0x39164(%rip), %rsi     # 0xde913
jmp 0xa57b8
leaq 0x2bc17(%rip), %rsi     # 0xd13cf
leaq 0x90ee9(%rip), %rdi     # 0x1366a8
callq 0xb510
testl %ebp, %ebp
je 0xa5871
cmpl $0x80, %ebp
jg 0xa5871
movl %ebp, %eax
shrl %eax
andl $0x55555555, %eax       # imm = 0x55555555
movl %ebp, %ecx
subl %eax, %ecx
movl $0x33333333, %eax       # imm = 0x33333333
movl %ecx, %edx
andl %eax, %edx
shrl $0x2, %ecx
andl %eax, %ecx
addl %edx, %ecx
movl %ecx, %eax
shrl $0x4, %eax
addl %ecx, %eax
andl $0xf0f0f0f, %eax        # imm = 0xF0F0F0F
imull $0x1010101, %eax, %eax  # imm = 0x1010101
shrl $0x18, %eax
cmpl $0x2, %eax
jae 0xa5871
movl %ebp, 0x30d4(%rbx)
movslq 0x30c4(%rbx), %rax
movslq 0x30d0(%rbx), %rcx
movslq %ebp, %rdx
imulq %rax, %rdx
movslq 0x30dc(%rbx), %rsi
imulq %rcx, %rsi
imulq %rdx, %rsi
movslq 0x30c0(%rbx), %rax
shlq $0x14, %rax
cqto
idivq %rsi
movl %eax, 0x30d8(%rbx)
cmpb $0x0, 0x31f8(%rbx)
jne 0xa5862
movl $0x8, 0x1fc(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x390a0(%rip), %rdi     # 0xde918
leaq 0x390c7(%rip), %rsi     # 0xde946
leaq 0x390ce(%rip), %rcx     # 0xde954
pushq $0x3f
popq %rdx
callq 0xb210
movq %rax, %r14
movl $0x188, %r15d           # imm = 0x188
jmp 0xa5906
movq %rax, %r14
movl $0x168, %r15d           # imm = 0x168
jmp 0xa5906
movq %rax, %r14
movl $0x148, %r15d           # imm = 0x148
jmp 0xa5906
movq %rax, %r14
movl $0x128, %r15d           # imm = 0x128
jmp 0xa5906
movq %rax, %r14
movl $0x108, %r15d           # imm = 0x108
jmp 0xa5906
movq %rax, %r14
movl $0xe8, %r15d
jmp 0xa5906
movq %rax, %r14
movl $0xc8, %r15d
jmp 0xa5906
movq %rax, %r14
movl $0xa8, %r15d
jmp 0xa5906
movq %rax, %r14
movl $0x88, %r15d
jmp 0xa5906
movq %rax, %r14
pushq $0x68
jmp 0xa5904
movq %rax, %r14
pushq $0x48
jmp 0xa5904
movq %rax, %r14
pushq $0x28
popq %r15
addq $-0x20, %rbx
leaq (%rbx,%r15), %rdi
addq $-0x20, %r15
callq 0xb568
cmpq $0x8, %r15
jne 0xa590a
jmp 0xa59d6
movq %rax, %r14
leaq 0x3040(%rbx), %r15
xorl %r12d, %r12d
leaq (%r15,%r12), %rdi
callq 0x96b6a
addq $-0x20, %r12
cmpq $-0x9c0, %r12           # imm = 0xF640
jne 0xa592f
leaq 0x2688(%rbx), %r15
xorl %r12d, %r12d
leaq (%r15,%r12), %rdi
callq 0x86146
addq $-0x18, %r12
cmpq $-0x750, %r12           # imm = 0xF8B0
jne 0xa594f
leaq 0x1f30(%rbx), %r15
xorl %r12d, %r12d
leaq (%r15,%r12), %rdi
callq 0x96b6a
addq $-0x20, %r12
cmpq $-0x9c0, %r12           # imm = 0xF640
jne 0xa596f
movl $0x1570, %r15d          # imm = 0x1570
leaq (%rbx,%r15), %rdi
callq 0x96b6a
addq $-0x20, %r15
cmpq $0xbb0, %r15            # imm = 0xBB0
jne 0xa598b
movl $0xbb0, %r15d           # imm = 0xBB0
leaq (%rbx,%r15), %rdi
callq 0x96b6a
addq $-0x20, %r15
cmpq $0x1f0, %r15            # imm = 0x1F0
jne 0xa59a7
movl $0x188, %r15d           # imm = 0x188
leaq (%rbx,%r15), %rdi
callq 0xb568
addq $-0x20, %r15
cmpq $-0x18, %r15
jne 0xa59c3
movq %r14, %rdi
callq 0xb4d0