// File: 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
movq %rsp, %rbp
subq $0x240, %rsp            # imm = 0x240
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq %rax, %rcx
movq %rcx, -0x60(%rbp)
movb $0x1, -0x41(%rbp)
movq %rax, -0x20(%rbp)
leaq -0x21(%rbp), %rdi
movq %rdi, -0x50(%rbp)
callq 0xc5e0
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rdx
leaq 0x180c7(%rip), %rsi     # 0x25abb2
callq 0x17a40
jmp 0x242af2
movq -0x58(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x70(%rbp)
movq %rax, -0x20(%rbp)
leaq -0x35(%rbp), %rdi
movq %rdi, -0x68(%rbp)
callq 0xc5e0
movq -0x70(%rbp), %rdi
movq -0x68(%rbp), %rdx
leaq 0x18098(%rip), %rsi     # 0x25abb6
callq 0x17a40
jmp 0x242b25
movq -0x58(%rbp), %rax
addq $0x40, %rax
movq %rax, -0x80(%rbp)
movq %rax, -0x20(%rbp)
leaq -0x36(%rbp), %rdi
movq %rdi, -0x78(%rbp)
callq 0xc5e0
movq -0x80(%rbp), %rdi
movq -0x78(%rbp), %rdx
leaq 0x1ca7c(%rip), %rsi     # 0x25f5cd
callq 0x17a40
jmp 0x242b58
movq -0x58(%rbp), %rax
addq $0x60, %rax
movq %rax, -0x90(%rbp)
movq %rax, -0x20(%rbp)
leaq -0x37(%rbp), %rdi
movq %rdi, -0x88(%rbp)
callq 0xc5e0
movq -0x90(%rbp), %rdi
movq -0x88(%rbp), %rdx
leaq 0x1802a(%rip), %rsi     # 0x25abba
callq 0x17a40
jmp 0x242b97
movq -0x58(%rbp), %rax
subq $-0x80, %rax
movq %rax, -0xa0(%rbp)
movq %rax, -0x20(%rbp)
leaq -0x38(%rbp), %rdi
movq %rdi, -0x98(%rbp)
callq 0xc5e0
movq -0xa0(%rbp), %rdi
movq -0x98(%rbp), %rdx
leaq 0xd7db(%rip), %rsi      # 0x2503aa
callq 0x17a40
jmp 0x242bd6
movq -0x58(%rbp), %rax
addq $0xa0, %rax
movq %rax, -0xb0(%rbp)
movq %rax, -0x20(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
callq 0xc5e0
movq -0xb0(%rbp), %rdi
movq -0xa8(%rbp), %rdx
leaq 0x17fad(%rip), %rsi     # 0x25abbd
callq 0x17a40
jmp 0x242c17
movq -0x58(%rbp), %rax
addq $0xc0, %rax
movq %rax, -0xc0(%rbp)
movq %rax, -0x20(%rbp)
leaq -0x3a(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
callq 0xc5e0
movq -0xc0(%rbp), %rdi
movq -0xb8(%rbp), %rdx
leaq 0x17f70(%rip), %rsi     # 0x25abc1
callq 0x17a40
jmp 0x242c58
movq -0x58(%rbp), %rax
addq $0xe0, %rax
movq %rax, -0xd0(%rbp)
movq %rax, -0x20(%rbp)
leaq -0x3b(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
callq 0xc5e0
movq -0xd0(%rbp), %rdi
movq -0xc8(%rbp), %rdx
leaq 0x21ece(%rip), %rsi     # 0x264b60
callq 0x17a40
jmp 0x242c99
movq -0x58(%rbp), %rax
addq $0x100, %rax            # imm = 0x100
movq %rax, -0xe0(%rbp)
movq %rax, -0x20(%rbp)
leaq -0x3c(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0xc5e0
movq -0xe0(%rbp), %rdi
movq -0xd8(%rbp), %rdx
leaq 0x1a8b2(%rip), %rsi     # 0x25d585
callq 0x17a40
jmp 0x242cda
movq -0x58(%rbp), %rax
addq $0x120, %rax            # imm = 0x120
movq %rax, -0xf0(%rbp)
movq %rax, -0x20(%rbp)
leaq -0x3d(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0xc5e0
movq -0xf0(%rbp), %rdi
movq -0xe8(%rbp), %rdx
leaq 0x1c8bd(%rip), %rsi     # 0x25f5d1
callq 0x17a40
jmp 0x242d1b
movq -0x58(%rbp), %rax
addq $0x140, %rax            # imm = 0x140
movq %rax, -0x100(%rbp)
movq %rax, -0x20(%rbp)
leaq -0x3e(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0xc5e0
movq -0x100(%rbp), %rdi
movq -0xf8(%rbp), %rdx
leaq 0x17e74(%rip), %rsi     # 0x25abc9
callq 0x17a40
jmp 0x242d5c
movq -0x58(%rbp), %rax
addq $0x160, %rax            # imm = 0x160
movq %rax, -0x110(%rbp)
movq %rax, -0x20(%rbp)
leaq -0x3f(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0xc5e0
movq -0x110(%rbp), %rdi
movq -0x108(%rbp), %rdx
leaq 0x1c83e(%rip), %rsi     # 0x25f5d4
callq 0x17a40
jmp 0x242d9d
movq -0x58(%rbp), %rax
addq $0x180, %rax            # imm = 0x180
movq %rax, -0x120(%rbp)
movq %rax, -0x20(%rbp)
leaq -0x40(%rbp), %rdi
movq %rdi, -0x118(%rbp)
callq 0xc5e0
movq -0x120(%rbp), %rdi
movq -0x118(%rbp), %rdx
leaq 0x1c802(%rip), %rsi     # 0x25f5d9
callq 0x17a40
jmp 0x242dde
movb $0x0, -0x41(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xc3c0
leaq -0x3f(%rbp), %rdi
callq 0xc3c0
leaq -0x3e(%rbp), %rdi
callq 0xc3c0
leaq -0x3d(%rbp), %rdi
callq 0xc3c0
leaq -0x3c(%rbp), %rdi
callq 0xc3c0
leaq -0x3b(%rbp), %rdi
callq 0xc3c0
leaq -0x3a(%rbp), %rdi
callq 0xc3c0
leaq -0x39(%rbp), %rdi
callq 0xc3c0
leaq -0x38(%rbp), %rdi
callq 0xc3c0
leaq -0x37(%rbp), %rdi
callq 0xc3c0
leaq -0x36(%rbp), %rdi
callq 0xc3c0
leaq -0x35(%rbp), %rdi
callq 0xc3c0
leaq -0x21(%rbp), %rdi
callq 0xc3c0
movq -0x60(%rbp), %rdi
addq $0x1a0, %rdi            # imm = 0x1A0
leaq 0x22927(%rip), %rsi     # 0x265790
movl $0x34, %edx
callq 0xc300
movq -0x60(%rbp), %rax
movq 0x22946(%rip), %rcx     # 0x2657c4
movq %rcx, 0x1d4(%rax)
movq 0x22940(%rip), %rcx     # 0x2657cc
movq %rcx, 0x1dc(%rax)
movl 0x2293b(%rip), %ecx     # 0x2657d4
movl %ecx, 0x1e4(%rax)
movq 0x22932(%rip), %rcx     # 0x2657d8
movq %rcx, 0x1e8(%rax)
movq 0x2292c(%rip), %rcx     # 0x2657e0
movq %rcx, 0x1f0(%rax)
movq 0x22926(%rip), %rcx     # 0x2657e8
movq %rcx, 0x1f8(%rax)
addq $0x200, %rax            # imm = 0x200
movq %rax, -0x138(%rbp)
movq %rax, %rcx
addq $0x820, %rcx            # imm = 0x820
movq %rcx, -0x130(%rbp)
movq %rax, -0x128(%rbp)
movq -0x128(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x249f20
movq -0x140(%rbp), %rax
movq -0x130(%rbp), %rcx
addq $0x20, %rax
cmpq %rcx, %rax
movq %rax, -0x128(%rbp)
jne 0x242eee
movq -0x60(%rbp), %rax
addq $0xa20, %rax            # imm = 0xA20
movq %rax, -0x158(%rbp)
movq %rax, %rcx
addq $0x820, %rcx            # imm = 0x820
movq %rcx, -0x150(%rbp)
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x249f60
movq -0x160(%rbp), %rax
movq -0x150(%rbp), %rcx
addq $0x20, %rax
cmpq %rcx, %rax
movq %rax, -0x148(%rbp)
jne 0x242f48
movq -0x60(%rbp), %rax
addq $0x1240, %rax           # imm = 0x1240
movq %rax, -0x178(%rbp)
movq %rax, %rcx
addq $0x820, %rcx            # imm = 0x820
movq %rcx, -0x170(%rbp)
movq %rax, -0x168(%rbp)
movq -0x168(%rbp), %rdi
movq %rdi, -0x180(%rbp)
callq 0x249f60
movq -0x180(%rbp), %rax
movq -0x170(%rbp), %rcx
addq $0x20, %rax
cmpq %rcx, %rax
movq %rax, -0x168(%rbp)
jne 0x242fa2
movq -0x60(%rbp), %rax
addq $0x1a60, %rax           # imm = 0x1A60
movq %rax, -0x198(%rbp)
movq %rax, %rcx
addq $0x618, %rcx            # imm = 0x618
movq %rcx, -0x190(%rbp)
movq %rax, -0x188(%rbp)
movq -0x188(%rbp), %rdi
movq %rdi, -0x1a0(%rbp)
callq 0x249fa0
movq -0x1a0(%rbp), %rax
movq -0x190(%rbp), %rcx
addq $0x18, %rax
cmpq %rcx, %rax
movq %rax, -0x188(%rbp)
jne 0x242ffc
movq -0x60(%rbp), %rax
addq $0x2078, %rax           # imm = 0x2078
movq %rax, -0x1b8(%rbp)
movq %rax, %rcx
addq $0x820, %rcx            # imm = 0x820
movq %rcx, -0x1b0(%rbp)
movq %rax, -0x1a8(%rbp)
movq -0x1a8(%rbp), %rdi
movq %rdi, -0x1c0(%rbp)
callq 0x249fc0
movq -0x1c0(%rbp), %rax
movq -0x1b0(%rbp), %rcx
addq $0x20, %rax
cmpq %rcx, %rax
movq %rax, -0x1a8(%rbp)
jne 0x243056
movq -0x60(%rbp), %rdi
movl $0x4, 0x28b4(%rdi)
movl $0x40, 0x28b8(%rdi)
addq $0x28c0, %rdi           # imm = 0x28C0
leaq 0x22743(%rip), %rsi     # 0x2657f0
movl $0xf0, %edx
callq 0xc300
movq -0x60(%rbp), %rax
movslq -0x10(%rbp), %rcx
imulq $0x78, %rcx, %rcx
movq %rcx, -0x1c8(%rbp)
movq 0x2930(%rax,%rcx), %rdx
movq %rdx, 0x2a20(%rax)
movups 0x2920(%rax,%rcx), %xmm0
movups %xmm0, 0x2a10(%rax)
movups 0x2910(%rax,%rcx), %xmm0
movups %xmm0, 0x2a00(%rax)
movups 0x2900(%rax,%rcx), %xmm0
movups %xmm0, 0x29f0(%rax)
movups 0x28c0(%rax,%rcx), %xmm0
movups 0x28d0(%rax,%rcx), %xmm1
movups 0x28e0(%rax,%rcx), %xmm2
movups 0x28f0(%rax,%rcx), %xmm3
movups %xmm3, 0x29e0(%rax)
movups %xmm2, 0x29d0(%rax)
movups %xmm1, 0x29c0(%rax)
movups %xmm0, 0x29b0(%rax)
movl 0x29d8(%rax), %ecx
movl 0x29c8(%rax), %edx
movl 0x29d0(%rax), %esi
addl %esi, %ecx
addl %edx, %ecx
movl %ecx, 0x2a28(%rax)
movl -0xc(%rbp), %eax
testl %eax, %eax
je 0x2432fd
jmp 0x2433cd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x2432a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x24329a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x243291
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x243288
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x24327f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x243276
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x24326d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x243264
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x24325b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x243252
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x243249
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x243240
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xc3c0
leaq -0x3f(%rbp), %rdi
callq 0xc3c0
leaq -0x3e(%rbp), %rdi
callq 0xc3c0
leaq -0x3d(%rbp), %rdi
callq 0xc3c0
leaq -0x3c(%rbp), %rdi
callq 0xc3c0
leaq -0x3b(%rbp), %rdi
callq 0xc3c0
leaq -0x3a(%rbp), %rdi
callq 0xc3c0
leaq -0x39(%rbp), %rdi
callq 0xc3c0
leaq -0x38(%rbp), %rdi
callq 0xc3c0
leaq -0x37(%rbp), %rdi
callq 0xc3c0
leaq -0x36(%rbp), %rdi
callq 0xc3c0
leaq -0x35(%rbp), %rdi
callq 0xc3c0
leaq -0x21(%rbp), %rdi
callq 0xc3c0
testb $0x1, -0x41(%rbp)
jne 0x2432b4
jmp 0x2432f8
movq -0x58(%rbp), %rcx
movq -0x20(%rbp), %rax
cmpq %rax, %rcx
movq %rax, -0x1d0(%rbp)
je 0x2432f6
movq -0x1d0(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x1d8(%rbp)
callq 0xc6b8
movq -0x58(%rbp), %rcx
movq -0x1d8(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x1d0(%rbp)
jne 0x2432c8
jmp 0x2432f8
jmp 0x2435fc
movl $0x2000, %eax           # imm = 0x2000
cltd
idivl -0x14(%rbp)
movl %eax, %ecx
movq -0x60(%rbp), %rax
movl %ecx, 0x2898(%rax)
movl $0x40, 0x289c(%rax)
cmpl $0x4, -0x14(%rbp)
jne 0x243363
movq -0x60(%rbp), %rax
movl $0x800, 0x2898(%rax)    # imm = 0x800
movl -0x14(%rbp), %ecx
movl %ecx, 0x28a0(%rax)
movl $0x0, 0x28a4(%rax)
movl $0x8, 0x28a8(%rax)
movl $0x2000, 0x28ac(%rax)   # imm = 0x2000
movl $0x200, 0x28b0(%rax)    # imm = 0x200
jmp 0x2433cb
cmpl $0x8, -0x14(%rbp)
jne 0x2433aa
movq -0x60(%rbp), %rax
movl $0x400, 0x2898(%rax)    # imm = 0x400
movl -0x14(%rbp), %ecx
movl %ecx, 0x28a0(%rax)
movl $0x0, 0x28a4(%rax)
movl $0x4, 0x28a8(%rax)
movl $0x4000, 0x28ac(%rax)   # imm = 0x4000
movl $0x100, 0x28b0(%rax)    # imm = 0x100
jmp 0x2433c9
leaq 0x227e5(%rip), %rdi     # 0x265b96
leaq 0x22822(%rip), %rsi     # 0x265bda
movl $0x2c, %edx
leaq 0x22826(%rip), %rcx     # 0x265bea
callq 0xc280
jmp 0x2433cb
jmp 0x2433ec
leaq 0xc78d(%rip), %rdi      # 0x24fb61
leaq 0x227ff(%rip), %rsi     # 0x265bda
movl $0x2e, %edx
leaq 0x22803(%rip), %rcx     # 0x265bea
callq 0xc280
cmpl $0x4, -0x14(%rbp)
jne 0x243404
movq -0x60(%rbp), %rax
movl 0x29e4(%rax), %eax
movl %eax, -0x1dc(%rbp)
jmp 0x243414
movq -0x60(%rbp), %rax
movl 0x29e0(%rax), %eax
movl %eax, -0x1dc(%rbp)
movq -0x60(%rbp), %rdi
movl -0x1dc(%rbp), %eax
movl %eax, 0x29e8(%rdi)
callq 0x243610
jmp 0x24342b
movq -0x60(%rbp), %rdi
callq 0x243730
jmp 0x243436
movq -0x60(%rbp), %rdi
callq 0x2437a0
jmp 0x243441
movq -0x60(%rbp), %rdi
callq 0x2438e0
jmp 0x24344c
addq $0x240, %rsp            # imm = 0x240
popq %rbp
retq
movq %rdx, %rcx
movq %rax, %rdx
movq -0x1b8(%rbp), %rax
movq %rdx, -0x30(%rbp)
movl %ecx, -0x34(%rbp)
addq $0x820, %rax            # imm = 0x820
movq %rax, -0x1e8(%rbp)
movq -0x1e8(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x1f0(%rbp)
callq 0x1024b0
movq -0x1b8(%rbp), %rcx
movq -0x1f0(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x1e8(%rbp)
jne 0x243476
movq -0x198(%rbp), %rax
addq $0x618, %rax            # imm = 0x618
movq %rax, -0x1f8(%rbp)
movq -0x1f8(%rbp), %rdi
addq $-0x18, %rdi
movq %rdi, -0x200(%rbp)
callq 0x1024d0
movq -0x198(%rbp), %rcx
movq -0x200(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x1f8(%rbp)
jne 0x2434bb
movq -0x178(%rbp), %rax
addq $0x820, %rax            # imm = 0x820
movq %rax, -0x208(%rbp)
movq -0x208(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x210(%rbp)
callq 0x102530
movq -0x178(%rbp), %rcx
movq -0x210(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x208(%rbp)
jne 0x243500
movq -0x158(%rbp), %rax
addq $0x820, %rax            # imm = 0x820
movq %rax, -0x218(%rbp)
movq -0x218(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x220(%rbp)
callq 0x102530
movq -0x158(%rbp), %rcx
movq -0x220(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x218(%rbp)
jne 0x243545
movq -0x138(%rbp), %rax
addq $0x820, %rax            # imm = 0x820
movq %rax, -0x228(%rbp)
movq -0x228(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x230(%rbp)
callq 0x102550
movq -0x138(%rbp), %rcx
movq -0x230(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x228(%rbp)
jne 0x24358a
movq -0x58(%rbp), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movq %rax, -0x238(%rbp)
movq -0x238(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x240(%rbp)
callq 0xc6b8
movq -0x58(%rbp), %rcx
movq -0x240(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x238(%rbp)
jne 0x2435cc
jmp 0x2435fc
movq -0x30(%rbp), %rdi
callq 0xc5d0
nopw %cs:(%rax,%rax)