// File: /workspace/github_cpp_makefile_star2_O2/CMU-SAFARI[P]ramulator/src/WideIO2.cpp
// Function: ramulator::WideIO2::WideIO2(ramulator::WideIO2::Org, ramulator::WideIO2::Speed, int)
WideIO2::WideIO2(Org org, Speed speed, int channels) :  
    speed_entry(speed_table[int(speed)]),
    read_latency(speed_entry.nCL + speed_entry.nDQSCK + speed_entry.nBL)
{
    switch(int(org)){
        case int(Org::WideIO2_8Gb):
            org_entry.size = (8<<10) / channels;
            org_entry.dq = 64;
            if (channels == 4) {
                org_entry.size = 2<<10;
                org_entry.count[int(Level::Channel)] = channels;
                org_entry.count[int(Level::Rank)] = 0;
                org_entry.count[int(Level::Bank)] = 8;
                org_entry.count[int(Level::Row)] = 1<<13;
                org_entry.count[int(Level::Column)] = 1<<9;
            } else if (channels == 8) {
                org_entry.size = 1<<10;
                org_entry.count[int(Level::Channel)] = channels;
                org_entry.count[int(Level::Rank)] = 0;
                org_entry.count[int(Level::Bank)] = 4;
                org_entry.count[int(Level::Row)] = 1<<14;
                org_entry.count[int(Level::Column)] = 1<<8;
            } else assert(false && "The WideIO2 interface supports 4 or 8 physical channels.");
            break;
        default: assert(false);
    }
    speed_entry.nRPab = (channels == 4)? speed_entry.nRP8b: speed_entry.nRPpb;
    init_prereq();
    init_rowhit(); // SAUGATA: added row hit function
    init_lambda();
    init_timing();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movl %ecx, %ebp
movl %edx, %r12d
movl %esi, %r15d
movq %rdi, %rbx
leaq 0xd91a(%rip), %rsi      # 0xdb170
leaq 0xf(%rsp), %rdx
callq 0x10eea
leaq 0x20(%rbx), %r14
leaq 0xd909(%rip), %rsi      # 0xdb174
leaq 0xe(%rsp), %rdx
movq %r14, %rdi
callq 0x10eea
leaq 0x40(%rbx), %r14
leaq 0x12532(%rip), %rsi     # 0xdfdb5
leaq 0xd(%rsp), %rdx
movq %r14, %rdi
callq 0x10eea
leaq 0x60(%rbx), %r14
leaq 0xd8dd(%rip), %rsi      # 0xdb178
leaq 0xc(%rsp), %rdx
movq %r14, %rdi
callq 0x10eea
leaq 0x80(%rbx), %r14
leaq 0x42ec(%rip), %rsi      # 0xd1ba2
leaq 0xb(%rsp), %rdx
movq %r14, %rdi
callq 0x10eea
leaq 0xa0(%rbx), %r14
leaq 0xd8aa(%rip), %rsi      # 0xdb17b
leaq 0xa(%rsp), %rdx
movq %r14, %rdi
callq 0x10eea
leaq 0xc0(%rbx), %r14
leaq 0xd893(%rip), %rsi      # 0xdb17f
leaq 0x9(%rsp), %rdx
movq %r14, %rdi
callq 0x10eea
leaq 0xe0(%rbx), %r14
leaq 0x169e0(%rip), %rsi     # 0xe42e7
leaq 0x8(%rsp), %rdx
movq %r14, %rdi
callq 0x10eea
leaq 0x100(%rbx), %r14
leaq 0x10fe5(%rip), %rsi     # 0xde907
leaq 0x7(%rsp), %rdx
movq %r14, %rdi
callq 0x10eea
leaq 0x120(%rbx), %r14
leaq 0x1247c(%rip), %rsi     # 0xdfdb9
leaq 0x6(%rsp), %rdx
movq %r14, %rdi
callq 0x10eea
leaq 0x140(%rbx), %r14
leaq 0xd82f(%rip), %rsi      # 0xdb187
leaq 0x5(%rsp), %rdx
movq %r14, %rdi
callq 0x10eea
leaq 0x160(%rbx), %r14
leaq 0x12449(%rip), %rsi     # 0xdfdbc
leaq 0x4(%rsp), %rdx
movq %r14, %rdi
callq 0x10eea
leaq 0x180(%rbx), %r14
leaq 0x12433(%rip), %rsi     # 0xdfdc1
leaq 0x3(%rsp), %rdx
movq %r14, %rdi
callq 0x10eea
movups 0x183fe(%rip), %xmm0    # 0xe5da0
movups %xmm0, 0x1c0(%rbx)
movups 0x183e0(%rip), %xmm0    # 0xe5d90
movups %xmm0, 0x1b0(%rbx)
movups 0x183c2(%rip), %xmm0    # 0xe5d80
movups %xmm0, 0x1a0(%rbx)
movl $0x1, 0x1d0(%rbx)
movups 0x183de(%rip), %xmm0    # 0xe5db4
movups %xmm0, 0x1d4(%rbx)
movl $0x6, 0x1e4(%rbx)
movups 0x1119e(%rip), %xmm0    # 0xdeb8c
movups %xmm0, 0x1e8(%rbx)
movq $0xb, 0x1f8(%rbx)
leaq 0x200(%rbx), %rdi
movl $0x2698, %edx           # imm = 0x2698
xorl %esi, %esi
callq 0xb1d0
movabsq $0x4000000004, %rax     # imm = 0x4000000004
movq %rax, 0x28b4(%rbx)
leaq 0x28c0(%rbx), %rdi
leaq 0x18396(%rip), %rsi     # 0xe5dc8
movl $0xf0, %edx
callq 0xb270
leaq 0x29b0(%rbx), %rdi
movslq %r12d, %rax
imulq $0x78, %rax, %rax
leaq (%rbx,%rax), %rsi
addq $0x28c0, %rsi           # imm = 0x28C0
pushq $0xf
popq %rcx
rep  movsq (%rsi), %es:(%rdi)
movl 0x29d0(%rbx), %eax
addl 0x29d8(%rbx), %eax
addl 0x29c8(%rbx), %eax
movl %eax, 0x2a28(%rbx)
testl %r15d, %r15d
jne 0xcdb29
movl $0x2000, %eax           # imm = 0x2000
xorl %edx, %edx
idivl %ebp
movl %eax, 0x2898(%rbx)
movl $0x40, 0x289c(%rbx)
cmpl $0x4, %ebp
je 0xcdabc
cmpl $0x8, %ebp
jne 0xcdb42
movsd 0x17fa5(%rip), %xmm0    # 0xe5a50
movl $0x29e0, %eax           # imm = 0x29E0
movl $0x100, %ecx            # imm = 0x100
movl $0x400, %edx            # imm = 0x400
jmp 0xcdad3
movsd 0x17f7c(%rip), %xmm0    # 0xe5a40
movl $0x29e4, %eax           # imm = 0x29E4
movl $0x200, %ecx            # imm = 0x200
movl $0x800, %edx            # imm = 0x800
movl %edx, 0x2898(%rbx)
movl %ebp, 0x28a0(%rbx)
andl $0x0, 0x28a4(%rbx)
movlps %xmm0, 0x28a8(%rbx)
movl %ecx, 0x28b0(%rbx)
movl (%rbx,%rax), %eax
movl %eax, 0x29e8(%rbx)
movq %rbx, %rdi
callq 0xcdc4a
movq %rbx, %rdi
callq 0xcddf6
movq %rbx, %rdi
callq 0xcde64
movq %rbx, %rdi
callq 0xce0fc
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3829(%rip), %rdi      # 0xd1359
leaq 0x17f92(%rip), %rsi     # 0xe5ac9
leaq 0x17f9b(%rip), %rcx     # 0xe5ad9
pushq $0x2e
jmp 0xcdb59
leaq 0x17f3c(%rip), %rdi     # 0xe5a85
leaq 0x17f79(%rip), %rsi     # 0xe5ac9
leaq 0x17f82(%rip), %rcx     # 0xe5ad9
pushq $0x2c
popq %rdx
callq 0xb210
jmp 0xcdb75
jmp 0xcdb75
jmp 0xcdb75
jmp 0xcdb75
jmp 0xcdb75
jmp 0xcdb75
jmp 0xcdb75
jmp 0xcdb75
jmp 0xcdb75
jmp 0xcdb75
jmp 0xcdb75
movq %rax, %r15
addq $-0x20, %r14
movq %r14, %rdi
callq 0xb568
cmpq %rbx, %r14
jne 0xcdb78
movq %r15, %rdi
callq 0xb4d0
movq %rax, %r15
leaq 0x2878(%rbx), %r14
xorl %r12d, %r12d
leaq (%r14,%r12), %rdi
callq 0x96b6a
addq $-0x20, %r12
cmpq $-0x820, %r12           # imm = 0xF7E0
jne 0xcdb9e
leaq 0x2060(%rbx), %r14
xorl %r12d, %r12d
leaq (%r14,%r12), %rdi
callq 0x6b378
addq $-0x18, %r12
cmpq $-0x618, %r12           # imm = 0xF9E8
jne 0xcdbbe
leaq 0x1a40(%rbx), %r14
xorl %r12d, %r12d
leaq (%r14,%r12), %rdi
callq 0x96b6a
addq $-0x20, %r12
cmpq $-0x820, %r12           # imm = 0xF7E0
jne 0xcdbde
movl $0x1220, %r14d          # imm = 0x1220
leaq (%rbx,%r14), %rdi
callq 0x96b6a
addq $-0x20, %r14
cmpq $0xa00, %r14            # imm = 0xA00
jne 0xcdbfa
movl $0xa00, %r14d           # imm = 0xA00
leaq (%rbx,%r14), %rdi
callq 0x96b6a
addq $-0x20, %r14
cmpq $0x1e0, %r14            # imm = 0x1E0
jne 0xcdc16
movl $0x180, %r14d           # imm = 0x180
leaq (%rbx,%r14), %rdi
callq 0xb568
addq $-0x20, %r14
cmpq $-0x20, %r14
jne 0xcdc32
jmp 0xcdb89