// File: CMU-SAFARI[P]ramulator/src/STTMRAM.cpp
// Function: ramulator::STTMRAM::init_speed()
void STTMRAM::init_speed()
{
    // nRRD, nFAW
    int page = (org_entry.dq * org_entry.count[int(Level::Column)]) >> 13;
    switch (speed_entry.rate) {
          case 1600: speed_entry.nRRD = ceil(speed_entry.nRRD  * ((page==1) ? 5 : 6) /10.0); speed_entry.nFAW = ceil(speed_entry.nFAW *((page==1) ? 24 : 32)/10.0); break;
        default: assert(false);
    }

    // nRFC, nXS
    int chip = org_entry.size;
    switch (speed_entry.rate) {
        case 1600: speed_entry.nRFC = 1; break;
        default: assert(false);
    }
    switch (speed_entry.rate) {
          case 1600: speed_entry.nXS  = ceil(speed_entry.nXS * ((chip==512) ? 80  : (chip==1<<10) ? 96  : (chip==1<<11) ? 136 : (chip==1<<12) ? 216 : 288) /10.0); break;
        default: assert(false);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
movl 0x2728(%rax), %ecx
movl 0x273c(%rax), %edx
imull %edx, %ecx
sarl $0xd, %ecx
movl %ecx, -0xc(%rbp)
movl 0x2898(%rax), %eax
subl $0x640, %eax            # imm = 0x640
jne 0x218ec0
jmp 0x218e3c
movq -0x18(%rbp), %rax
movl 0x28e0(%rax), %eax
movl -0xc(%rbp), %esi
movl $0x6, %ecx
movl $0x5, %edx
cmpl $0x1, %esi
cmovel %edx, %ecx
imull %ecx, %eax
cvtsi2sd %eax, %xmm0
movsd 0x49fb0(%rip), %xmm1    # 0x262e18
divsd %xmm1, %xmm0
callq 0xc0c0
movq -0x18(%rbp), %rax
cvttsd2si %xmm0, %ecx
movl %ecx, 0x28e0(%rax)
movl 0x28e4(%rax), %eax
movl -0xc(%rbp), %esi
movl $0x20, %ecx
movl $0x18, %edx
cmpl $0x1, %esi
cmovel %edx, %ecx
imull %ecx, %eax
cvtsi2sd %eax, %xmm0
movsd 0x49f71(%rip), %xmm1    # 0x262e18
divsd %xmm1, %xmm0
callq 0xc0c0
movq -0x18(%rbp), %rax
cvttsd2si %xmm0, %ecx
movl %ecx, 0x28e4(%rax)
jmp 0x218edf
leaq 0x36c9a(%rip), %rdi     # 0x24fb61
leaq 0x4a823(%rip), %rsi     # 0x2636f1
movl $0x44, %edx
leaq 0x4a827(%rip), %rcx     # 0x263701
callq 0xc280
movq -0x18(%rbp), %rax
movl 0x2724(%rax), %ecx
movl %ecx, -0x10(%rbp)
movl 0x2898(%rax), %eax
subl $0x640, %eax            # imm = 0x640
jne 0x218f0b
jmp 0x218efb
movq -0x18(%rbp), %rax
movl $0x1, 0x28e8(%rax)
jmp 0x218f2a
leaq 0x36c4f(%rip), %rdi     # 0x24fb61
leaq 0x4a7d8(%rip), %rsi     # 0x2636f1
movl $0x4b, %edx
leaq 0x4a7dc(%rip), %rcx     # 0x263701
callq 0xc280
movq -0x18(%rbp), %rax
movl 0x2898(%rax), %eax
subl $0x640, %eax            # imm = 0x640
jne 0x218fda
jmp 0x218f41
movq -0x18(%rbp), %rax
movl 0x2900(%rax), %eax
movl %eax, -0x1c(%rbp)
cmpl $0x200, -0x10(%rbp)     # imm = 0x200
jne 0x218f61
movl $0x50, %eax
movl %eax, -0x20(%rbp)
jmp 0x218fac
cmpl $0x400, -0x10(%rbp)     # imm = 0x400
jne 0x218f74
movl $0x60, %eax
movl %eax, -0x24(%rbp)
jmp 0x218fa6
cmpl $0x800, -0x10(%rbp)     # imm = 0x800
jne 0x218f87
movl $0x88, %eax
movl %eax, -0x28(%rbp)
jmp 0x218fa0
movl -0x10(%rbp), %edx
movl $0x120, %eax            # imm = 0x120
movl $0xd8, %ecx
cmpl $0x1000, %edx           # imm = 0x1000
cmovel %ecx, %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %eax
movl -0x20(%rbp), %ecx
imull %ecx, %eax
cvtsi2sd %eax, %xmm0
movsd 0x49e57(%rip), %xmm1    # 0x262e18
divsd %xmm1, %xmm0
callq 0xc0c0
movq -0x18(%rbp), %rax
cvttsd2si %xmm0, %ecx
movl %ecx, 0x2900(%rax)
jmp 0x218ff9
leaq 0x36b80(%rip), %rdi     # 0x24fb61
leaq 0x4a709(%rip), %rsi     # 0x2636f1
movl $0x4f, %edx
leaq 0x4a70d(%rip), %rcx     # 0x263701
callq 0xc280
addq $0x30, %rsp
popq %rbp
retq
nop