// File: CMU-SAFARI[P]ramulator/src/TLDRAM.cpp
// Function: ramulator::TLDRAM::init_speed()
void TLDRAM::init_speed()
{
    // nRRD, nFAW
    int page = (org_entry.dq * org_entry.count[int(Level::Column)]) >> 13;
    switch (speed_entry.rate) {
        case 800:  speed_entry.nRRD = (page==1) ? 4 : 4;
          speed_entry.nFAW = (page==1) ? 16 : 20;
          break;
        case 1066: speed_entry.nRRD = (page==1) ? 4 : 6;
          speed_entry.nFAW = (page==1) ? 20 : 27;
          break;
        case 1333:
          speed_entry.nRRD = (page==1) ? 4 : 5;
          speed_entry.nFAW = (page==1) ? 20 : 30;
          break;
        case 1600:
          speed_entry.nRRD = (page==1) ? 5 : 6;
          speed_entry.nFAW = (page==1) ? 24 : 32;
          break;
        case 1866:
          speed_entry.nRRD = (page==1) ? 5 : 6;
          speed_entry.nFAW = (page==1) ? 26 : 33;
          break;
        case 2133:
          speed_entry.nRRD = (page==1) ? 5 : 6;
          speed_entry.nFAW = (page==1) ? 27 : 34;
          break;
        default: assert(false);
    }

    // nRFC, nXS
    int chip = org_entry.size;
    switch (speed_entry.rate) {
        case 800:  speed_entry.nRFC = (chip==512) ? 36  : (chip==1<<10) ? 44
          : (chip==1<<11) ? 64  : (chip==1<<12) ? 104 : 140; break;
        case 1066: speed_entry.nRFC = (chip==512) ? 48  : (chip==1<<10) ? 59
          : (chip==1<<11) ? 86  : (chip==1<<12) ? 139 : 187; break;
        case 1333: speed_entry.nRFC = (chip==512) ? 60  : (chip==1<<10) ? 74
          : (chip==1<<11) ? 107 : (chip==1<<12) ? 174 : 234; break;
        case 1600: speed_entry.nRFC = (chip==512) ? 72  : (chip==1<<10) ? 88
          : (chip==1<<11) ? 128 : (chip==1<<12) ? 208 : 280; break;
        case 1866: speed_entry.nRFC = (chip==512) ? 84  : (chip==1<<10) ? 103
          : (chip==1<<11) ? 150 : (chip==1<<12) ? 243 : 327; break;
        case 2133: speed_entry.nRFC = (chip==512) ? 96  : (chip==1<<10) ? 118
          : (chip==1<<11) ? 171 : (chip==1<<12) ? 278 : 374; break;
        default: assert(false);
    }
    switch (speed_entry.rate) {
        case 800:  speed_entry.nXS  = (chip==512) ? 40  : (chip==1<<10) ? 48
          : (chip==1<<11) ? 68  : (chip==1<<12) ? 108 : 144; break;
        case 1066: speed_entry.nXS  = (chip==512) ? 54  : (chip==1<<10) ? 64
          : (chip==1<<11) ? 91  : (chip==1<<12) ? 144 : 192; break;
        case 1333: speed_entry.nXS  = (chip==512) ? 67  : (chip==1<<10) ? 80
          : (chip==1<<11) ? 114 : (chip==1<<12) ? 180 : 240; break;
        case 1600: speed_entry.nXS  = (chip==512) ? 80  : (chip==1<<10) ? 96
          : (chip==1<<11) ? 136 : (chip==1<<12) ? 216 : 288; break;
        case 1866: speed_entry.nXS  = (chip==512) ? 94  : (chip==1<<10) ? 112
          : (chip==1<<11) ? 159 : (chip==1<<12) ? 252 : 336; break;
        case 2133: speed_entry.nXS  = (chip==512) ? 107 : (chip==1<<10) ? 128
          : (chip==1<<11) ? 182 : (chip==1<<12) ? 288 : 384; break;
        default: assert(false);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
movl 0x36b8(%rax), %ecx
movl 0x36cc(%rax), %edx
imull %edx, %ecx
sarl $0xd, %ecx
movl %ecx, -0xc(%rbp)
movl 0x3eb8(%rax), %eax
movl %eax, -0x14(%rbp)
subl $0x320, %eax            # imm = 0x320
je 0x2269dd
jmp 0x22698e
movl -0x14(%rbp), %eax
subl $0x42a, %eax            # imm = 0x42A
je 0x226a13
jmp 0x22699a
movl -0x14(%rbp), %eax
subl $0x535, %eax            # imm = 0x535
je 0x226a4e
jmp 0x2269aa
movl -0x14(%rbp), %eax
subl $0x640, %eax            # imm = 0x640
je 0x226a89
jmp 0x2269ba
movl -0x14(%rbp), %eax
subl $0x74a, %eax            # imm = 0x74A
je 0x226ac4
jmp 0x2269ca
movl -0x14(%rbp), %eax
subl $0x855, %eax            # imm = 0x855
je 0x226afc
jmp 0x226b34
movq -0x20(%rbp), %rax
movl -0xc(%rbp), %edx
movl $0x4, %ecx
cmpl $0x1, %edx
cmovel %ecx, %ecx
movl %ecx, 0x3f00(%rax)
movl -0xc(%rbp), %esi
movl $0x14, %ecx
movl $0x10, %edx
cmpl $0x1, %esi
cmovel %edx, %ecx
movl %ecx, 0x3f04(%rax)
jmp 0x226b53
movq -0x20(%rbp), %rax
movl -0xc(%rbp), %esi
movl $0x6, %ecx
movl $0x4, %edx
cmpl $0x1, %esi
cmovel %edx, %ecx
movl %ecx, 0x3f00(%rax)
movl -0xc(%rbp), %esi
movl $0x1b, %ecx
movl $0x14, %edx
cmpl $0x1, %esi
cmovel %edx, %ecx
movl %ecx, 0x3f04(%rax)
jmp 0x226b53
movq -0x20(%rbp), %rax
movl -0xc(%rbp), %esi
movl $0x5, %ecx
movl $0x4, %edx
cmpl $0x1, %esi
cmovel %edx, %ecx
movl %ecx, 0x3f00(%rax)
movl -0xc(%rbp), %esi
movl $0x1e, %ecx
movl $0x14, %edx
cmpl $0x1, %esi
cmovel %edx, %ecx
movl %ecx, 0x3f04(%rax)
jmp 0x226b53
movq -0x20(%rbp), %rax
movl -0xc(%rbp), %esi
movl $0x6, %ecx
movl $0x5, %edx
cmpl $0x1, %esi
cmovel %edx, %ecx
movl %ecx, 0x3f00(%rax)
movl -0xc(%rbp), %esi
movl $0x20, %ecx
movl $0x18, %edx
cmpl $0x1, %esi
cmovel %edx, %ecx
movl %ecx, 0x3f04(%rax)
jmp 0x226b53
movq -0x20(%rbp), %rax
movl -0xc(%rbp), %esi
movl $0x6, %ecx
movl $0x5, %edx
cmpl $0x1, %esi
cmovel %edx, %ecx
movl %ecx, 0x3f00(%rax)
movl -0xc(%rbp), %esi
movl $0x21, %ecx
movl $0x1a, %edx
cmpl $0x1, %esi
cmovel %edx, %ecx
movl %ecx, 0x3f04(%rax)
jmp 0x226b53
movq -0x20(%rbp), %rax
movl -0xc(%rbp), %esi
movl $0x6, %ecx
movl $0x5, %edx
cmpl $0x1, %esi
cmovel %edx, %ecx
movl %ecx, 0x3f00(%rax)
movl -0xc(%rbp), %esi
movl $0x22, %ecx
movl $0x1b, %edx
cmpl $0x1, %esi
cmovel %edx, %ecx
movl %ecx, 0x3f04(%rax)
jmp 0x226b53
leaq 0x29026(%rip), %rdi     # 0x24fb61
leaq 0x3e03c(%rip), %rsi     # 0x264b7e
movl $0x6b, %edx
leaq 0x3e03f(%rip), %rcx     # 0x264b8d
callq 0xc280
movq -0x20(%rbp), %rax
movl 0x36b4(%rax), %ecx
movl %ecx, -0x10(%rbp)
movl 0x3eb8(%rax), %eax
movl %eax, -0x24(%rbp)
subl $0x320, %eax            # imm = 0x320
je 0x226bc5
jmp 0x226b72
movl -0x24(%rbp), %eax
subl $0x42a, %eax            # imm = 0x42A
je 0x226c35
jmp 0x226b82
movl -0x24(%rbp), %eax
subl $0x535, %eax            # imm = 0x535
je 0x226ca5
jmp 0x226b92
movl -0x24(%rbp), %eax
subl $0x640, %eax            # imm = 0x640
je 0x226d15
jmp 0x226ba2
movl -0x24(%rbp), %eax
subl $0x74a, %eax            # imm = 0x74A
je 0x226d85
jmp 0x226bb2
movl -0x24(%rbp), %eax
subl $0x855, %eax            # imm = 0x855
je 0x226df5
jmp 0x226e62
cmpl $0x200, -0x10(%rbp)     # imm = 0x200
jne 0x226bd8
movl $0x24, %eax
movl %eax, -0x28(%rbp)
jmp 0x226c23
cmpl $0x400, -0x10(%rbp)     # imm = 0x400
jne 0x226beb
movl $0x2c, %eax
movl %eax, -0x2c(%rbp)
jmp 0x226c1d
cmpl $0x800, -0x10(%rbp)     # imm = 0x800
jne 0x226bfe
movl $0x40, %eax
movl %eax, -0x30(%rbp)
jmp 0x226c17
movl -0x10(%rbp), %edx
movl $0x8c, %eax
movl $0x68, %ecx
cmpl $0x1000, %edx           # imm = 0x1000
cmovel %ecx, %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movl -0x28(%rbp), %ecx
movl %ecx, 0x3f08(%rax)
jmp 0x226e81
cmpl $0x200, -0x10(%rbp)     # imm = 0x200
jne 0x226c48
movl $0x30, %eax
movl %eax, -0x34(%rbp)
jmp 0x226c93
cmpl $0x400, -0x10(%rbp)     # imm = 0x400
jne 0x226c5b
movl $0x3b, %eax
movl %eax, -0x38(%rbp)
jmp 0x226c8d
cmpl $0x800, -0x10(%rbp)     # imm = 0x800
jne 0x226c6e
movl $0x56, %eax
movl %eax, -0x3c(%rbp)
jmp 0x226c87
movl -0x10(%rbp), %edx
movl $0xbb, %eax
movl $0x8b, %ecx
cmpl $0x1000, %edx           # imm = 0x1000
cmovel %ecx, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x20(%rbp), %rax
movl -0x34(%rbp), %ecx
movl %ecx, 0x3f08(%rax)
jmp 0x226e81
cmpl $0x200, -0x10(%rbp)     # imm = 0x200
jne 0x226cb8
movl $0x3c, %eax
movl %eax, -0x40(%rbp)
jmp 0x226d03
cmpl $0x400, -0x10(%rbp)     # imm = 0x400
jne 0x226ccb
movl $0x4a, %eax
movl %eax, -0x44(%rbp)
jmp 0x226cfd
cmpl $0x800, -0x10(%rbp)     # imm = 0x800
jne 0x226cde
movl $0x6b, %eax
movl %eax, -0x48(%rbp)
jmp 0x226cf7
movl -0x10(%rbp), %edx
movl $0xea, %eax
movl $0xae, %ecx
cmpl $0x1000, %edx           # imm = 0x1000
cmovel %ecx, %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movl -0x40(%rbp), %ecx
movl %ecx, 0x3f08(%rax)
jmp 0x226e81
cmpl $0x200, -0x10(%rbp)     # imm = 0x200
jne 0x226d28
movl $0x48, %eax
movl %eax, -0x4c(%rbp)
jmp 0x226d73
cmpl $0x400, -0x10(%rbp)     # imm = 0x400
jne 0x226d3b
movl $0x58, %eax
movl %eax, -0x50(%rbp)
jmp 0x226d6d
cmpl $0x800, -0x10(%rbp)     # imm = 0x800
jne 0x226d4e
movl $0x80, %eax
movl %eax, -0x54(%rbp)
jmp 0x226d67
movl -0x10(%rbp), %edx
movl $0x118, %eax            # imm = 0x118
movl $0xd0, %ecx
cmpl $0x1000, %edx           # imm = 0x1000
cmovel %ecx, %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x4c(%rbp)
movq -0x20(%rbp), %rax
movl -0x4c(%rbp), %ecx
movl %ecx, 0x3f08(%rax)
jmp 0x226e81
cmpl $0x200, -0x10(%rbp)     # imm = 0x200
jne 0x226d98
movl $0x54, %eax
movl %eax, -0x58(%rbp)
jmp 0x226de3
cmpl $0x400, -0x10(%rbp)     # imm = 0x400
jne 0x226dab
movl $0x67, %eax
movl %eax, -0x5c(%rbp)
jmp 0x226ddd
cmpl $0x800, -0x10(%rbp)     # imm = 0x800
jne 0x226dbe
movl $0x96, %eax
movl %eax, -0x60(%rbp)
jmp 0x226dd7
movl -0x10(%rbp), %edx
movl $0x147, %eax            # imm = 0x147
movl $0xf3, %ecx
cmpl $0x1000, %edx           # imm = 0x1000
cmovel %ecx, %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movl %eax, -0x58(%rbp)
movq -0x20(%rbp), %rax
movl -0x58(%rbp), %ecx
movl %ecx, 0x3f08(%rax)
jmp 0x226e81
cmpl $0x200, -0x10(%rbp)     # imm = 0x200
jne 0x226e08
movl $0x60, %eax
movl %eax, -0x64(%rbp)
jmp 0x226e53
cmpl $0x400, -0x10(%rbp)     # imm = 0x400
jne 0x226e1b
movl $0x76, %eax
movl %eax, -0x68(%rbp)
jmp 0x226e4d
cmpl $0x800, -0x10(%rbp)     # imm = 0x800
jne 0x226e2e
movl $0xab, %eax
movl %eax, -0x6c(%rbp)
jmp 0x226e47
movl -0x10(%rbp), %edx
movl $0x176, %eax            # imm = 0x176
movl $0x116, %ecx            # imm = 0x116
cmpl $0x1000, %edx           # imm = 0x1000
cmovel %ecx, %eax
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, -0x68(%rbp)
movl -0x68(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0x20(%rbp), %rax
movl -0x64(%rbp), %ecx
movl %ecx, 0x3f08(%rax)
jmp 0x226e81
leaq 0x28cf8(%rip), %rdi     # 0x24fb61
leaq 0x3dd0e(%rip), %rsi     # 0x264b7e
movl $0x7d, %edx
leaq 0x3dd11(%rip), %rcx     # 0x264b8d
callq 0xc280
movq -0x20(%rbp), %rax
movl 0x3eb8(%rax), %eax
movl %eax, -0x70(%rbp)
subl $0x320, %eax            # imm = 0x320
je 0x226eea
jmp 0x226e97
movl -0x70(%rbp), %eax
subl $0x42a, %eax            # imm = 0x42A
je 0x226f5a
jmp 0x226ea7
movl -0x70(%rbp), %eax
subl $0x535, %eax            # imm = 0x535
je 0x226fdc
jmp 0x226eb7
movl -0x70(%rbp), %eax
subl $0x640, %eax            # imm = 0x640
je 0x227067
jmp 0x226ec7
movl -0x70(%rbp), %eax
subl $0x74a, %eax            # imm = 0x74A
je 0x2270f2
jmp 0x226ed7
movl -0x70(%rbp), %eax
subl $0x855, %eax            # imm = 0x855
je 0x22717d
jmp 0x227205
cmpl $0x200, -0x10(%rbp)     # imm = 0x200
jne 0x226efd
movl $0x28, %eax
movl %eax, -0x74(%rbp)
jmp 0x226f48
cmpl $0x400, -0x10(%rbp)     # imm = 0x400
jne 0x226f10
movl $0x30, %eax
movl %eax, -0x78(%rbp)
jmp 0x226f42
cmpl $0x800, -0x10(%rbp)     # imm = 0x800
jne 0x226f23
movl $0x44, %eax
movl %eax, -0x7c(%rbp)
jmp 0x226f3c
movl -0x10(%rbp), %edx
movl $0x90, %eax
movl $0x6c, %ecx
cmpl $0x1000, %edx           # imm = 0x1000
cmovel %ecx, %eax
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, -0x78(%rbp)
movl -0x78(%rbp), %eax
movl %eax, -0x74(%rbp)
movq -0x20(%rbp), %rax
movl -0x74(%rbp), %ecx
movl %ecx, 0x3f20(%rax)
jmp 0x227224
cmpl $0x200, -0x10(%rbp)     # imm = 0x200
jne 0x226f6d
movl $0x36, %eax
movl %eax, -0x80(%rbp)
jmp 0x226fca
cmpl $0x400, -0x10(%rbp)     # imm = 0x400
jne 0x226f83
movl $0x40, %eax
movl %eax, -0x84(%rbp)
jmp 0x226fc1
cmpl $0x800, -0x10(%rbp)     # imm = 0x800
jne 0x226f99
movl $0x5b, %eax
movl %eax, -0x88(%rbp)
jmp 0x226fb5
movl -0x10(%rbp), %edx
movl $0xc0, %eax
movl $0x90, %ecx
cmpl $0x1000, %edx           # imm = 0x1000
cmovel %ecx, %eax
movl %eax, -0x88(%rbp)
movl -0x88(%rbp), %eax
movl %eax, -0x84(%rbp)
movl -0x84(%rbp), %eax
movl %eax, -0x80(%rbp)
movq -0x20(%rbp), %rax
movl -0x80(%rbp), %ecx
movl %ecx, 0x3f20(%rax)
jmp 0x227224
cmpl $0x200, -0x10(%rbp)     # imm = 0x200
jne 0x226ff2
movl $0x43, %eax
movl %eax, -0x8c(%rbp)
jmp 0x227052
cmpl $0x400, -0x10(%rbp)     # imm = 0x400
jne 0x227008
movl $0x50, %eax
movl %eax, -0x90(%rbp)
jmp 0x227046
cmpl $0x800, -0x10(%rbp)     # imm = 0x800
jne 0x22701e
movl $0x72, %eax
movl %eax, -0x94(%rbp)
jmp 0x22703a
movl -0x10(%rbp), %edx
movl $0xf0, %eax
movl $0xb4, %ecx
cmpl $0x1000, %edx           # imm = 0x1000
cmovel %ecx, %eax
movl %eax, -0x94(%rbp)
movl -0x94(%rbp), %eax
movl %eax, -0x90(%rbp)
movl -0x90(%rbp), %eax
movl %eax, -0x8c(%rbp)
movq -0x20(%rbp), %rax
movl -0x8c(%rbp), %ecx
movl %ecx, 0x3f20(%rax)
jmp 0x227224
cmpl $0x200, -0x10(%rbp)     # imm = 0x200
jne 0x22707d
movl $0x50, %eax
movl %eax, -0x98(%rbp)
jmp 0x2270dd
cmpl $0x400, -0x10(%rbp)     # imm = 0x400
jne 0x227093
movl $0x60, %eax
movl %eax, -0x9c(%rbp)
jmp 0x2270d1
cmpl $0x800, -0x10(%rbp)     # imm = 0x800
jne 0x2270a9
movl $0x88, %eax
movl %eax, -0xa0(%rbp)
jmp 0x2270c5
movl -0x10(%rbp), %edx
movl $0x120, %eax            # imm = 0x120
movl $0xd8, %ecx
cmpl $0x1000, %edx           # imm = 0x1000
cmovel %ecx, %eax
movl %eax, -0xa0(%rbp)
movl -0xa0(%rbp), %eax
movl %eax, -0x9c(%rbp)
movl -0x9c(%rbp), %eax
movl %eax, -0x98(%rbp)
movq -0x20(%rbp), %rax
movl -0x98(%rbp), %ecx
movl %ecx, 0x3f20(%rax)
jmp 0x227224
cmpl $0x200, -0x10(%rbp)     # imm = 0x200
jne 0x227108
movl $0x5e, %eax
movl %eax, -0xa4(%rbp)
jmp 0x227168
cmpl $0x400, -0x10(%rbp)     # imm = 0x400
jne 0x22711e
movl $0x70, %eax
movl %eax, -0xa8(%rbp)
jmp 0x22715c
cmpl $0x800, -0x10(%rbp)     # imm = 0x800
jne 0x227134
movl $0x9f, %eax
movl %eax, -0xac(%rbp)
jmp 0x227150
movl -0x10(%rbp), %edx
movl $0x150, %eax            # imm = 0x150
movl $0xfc, %ecx
cmpl $0x1000, %edx           # imm = 0x1000
cmovel %ecx, %eax
movl %eax, -0xac(%rbp)
movl -0xac(%rbp), %eax
movl %eax, -0xa8(%rbp)
movl -0xa8(%rbp), %eax
movl %eax, -0xa4(%rbp)
movq -0x20(%rbp), %rax
movl -0xa4(%rbp), %ecx
movl %ecx, 0x3f20(%rax)
jmp 0x227224
cmpl $0x200, -0x10(%rbp)     # imm = 0x200
jne 0x227193
movl $0x6b, %eax
movl %eax, -0xb0(%rbp)
jmp 0x2271f3
cmpl $0x400, -0x10(%rbp)     # imm = 0x400
jne 0x2271a9
movl $0x80, %eax
movl %eax, -0xb4(%rbp)
jmp 0x2271e7
cmpl $0x800, -0x10(%rbp)     # imm = 0x800
jne 0x2271bf
movl $0xb6, %eax
movl %eax, -0xb8(%rbp)
jmp 0x2271db
movl -0x10(%rbp), %edx
movl $0x180, %eax            # imm = 0x180
movl $0x120, %ecx            # imm = 0x120
cmpl $0x1000, %edx           # imm = 0x1000
cmovel %ecx, %eax
movl %eax, -0xb8(%rbp)
movl -0xb8(%rbp), %eax
movl %eax, -0xb4(%rbp)
movl -0xb4(%rbp), %eax
movl %eax, -0xb0(%rbp)
movq -0x20(%rbp), %rax
movl -0xb0(%rbp), %ecx
movl %ecx, 0x3f20(%rax)
jmp 0x227224
leaq 0x28955(%rip), %rdi     # 0x24fb61
leaq 0x3d96b(%rip), %rsi     # 0x264b7e
movl $0x8c, %edx
leaq 0x3d96e(%rip), %rcx     # 0x264b8d
callq 0xc280
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax)