// File: /workspace/github_cpp_makefile_star2_O1/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, %r14d
movl %edx, %r15d
movl %esi, %r12d
movq %rdi, %rbx
movl %ecx, (%rdi)
addq $0x8, %rdi
leaq 0x18(%rbx), %rax
movq %rax, 0x8(%rbx)
leaq 0x42fde(%rip), %rsi     # 0x157161
leaq 0x42fda(%rip), %rdx     # 0x157164
callq 0x17586
leaq 0x28(%rbx), %rdi
leaq 0x38(%rbx), %rax
movq %rax, 0x28(%rbx)
leaq 0x42fc3(%rip), %rsi     # 0x157165
leaq 0x42fbf(%rip), %rdx     # 0x157168
callq 0x17586
leaq 0x48(%rbx), %rdi
leaq 0x58(%rbx), %rax
movq %rax, 0x48(%rbx)
leaq 0x3a952(%rip), %rsi     # 0x14eb13
leaq 0x3a94f(%rip), %rdx     # 0x14eb17
callq 0x17586
leaq 0x68(%rbx), %rdi
leaq 0x78(%rbx), %rax
movq %rax, 0x68(%rbx)
leaq 0x42f89(%rip), %rsi     # 0x157169
leaq 0x42f84(%rip), %rdx     # 0x15716b
callq 0x17586
leaq 0x88(%rbx), %rdi
leaq 0x98(%rbx), %rax
movq %rax, 0x88(%rbx)
leaq 0x3999a(%rip), %rsi     # 0x14dba2
leaq 0x39995(%rip), %rdx     # 0x14dba4
callq 0x17586
leaq 0xa8(%rbx), %rdi
leaq 0xb8(%rbx), %rax
movq %rax, 0xa8(%rbx)
leaq 0x42f3c(%rip), %rsi     # 0x15716c
leaq 0x42f38(%rip), %rdx     # 0x15716f
callq 0x17586
leaq 0xc8(%rbx), %rdi
leaq 0xd8(%rbx), %rax
movq %rax, 0xc8(%rbx)
leaq 0x42f18(%rip), %rsi     # 0x157170
leaq 0x42f14(%rip), %rdx     # 0x157173
callq 0x17586
leaq 0xe8(%rbx), %rdi
leaq 0xf8(%rbx), %rax
movq %rax, 0xe8(%rbx)
leaq 0x4c002(%rip), %rsi     # 0x160282
leaq 0x4bffe(%rip), %rdx     # 0x160285
callq 0x17586
leaq 0x108(%rbx), %rdi
leaq 0x118(%rbx), %rax
movq %rax, 0x108(%rbx)
leaq 0x46622(%rip), %r13     # 0x15a8ca
leaq 0x46620(%rip), %rdx     # 0x15a8cf
movq %r13, %rsi
callq 0x17586
leaq 0x128(%rbx), %rdi
leaq 0x138(%rbx), %rax
movq %rax, 0x128(%rbx)
leaq 0x42ea1(%rip), %rsi     # 0x157174
leaq 0x42e9d(%rip), %rdx     # 0x157177
callq 0x17586
leaq 0x148(%rbx), %rdi
leaq 0x158(%rbx), %rax
movq %rax, 0x148(%rbx)
leaq 0x42e7d(%rip), %rsi     # 0x157178
leaq 0x42e79(%rip), %rdx     # 0x15717b
callq 0x17586
leaq 0x168(%rbx), %rdi
leaq 0x178(%rbx), %rax
movq %rax, 0x168(%rbx)
leaq 0x42e59(%rip), %rsi     # 0x15717c
leaq 0x42e55(%rip), %rdx     # 0x15717f
callq 0x17586
leaq 0x188(%rbx), %rdi
leaq 0x198(%rbx), %rax
movq %rax, 0x188(%rbx)
leaq 0x42e35(%rip), %rsi     # 0x157180
leaq 0x42e31(%rip), %rdx     # 0x157183
callq 0x17586
movups 0x4602e(%rip), %xmm0    # 0x15a38c
movups %xmm0, 0x1c8(%rbx)
movups 0x46010(%rip), %xmm0    # 0x15a37c
movups %xmm0, 0x1b8(%rbx)
movups 0x45ff2(%rip), %xmm0    # 0x15a36c
movups %xmm0, 0x1a8(%rbx)
movl $0x1, 0x1d8(%rbx)
movups 0x467a6(%rip), %xmm0    # 0x15ab38
movups %xmm0, 0x1dc(%rbx)
movq $0x6, 0x1ec(%rbx)
movups 0x467a5(%rip), %xmm0    # 0x15ab50
movups %xmm0, 0x1f4(%rbx)
movq $0xb, 0x204(%rbx)
leaq 0x210(%rbx), %rdi
movl $0x9c0, %edx            # imm = 0x9C0
xorl %esi, %esi
callq 0xb1d0
leaq 0xbd0(%rbx), %rdi
movl $0x9c0, %edx            # imm = 0x9C0
xorl %esi, %esi
callq 0xb1d0
leaq 0x1590(%rbx), %rdi
movl $0x9c0, %edx            # imm = 0x9C0
xorl %esi, %esi
callq 0xb1d0
leaq 0x1f50(%rbx), %rdi
movl $0x750, %edx            # imm = 0x750
xorl %esi, %esi
callq 0xb1d0
leaq 0x26a0(%rbx), %rdi
movl $0x9c0, %edx            # imm = 0x9C0
xorl %esi, %esi
callq 0xb1d0
leaq 0x3060(%rbx), %rdi
leaq 0x45f76(%rip), %rsi     # 0x15a3a0
movl $0x18, %ecx
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 0x45f81(%rip), %rsi     # 0x15a400
movl $0x10, %ecx
rep  movsq (%rsi), %es:(%rdi)
leaq 0x3170(%rbx), %rdi
movslq %r15d, %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 0x11482c
movq %rbx, %rdi
callq 0x1148d6
movq %rbx, %rdi
callq 0x114c1e
movq %rbx, %rdi
callq 0x114cb4
movq %rbx, %rdi
callq 0x114d4a
movq %rbx, %rdi
callq 0x115478
movb $0x0, 0x31f8(%rbx)
cmpl $0x4, %r14d
ja 0x114589
movl $0x5, %r8d
movl %r14d, %eax
leaq 0x45e3a(%rip), %rcx     # 0x15a358
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x90182(%rip), %rdx     # 0x1a46b0
leaq 0x90173(%rip), %rdi     # 0x1a46a8
leaq 0x46394(%rip), %rcx     # 0x15a8d0
xorl %esi, %esi
callq 0xb430
movb $0x1, 0x31f8(%rbx)
jmp 0x114589
leaq 0x38e7b(%rip), %r13     # 0x14d3ce
jmp 0x114571
movl $0x4, %r8d
leaq 0x46374(%rip), %r13     # 0x15a8d6
jmp 0x114571
movl $0x4, %r8d
leaq 0x38e5e(%rip), %r13     # 0x14d3cf
movq 0x90138(%rip), %rdx     # 0x1a46b0
leaq 0x90129(%rip), %rdi     # 0x1a46a8
xorl %esi, %esi
movq %r13, %rcx
callq 0xb430
testl %ebp, %ebp
je 0x114636
cmpl $0x80, %ebp
jg 0x114636
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 0x114636
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 0x114627
movl $0x8, 0x1fc(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4629e(%rip), %rdi     # 0x15a8db
leaq 0x462c5(%rip), %rsi     # 0x15a909
leaq 0x462cc(%rip), %rcx     # 0x15a917
movl $0x3f, %edx
callq 0xb200
movq %rax, %r14
movl $0x188, %r15d           # imm = 0x188
jmp 0x1146d7
movq %rax, %r14
movl $0x168, %r15d           # imm = 0x168
jmp 0x1146d7
movq %rax, %r14
movl $0x148, %r15d           # imm = 0x148
jmp 0x1146d7
movq %rax, %r14
movl $0x128, %r15d           # imm = 0x128
jmp 0x1146d7
movq %rax, %r14
movl $0x108, %r15d           # imm = 0x108
jmp 0x1146d7
movq %rax, %r14
movl $0xe8, %r15d
jmp 0x1146d7
movq %rax, %r14
movl $0xc8, %r15d
jmp 0x1146d7
movq %rax, %r14
movl $0xa8, %r15d
jmp 0x1146d7
movq %rax, %r14
movl $0x88, %r15d
jmp 0x1146d7
movq %rax, %r14
movl $0x68, %r15d
jmp 0x1146d7
movq %rax, %r14
movl $0x48, %r15d
jmp 0x1146d7
movq %rax, %r14
movl $0x28, %r15d
xorl %eax, %eax
testb %al, %al
jne 0x114816
addq $-0x10, %rbx
leaq (%rbx,%r15), %rax
movq -0x10(%rbx,%r15), %rdi
cmpq %rdi, %rax
je 0x1146fe
movq (%rax), %rsi
incq %rsi
callq 0xb2f0
addq $-0x20, %r15
cmpq $0x8, %r15
jne 0x1146e5
jmp 0x114816
movq %rax, %r14
movl $0x8, %r15d
movb $0x1, %al
jmp 0x1146d9
movq %rax, %r14
leaq 0x3040(%rbx), %r15
xorl %r12d, %r12d
movq 0x3050(%rbx,%r12), %rax
testq %rax, %rax
je 0x114742
leaq (%r15,%r12), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
addq $-0x20, %r12
cmpq $-0x9c0, %r12           # imm = 0xF640
jne 0x114727
movl $0x2698, %r15d          # imm = 0x2698
movq -0x10(%rbx,%r15), %rdi
testq %rdi, %rdi
je 0x11476b
movq (%rbx,%r15), %rsi
subq %rdi, %rsi
callq 0xb2f0
addq $-0x18, %r15
cmpq $0x1f48, %r15           # imm = 0x1F48
jne 0x114755
leaq 0x1f30(%rbx), %r15
xorl %r12d, %r12d
movq 0x1f40(%rbx,%r12), %rax
testq %rax, %rax
je 0x11479d
leaq (%r15,%r12), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
addq $-0x20, %r12
cmpq $-0x9c0, %r12           # imm = 0xF640
jne 0x114782
leaq 0x1570(%rbx), %r15
xorl %r12d, %r12d
movq 0x1580(%rbx,%r12), %rax
testq %rax, %rax
je 0x1147cf
leaq (%r15,%r12), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
addq $-0x20, %r12
cmpq $-0x9c0, %r12           # imm = 0xF640
jne 0x1147b4
leaq 0xbb0(%rbx), %r15
xorl %r12d, %r12d
movq 0xbc0(%rbx,%r12), %rax
testq %rax, %rax
je 0x114801
leaq (%r15,%r12), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
addq $-0x20, %r12
cmpq $-0x9c0, %r12           # imm = 0xF640
jne 0x1147e6
movq %rbx, %rdi
callq 0xbdab
movq %r14, %rdi
callq 0xb510
jmp 0x114824
jmp 0x114824
jmp 0x114824
movq %rax, %rdi
callq 0x1718f