// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %rax
movl %r8d, %ebp
movl %ecx, %r13d
movl %edx, %r15d
movl %esi, %r12d
movq %rdi, %rbx
movl %ecx, (%rdi)
addq $0x8, %rdi
leaq 0x18(%rbx), %rax
movq %rax, 0x8(%rbx)
leaq 0x43032(%rip), %rsi     # 0x1541d1
leaq 0x4302e(%rip), %rdx     # 0x1541d4
callq 0x175a0
leaq 0x28(%rbx), %rdi
leaq 0x38(%rbx), %rax
movq %rax, 0x28(%rbx)
leaq 0x43017(%rip), %rsi     # 0x1541d5
leaq 0x43013(%rip), %rdx     # 0x1541d8
callq 0x175a0
leaq 0x48(%rbx), %rdi
leaq 0x58(%rbx), %rax
movq %rax, 0x48(%rbx)
leaq 0x3a976(%rip), %rsi     # 0x14bb53
leaq 0x3a973(%rip), %rdx     # 0x14bb57
callq 0x175a0
leaq 0x68(%rbx), %rdi
leaq 0x78(%rbx), %rax
movq %rax, 0x68(%rbx)
leaq 0x42fdd(%rip), %rsi     # 0x1541d9
leaq 0x42fd8(%rip), %rdx     # 0x1541db
callq 0x175a0
leaq 0x88(%rbx), %rdi
leaq 0x98(%rbx), %rax
movq %rax, 0x88(%rbx)
leaq 0x399be(%rip), %rsi     # 0x14abe2
leaq 0x399b9(%rip), %rdx     # 0x14abe4
callq 0x175a0
leaq 0xa8(%rbx), %rdi
leaq 0xb8(%rbx), %rax
movq %rax, 0xa8(%rbx)
leaq 0x42f90(%rip), %rsi     # 0x1541dc
leaq 0x42f8c(%rip), %rdx     # 0x1541df
callq 0x175a0
leaq 0xc8(%rbx), %rdi
leaq 0xd8(%rbx), %rax
movq %rax, 0xc8(%rbx)
leaq 0x42f6c(%rip), %rsi     # 0x1541e0
leaq 0x42f68(%rip), %rdx     # 0x1541e3
callq 0x175a0
leaq 0xe8(%rbx), %rdi
leaq 0xf8(%rbx), %rax
movq %rax, 0xe8(%rbx)
leaq 0x4c08b(%rip), %rsi     # 0x15d327
leaq 0x4c087(%rip), %rdx     # 0x15d32a
callq 0x175a0
leaq 0x108(%rbx), %rdi
leaq 0x118(%rbx), %rax
movq %rax, 0x108(%rbx)
leaq 0x466a0(%rip), %rsi     # 0x157964
leaq 0x4669e(%rip), %rdx     # 0x157969
callq 0x175a0
leaq 0x128(%rbx), %rdi
leaq 0x138(%rbx), %rax
movq %rax, 0x128(%rbx)
leaq 0x42ef8(%rip), %rsi     # 0x1541e4
leaq 0x42ef4(%rip), %rdx     # 0x1541e7
callq 0x175a0
leaq 0x148(%rbx), %rdi
leaq 0x158(%rbx), %rax
movq %rax, 0x148(%rbx)
leaq 0x42ed4(%rip), %rsi     # 0x1541e8
leaq 0x42ed0(%rip), %rdx     # 0x1541eb
callq 0x175a0
leaq 0x168(%rbx), %rdi
leaq 0x178(%rbx), %rax
movq %rax, 0x168(%rbx)
leaq 0x42eb0(%rip), %rsi     # 0x1541ec
leaq 0x42eac(%rip), %rdx     # 0x1541ef
callq 0x175a0
movl %r15d, %r14d
leaq 0x188(%rbx), %rdi
leaq 0x198(%rbx), %rax
movq %rax, 0x188(%rbx)
leaq 0x42e89(%rip), %rsi     # 0x1541f0
leaq 0x42e85(%rip), %rdx     # 0x1541f3
callq 0x175a0
movups 0x46072(%rip), %xmm0    # 0x1573ec
movups %xmm0, 0x1c8(%rbx)
movups 0x46054(%rip), %xmm0    # 0x1573dc
movups %xmm0, 0x1b8(%rbx)
movups 0x46036(%rip), %xmm0    # 0x1573cc
movups %xmm0, 0x1a8(%rbx)
movl $0x1, 0x1d8(%rbx)
movups 0x46822(%rip), %xmm0    # 0x157bd0
movups %xmm0, 0x1dc(%rbx)
movq $0x6, 0x1ec(%rbx)
movups 0x46821(%rip), %xmm0    # 0x157be8
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 0x46006(%rip), %rsi     # 0x157400
movl $0x18, %ecx
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 0x4600e(%rip), %rsi     # 0x157460
movl $0x10, %ecx
rep  movsq (%rsi), %es:(%rdi)
leaq 0x3170(%rbx), %rdi
movslq %r14d, %rax
shlq $0x7, %rax
leaq (%rbx,%rax), %rsi
addq $0x30f0, %rsi           # imm = 0x30F0
movl $0x10, %ecx
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 0x1117f2
movq %rbx, %rdi
callq 0x11189c
movq %rbx, %rdi
callq 0x111b82
movq %rbx, %rdi
callq 0x111c0a
movq %rbx, %rdi
callq 0x111c92
movq %rbx, %rdi
callq 0x1122d2
movb $0x0, 0x31f8(%rbx)
cmpl $0x4, %r13d
ja 0x111566
movl $0x5, %r8d
movl %r13d, %eax
leaq 0x45ec3(%rip), %rcx     # 0x1573b8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x8f1ab(%rip), %rdx     # 0x1a06b0
leaq 0x8f19c(%rip), %rdi     # 0x1a06a8
leaq 0x46457(%rip), %rcx     # 0x15796a
xorl %esi, %esi
callq 0xb430
movb $0x1, 0x31f8(%rbx)
jmp 0x111566
leaq 0x38ee4(%rip), %rcx     # 0x14a40e
jmp 0x111551
movl $0x4, %r8d
leaq 0x46437(%rip), %rcx     # 0x157970
jmp 0x111551
movl $0x4, %r8d
leaq 0x38ec7(%rip), %rcx     # 0x14a40f
jmp 0x111551
leaq 0x46413(%rip), %rcx     # 0x157964
movq 0x8f158(%rip), %rdx     # 0x1a06b0
leaq 0x8f149(%rip), %rdi     # 0x1a06a8
xorl %esi, %esi
callq 0xb430
testl %ebp, %ebp
je 0x111613
cmpl $0x80, %ebp
jg 0x111613
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 0x111613
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 0x111604
movl $0x8, 0x1fc(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4635b(%rip), %rdi     # 0x157975
leaq 0x46382(%rip), %rsi     # 0x1579a3
leaq 0x46389(%rip), %rcx     # 0x1579b1
movl $0x3f, %edx
callq 0xb200
movq %rax, %r14
movl $0x188, %r15d           # imm = 0x188
jmp 0x1116b4
movq %rax, %r14
movl $0x168, %r15d           # imm = 0x168
jmp 0x1116b4
movq %rax, %r14
movl $0x148, %r15d           # imm = 0x148
jmp 0x1116b4
movq %rax, %r14
movl $0x128, %r15d           # imm = 0x128
jmp 0x1116b4
movq %rax, %r14
movl $0x108, %r15d           # imm = 0x108
jmp 0x1116b4
movq %rax, %r14
movl $0xe8, %r15d
jmp 0x1116b4
movq %rax, %r14
movl $0xc8, %r15d
jmp 0x1116b4
movq %rax, %r14
movl $0xa8, %r15d
jmp 0x1116b4
movq %rax, %r14
movl $0x88, %r15d
jmp 0x1116b4
movq %rax, %r14
movl $0x68, %r15d
jmp 0x1116b4
movq %rax, %r14
movl $0x48, %r15d
jmp 0x1116b4
movq %rax, %r14
movl $0x28, %r15d
addq $-0x10, %rbx
leaq (%rbx,%r15), %rax
movq -0x10(%rbx,%r15), %rdi
cmpq %rdi, %rax
je 0x1116d1
movq (%rax), %rsi
incq %rsi
callq 0xb2f0
addq $-0x20, %r15
cmpq $0x8, %r15
jne 0x1116b8
jmp 0x1117dc
movq %rax, %r14
leaq 0x3040(%rbx), %r15
xorl %r12d, %r12d
movq 0x3050(%rbx,%r12), %rax
testq %rax, %rax
je 0x111708
leaq (%r15,%r12), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
addq $-0x20, %r12
cmpq $-0x9c0, %r12           # imm = 0xF640
jne 0x1116ed
movl $0x2698, %r15d          # imm = 0x2698
movq -0x10(%rbx,%r15), %rdi
testq %rdi, %rdi
je 0x111731
movq (%rbx,%r15), %rsi
subq %rdi, %rsi
callq 0xb2f0
addq $-0x18, %r15
cmpq $0x1f48, %r15           # imm = 0x1F48
jne 0x11171b
leaq 0x1f30(%rbx), %r15
xorl %r12d, %r12d
movq 0x1f40(%rbx,%r12), %rax
testq %rax, %rax
je 0x111763
leaq (%r15,%r12), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
addq $-0x20, %r12
cmpq $-0x9c0, %r12           # imm = 0xF640
jne 0x111748
leaq 0x1570(%rbx), %r15
xorl %r12d, %r12d
movq 0x1580(%rbx,%r12), %rax
testq %rax, %rax
je 0x111795
leaq (%r15,%r12), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
addq $-0x20, %r12
cmpq $-0x9c0, %r12           # imm = 0xF640
jne 0x11177a
leaq 0xbb0(%rbx), %r15
xorl %r12d, %r12d
movq 0xbc0(%rbx,%r12), %rax
testq %rax, %rax
je 0x1117c7
leaq (%r15,%r12), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
addq $-0x20, %r12
cmpq $-0x9c0, %r12           # imm = 0xF640
jne 0x1117ac
movq %rbx, %rdi
callq 0xbddb
movq %r14, %rdi
callq 0xb510
jmp 0x1117ea
jmp 0x1117ea
jmp 0x1117ea
movq %rax, %rdi
callq 0x171a3