// File: CMU-SAFARI[P]ramulator/src/GDDR5.cpp
// Function: ramulator::GDDR5::init_speed()
void GDDR5::init_speed()
{
    const int REFIL_TABLE[int(Speed::MAX)] = {3900, 4388, 4875, 5363, 5850, 6338, 6825};
    const int REFIS_TABLE[int(Speed::MAX)] = {1900, 2138, 2375, 2613, 2850, 3088, 3325};
    const int RFC_TABLE[5][int(Speed::MAX)] = {
        // using DDR3 values
        {90, 102, 113, 124, 135, 147, 158},
        {110, 124, 138, 152, 165, 179, 193},
        {160, 180, 200, 220, 240, 260, 280},
        {260, 293, 325, 358, 390, 423, 455},
        {350, 394, 438, 482, 525, 569, 613}
    };
    int speed = 0, density = 0;
    switch (speed_entry.rate){
        case 4000: speed = 0; break;
        case 4500: speed = 1; break;
        case 5000: speed = 2; break;
        case 5500: speed = 3; break;
        case 6000: speed = 4; break;
        case 6500: speed = 5; break;
        case 7000: speed = 6; break;
        default: assert(0);
    }
    switch (org_entry.size >> 9){
        case 1: density = 0; break;
        case 2: density = 1; break;
        case 4: density = 2; break;
        case 8: density = 3; break;
        case 16: density = 4; break;
        default: assert(0);
    }
    if (org_entry.size <= 1024) speed_entry.nREFI = REFIL_TABLE[speed];
    else speed_entry.nREFI = REFIS_TABLE[speed];
    speed_entry.nRFC = RFC_TABLE[density][speed];
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xf8(%rbp)
movups 0xa85ab(%rip), %xmm0    # 0x25decc
movups %xmm0, -0x24(%rbp)
movaps 0xa8594(%rip), %xmm0    # 0x25dec0
movaps %xmm0, -0x30(%rbp)
movups 0xa85b5(%rip), %xmm0    # 0x25deec
movups %xmm0, -0x44(%rbp)
movaps 0xa859e(%rip), %xmm0    # 0x25dee0
movaps %xmm0, -0x50(%rbp)
leaq 0xa85b3(%rip), %rsi     # 0x25df00
leaq -0xe0(%rbp), %rdi
movl $0x8c, %edx
callq 0xc300
movq -0xf8(%rbp), %rax
movl $0x0, -0xe4(%rbp)
movl $0x0, -0xe8(%rbp)
movl 0x3188(%rax), %eax
movl %eax, -0xec(%rbp)
subl $0xfa0, %eax            # imm = 0xFA0
je 0x1b59e8
jmp 0x1b598e
movl -0xec(%rbp), %eax
subl $0x1194, %eax           # imm = 0x1194
je 0x1b59f4
jmp 0x1b599d
movl -0xec(%rbp), %eax
subl $0x1388, %eax           # imm = 0x1388
je 0x1b5a00
jmp 0x1b59ac
movl -0xec(%rbp), %eax
subl $0x157c, %eax           # imm = 0x157C
je 0x1b5a0c
jmp 0x1b59bb
movl -0xec(%rbp), %eax
subl $0x1770, %eax           # imm = 0x1770
je 0x1b5a18
jmp 0x1b59ca
movl -0xec(%rbp), %eax
subl $0x1964, %eax           # imm = 0x1964
je 0x1b5a24
jmp 0x1b59d9
movl -0xec(%rbp), %eax
subl $0x1b58, %eax           # imm = 0x1B58
je 0x1b5a30
jmp 0x1b5a3c
movl $0x0, -0xe4(%rbp)
jmp 0x1b5a5b
movl $0x1, -0xe4(%rbp)
jmp 0x1b5a5b
movl $0x2, -0xe4(%rbp)
jmp 0x1b5a5b
movl $0x3, -0xe4(%rbp)
jmp 0x1b5a5b
movl $0x4, -0xe4(%rbp)
jmp 0x1b5a5b
movl $0x5, -0xe4(%rbp)
jmp 0x1b5a5b
movl $0x6, -0xe4(%rbp)
jmp 0x1b5a5b
leaq 0x9a2c6(%rip), %rdi     # 0x24fd09
leaq 0xa895a(%rip), %rsi     # 0x25e3a4
movl $0x4c, %edx
leaq 0xa8988(%rip), %rcx     # 0x25e3de
callq 0xc280
movq -0xf8(%rbp), %rax
movl 0x2de0(%rax), %eax
sarl $0x9, %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x100(%rbp)
subl $0xf, %eax
ja 0x1b5ace
movq -0x100(%rbp), %rax
leaq 0xa7d77(%rip), %rcx     # 0x25d800
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x0, -0xe8(%rbp)
jmp 0x1b5aed
movl $0x1, -0xe8(%rbp)
jmp 0x1b5aed
movl $0x2, -0xe8(%rbp)
jmp 0x1b5aed
movl $0x3, -0xe8(%rbp)
jmp 0x1b5aed
movl $0x4, -0xe8(%rbp)
jmp 0x1b5aed
leaq 0x9a234(%rip), %rdi     # 0x24fd09
leaq 0xa88c8(%rip), %rsi     # 0x25e3a4
movl $0x54, %edx
leaq 0xa88f6(%rip), %rcx     # 0x25e3de
callq 0xc280
movq -0xf8(%rbp), %rax
cmpl $0x400, 0x2de0(%rax)    # imm = 0x400
jg 0x1b5b1a
movq -0xf8(%rbp), %rax
movslq -0xe4(%rbp), %rcx
movl -0x30(%rbp,%rcx,4), %ecx
movl %ecx, 0x31e8(%rax)
jmp 0x1b5b32
movq -0xf8(%rbp), %rax
movslq -0xe4(%rbp), %rcx
movl -0x50(%rbp,%rcx,4), %ecx
movl %ecx, 0x31e8(%rax)
movq -0xf8(%rbp), %rax
movslq -0xe8(%rbp), %rdx
leaq -0xe0(%rbp), %rcx
imulq $0x1c, %rdx, %rdx
addq %rdx, %rcx
movslq -0xe4(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
movl %ecx, 0x31e4(%rax)
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nopw (%rax,%rax)