// File: CMU-SAFARI[P]ramulator/src/ALDRAM.cpp
// Function: ramulator::ALDRAM::init_speed()
void ALDRAM::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 0x2728(%rax), %ecx
movl 0x273c(%rax), %edx
imull %edx, %ecx
sarl $0xd, %ecx
movl %ecx, -0xc(%rbp)
movl 0x3390(%rax), %eax
movl %eax, -0x14(%rbp)
subl $0x320, %eax            # imm = 0x320
je 0x16f77d
jmp 0x16f72e
movl -0x14(%rbp), %eax
subl $0x42a, %eax            # imm = 0x42A
je 0x16f7b3
jmp 0x16f73a
movl -0x14(%rbp), %eax
subl $0x535, %eax            # imm = 0x535
je 0x16f7ee
jmp 0x16f74a
movl -0x14(%rbp), %eax
subl $0x640, %eax            # imm = 0x640
je 0x16f829
jmp 0x16f75a
movl -0x14(%rbp), %eax
subl $0x74a, %eax            # imm = 0x74A
je 0x16f864
jmp 0x16f76a
movl -0x14(%rbp), %eax
subl $0x855, %eax            # imm = 0x855
je 0x16f89c
jmp 0x16f8d4
movq -0x20(%rbp), %rax
movl -0xc(%rbp), %edx
movl $0x4, %ecx
cmpl $0x1, %edx
cmovel %ecx, %ecx
movl %ecx, 0x33d8(%rax)
movl -0xc(%rbp), %esi
movl $0x14, %ecx
movl $0x10, %edx
cmpl $0x1, %esi
cmovel %edx, %ecx
movl %ecx, 0x33dc(%rax)
jmp 0x16f8f3
movq -0x20(%rbp), %rax
movl -0xc(%rbp), %esi
movl $0x6, %ecx
movl $0x4, %edx
cmpl $0x1, %esi
cmovel %edx, %ecx
movl %ecx, 0x33d8(%rax)
movl -0xc(%rbp), %esi
movl $0x1b, %ecx
movl $0x14, %edx
cmpl $0x1, %esi
cmovel %edx, %ecx
movl %ecx, 0x33dc(%rax)
jmp 0x16f8f3
movq -0x20(%rbp), %rax
movl -0xc(%rbp), %esi
movl $0x5, %ecx
movl $0x4, %edx
cmpl $0x1, %esi
cmovel %edx, %ecx
movl %ecx, 0x33d8(%rax)
movl -0xc(%rbp), %esi
movl $0x1e, %ecx
movl $0x14, %edx
cmpl $0x1, %esi
cmovel %edx, %ecx
movl %ecx, 0x33dc(%rax)
jmp 0x16f8f3
movq -0x20(%rbp), %rax
movl -0xc(%rbp), %esi
movl $0x6, %ecx
movl $0x5, %edx
cmpl $0x1, %esi
cmovel %edx, %ecx
movl %ecx, 0x33d8(%rax)
movl -0xc(%rbp), %esi
movl $0x20, %ecx
movl $0x18, %edx
cmpl $0x1, %esi
cmovel %edx, %ecx
movl %ecx, 0x33dc(%rax)
jmp 0x16f8f3
movq -0x20(%rbp), %rax
movl -0xc(%rbp), %esi
movl $0x6, %ecx
movl $0x5, %edx
cmpl $0x1, %esi
cmovel %edx, %ecx
movl %ecx, 0x33d8(%rax)
movl -0xc(%rbp), %esi
movl $0x21, %ecx
movl $0x1a, %edx
cmpl $0x1, %esi
cmovel %edx, %ecx
movl %ecx, 0x33dc(%rax)
jmp 0x16f8f3
movq -0x20(%rbp), %rax
movl -0xc(%rbp), %esi
movl $0x6, %ecx
movl $0x5, %edx
cmpl $0x1, %esi
cmovel %edx, %ecx
movl %ecx, 0x33d8(%rax)
movl -0xc(%rbp), %esi
movl $0x22, %ecx
movl $0x1b, %edx
cmpl $0x1, %esi
cmovel %edx, %ecx
movl %ecx, 0x33dc(%rax)
jmp 0x16f8f3
leaq 0xe0286(%rip), %rdi     # 0x24fb61
leaq 0xeb2f3(%rip), %rsi     # 0x25abd5
movl $0x57, %edx
leaq 0xeb2f6(%rip), %rcx     # 0x25abe4
callq 0xc280
movq -0x20(%rbp), %rax
movl 0x2724(%rax), %ecx
movl %ecx, -0x10(%rbp)
movl 0x3390(%rax), %eax
movl %eax, -0x24(%rbp)
subl $0x320, %eax            # imm = 0x320
je 0x16f965
jmp 0x16f912
movl -0x24(%rbp), %eax
subl $0x42a, %eax            # imm = 0x42A
je 0x16f9d5
jmp 0x16f922
movl -0x24(%rbp), %eax
subl $0x535, %eax            # imm = 0x535
je 0x16fa45
jmp 0x16f932
movl -0x24(%rbp), %eax
subl $0x640, %eax            # imm = 0x640
je 0x16fab5
jmp 0x16f942
movl -0x24(%rbp), %eax
subl $0x74a, %eax            # imm = 0x74A
je 0x16fb25
jmp 0x16f952
movl -0x24(%rbp), %eax
subl $0x855, %eax            # imm = 0x855
je 0x16fb95
jmp 0x16fc02
cmpl $0x200, -0x10(%rbp)     # imm = 0x200
jne 0x16f978
movl $0x24, %eax
movl %eax, -0x28(%rbp)
jmp 0x16f9c3
cmpl $0x400, -0x10(%rbp)     # imm = 0x400
jne 0x16f98b
movl $0x2c, %eax
movl %eax, -0x2c(%rbp)
jmp 0x16f9bd
cmpl $0x800, -0x10(%rbp)     # imm = 0x800
jne 0x16f99e
movl $0x40, %eax
movl %eax, -0x30(%rbp)
jmp 0x16f9b7
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, 0x33e0(%rax)
jmp 0x16fc21
cmpl $0x200, -0x10(%rbp)     # imm = 0x200
jne 0x16f9e8
movl $0x30, %eax
movl %eax, -0x34(%rbp)
jmp 0x16fa33
cmpl $0x400, -0x10(%rbp)     # imm = 0x400
jne 0x16f9fb
movl $0x3b, %eax
movl %eax, -0x38(%rbp)
jmp 0x16fa2d
cmpl $0x800, -0x10(%rbp)     # imm = 0x800
jne 0x16fa0e
movl $0x56, %eax
movl %eax, -0x3c(%rbp)
jmp 0x16fa27
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, 0x33e0(%rax)
jmp 0x16fc21
cmpl $0x200, -0x10(%rbp)     # imm = 0x200
jne 0x16fa58
movl $0x3c, %eax
movl %eax, -0x40(%rbp)
jmp 0x16faa3
cmpl $0x400, -0x10(%rbp)     # imm = 0x400
jne 0x16fa6b
movl $0x4a, %eax
movl %eax, -0x44(%rbp)
jmp 0x16fa9d
cmpl $0x800, -0x10(%rbp)     # imm = 0x800
jne 0x16fa7e
movl $0x6b, %eax
movl %eax, -0x48(%rbp)
jmp 0x16fa97
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, 0x33e0(%rax)
jmp 0x16fc21
cmpl $0x200, -0x10(%rbp)     # imm = 0x200
jne 0x16fac8
movl $0x48, %eax
movl %eax, -0x4c(%rbp)
jmp 0x16fb13
cmpl $0x400, -0x10(%rbp)     # imm = 0x400
jne 0x16fadb
movl $0x58, %eax
movl %eax, -0x50(%rbp)
jmp 0x16fb0d
cmpl $0x800, -0x10(%rbp)     # imm = 0x800
jne 0x16faee
movl $0x80, %eax
movl %eax, -0x54(%rbp)
jmp 0x16fb07
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, 0x33e0(%rax)
jmp 0x16fc21
cmpl $0x200, -0x10(%rbp)     # imm = 0x200
jne 0x16fb38
movl $0x54, %eax
movl %eax, -0x58(%rbp)
jmp 0x16fb83
cmpl $0x400, -0x10(%rbp)     # imm = 0x400
jne 0x16fb4b
movl $0x67, %eax
movl %eax, -0x5c(%rbp)
jmp 0x16fb7d
cmpl $0x800, -0x10(%rbp)     # imm = 0x800
jne 0x16fb5e
movl $0x96, %eax
movl %eax, -0x60(%rbp)
jmp 0x16fb77
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, 0x33e0(%rax)
jmp 0x16fc21
cmpl $0x200, -0x10(%rbp)     # imm = 0x200
jne 0x16fba8
movl $0x60, %eax
movl %eax, -0x64(%rbp)
jmp 0x16fbf3
cmpl $0x400, -0x10(%rbp)     # imm = 0x400
jne 0x16fbbb
movl $0x76, %eax
movl %eax, -0x68(%rbp)
jmp 0x16fbed
cmpl $0x800, -0x10(%rbp)     # imm = 0x800
jne 0x16fbce
movl $0xab, %eax
movl %eax, -0x6c(%rbp)
jmp 0x16fbe7
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, 0x33e0(%rax)
jmp 0x16fc21
leaq 0xdff58(%rip), %rdi     # 0x24fb61
leaq 0xeafc5(%rip), %rsi     # 0x25abd5
movl $0x63, %edx
leaq 0xeafc8(%rip), %rcx     # 0x25abe4
callq 0xc280
movq -0x20(%rbp), %rax
movl 0x3390(%rax), %eax
movl %eax, -0x70(%rbp)
subl $0x320, %eax            # imm = 0x320
je 0x16fc8a
jmp 0x16fc37
movl -0x70(%rbp), %eax
subl $0x42a, %eax            # imm = 0x42A
je 0x16fcfa
jmp 0x16fc47
movl -0x70(%rbp), %eax
subl $0x535, %eax            # imm = 0x535
je 0x16fd7c
jmp 0x16fc57
movl -0x70(%rbp), %eax
subl $0x640, %eax            # imm = 0x640
je 0x16fe07
jmp 0x16fc67
movl -0x70(%rbp), %eax
subl $0x74a, %eax            # imm = 0x74A
je 0x16fe92
jmp 0x16fc77
movl -0x70(%rbp), %eax
subl $0x855, %eax            # imm = 0x855
je 0x16ff1d
jmp 0x16ffa5
cmpl $0x200, -0x10(%rbp)     # imm = 0x200
jne 0x16fc9d
movl $0x28, %eax
movl %eax, -0x74(%rbp)
jmp 0x16fce8
cmpl $0x400, -0x10(%rbp)     # imm = 0x400
jne 0x16fcb0
movl $0x30, %eax
movl %eax, -0x78(%rbp)
jmp 0x16fce2
cmpl $0x800, -0x10(%rbp)     # imm = 0x800
jne 0x16fcc3
movl $0x44, %eax
movl %eax, -0x7c(%rbp)
jmp 0x16fcdc
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, 0x33f8(%rax)
jmp 0x16ffc4
cmpl $0x200, -0x10(%rbp)     # imm = 0x200
jne 0x16fd0d
movl $0x36, %eax
movl %eax, -0x80(%rbp)
jmp 0x16fd6a
cmpl $0x400, -0x10(%rbp)     # imm = 0x400
jne 0x16fd23
movl $0x40, %eax
movl %eax, -0x84(%rbp)
jmp 0x16fd61
cmpl $0x800, -0x10(%rbp)     # imm = 0x800
jne 0x16fd39
movl $0x5b, %eax
movl %eax, -0x88(%rbp)
jmp 0x16fd55
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, 0x33f8(%rax)
jmp 0x16ffc4
cmpl $0x200, -0x10(%rbp)     # imm = 0x200
jne 0x16fd92
movl $0x43, %eax
movl %eax, -0x8c(%rbp)
jmp 0x16fdf2
cmpl $0x400, -0x10(%rbp)     # imm = 0x400
jne 0x16fda8
movl $0x50, %eax
movl %eax, -0x90(%rbp)
jmp 0x16fde6
cmpl $0x800, -0x10(%rbp)     # imm = 0x800
jne 0x16fdbe
movl $0x72, %eax
movl %eax, -0x94(%rbp)
jmp 0x16fdda
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, 0x33f8(%rax)
jmp 0x16ffc4
cmpl $0x200, -0x10(%rbp)     # imm = 0x200
jne 0x16fe1d
movl $0x50, %eax
movl %eax, -0x98(%rbp)
jmp 0x16fe7d
cmpl $0x400, -0x10(%rbp)     # imm = 0x400
jne 0x16fe33
movl $0x60, %eax
movl %eax, -0x9c(%rbp)
jmp 0x16fe71
cmpl $0x800, -0x10(%rbp)     # imm = 0x800
jne 0x16fe49
movl $0x88, %eax
movl %eax, -0xa0(%rbp)
jmp 0x16fe65
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, 0x33f8(%rax)
jmp 0x16ffc4
cmpl $0x200, -0x10(%rbp)     # imm = 0x200
jne 0x16fea8
movl $0x5e, %eax
movl %eax, -0xa4(%rbp)
jmp 0x16ff08
cmpl $0x400, -0x10(%rbp)     # imm = 0x400
jne 0x16febe
movl $0x70, %eax
movl %eax, -0xa8(%rbp)
jmp 0x16fefc
cmpl $0x800, -0x10(%rbp)     # imm = 0x800
jne 0x16fed4
movl $0x9f, %eax
movl %eax, -0xac(%rbp)
jmp 0x16fef0
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, 0x33f8(%rax)
jmp 0x16ffc4
cmpl $0x200, -0x10(%rbp)     # imm = 0x200
jne 0x16ff33
movl $0x6b, %eax
movl %eax, -0xb0(%rbp)
jmp 0x16ff93
cmpl $0x400, -0x10(%rbp)     # imm = 0x400
jne 0x16ff49
movl $0x80, %eax
movl %eax, -0xb4(%rbp)
jmp 0x16ff87
cmpl $0x800, -0x10(%rbp)     # imm = 0x800
jne 0x16ff5f
movl $0xb6, %eax
movl %eax, -0xb8(%rbp)
jmp 0x16ff7b
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, 0x33f8(%rax)
jmp 0x16ffc4
leaq 0xdfbb5(%rip), %rdi     # 0x24fb61
leaq 0xeac22(%rip), %rsi     # 0x25abd5
movl $0x6c, %edx
leaq 0xeac25(%rip), %rcx     # 0x25abe4
callq 0xc280
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax)