// File: NishadSaraf[P]Championship-Simulator/src/cache.cc
// Function: CACHE::fill_cache(unsigned int, unsigned int, PACKET*)
void CACHE::fill_cache(uint32_t set, uint32_t way, PACKET *packet)
{
#ifdef SANITY_CHECK
    if (cache_type == IS_ITLB) {
        if (packet->data == 0)
            assert(0);
    }

    if (cache_type == IS_DTLB) {
        if (packet->data == 0)
            assert(0);
    }

    if (cache_type == IS_STLB) {
        if (packet->data == 0)
            assert(0);
    }
#endif
    if (block[set][way].prefetch && (block[set][way].used == 0))
        STATS.pf_useless++;

    if (block[set][way].valid == 0)
        block[set][way].valid = 1;
    block[set][way].dirty = 0;
    block[set][way].prefetch = (packet->type == PREFETCH) ? 1 : 0;
    block[set][way].used = 0;

    if (block[set][way].prefetch)
        STATS.pf_fill++;

    block[set][way].delta = packet->delta;
    block[set][way].depth = packet->depth;
    block[set][way].signature = packet->signature;
    block[set][way].confidence = packet->confidence;

    block[set][way].tag = packet->address;
    block[set][way].address = packet->address;
    block[set][way].full_addr = packet->full_addr;
    block[set][way].data = packet->data;
    block[set][way].cpu = packet->cpu;
    block[set][way].instr_id = packet->instr_id;

    DP ( if (warmup_complete[packet->cpu]) {
    cout << "[" << NAME << "] " << __func__ << " set: " << set << " way: " << way;
    cout << " lru: " << block[set][way].lru << " tag: " << hex << block[set][way].tag << " full_addr: " << block[set][way].full_addr;
    cout << " data: " << block[set][way].data << dec << endl; });
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movl %esi, 0x1c(%rsp)
movl %edx, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x8(%rsp)
movzbl 0x73a4(%rax), %eax
cmpl $0x0, %eax
jne 0x4b5c
movq 0x10(%rsp), %rax
cmpq $0x0, 0x360(%rax)
jne 0x4b5a
leaq 0x1e4c2(%rip), %rdi     # 0x23004
leaq 0x1e4bd(%rip), %rsi     # 0x23006
movl $0x337, %edx            # imm = 0x337
leaq 0x1e56c(%rip), %rcx     # 0x230c1
callq 0x3160
jmp 0x4b5c
movq 0x8(%rsp), %rax
movzbl 0x73a4(%rax), %eax
cmpl $0x1, %eax
jne 0x4b9d
movq 0x10(%rsp), %rax
cmpq $0x0, 0x360(%rax)
jne 0x4b9b
leaq 0x1e481(%rip), %rdi     # 0x23004
leaq 0x1e47c(%rip), %rsi     # 0x23006
movl $0x33c, %edx            # imm = 0x33C
leaq 0x1e52b(%rip), %rcx     # 0x230c1
callq 0x3160
jmp 0x4b9d
movq 0x8(%rsp), %rax
movzbl 0x73a4(%rax), %eax
cmpl $0x2, %eax
jne 0x4bde
movq 0x10(%rsp), %rax
cmpq $0x0, 0x360(%rax)
jne 0x4bdc
leaq 0x1e440(%rip), %rdi     # 0x23004
leaq 0x1e43b(%rip), %rsi     # 0x23006
movl $0x341, %edx            # imm = 0x341
leaq 0x1e4ea(%rip), %rcx     # 0x230c1
callq 0x3160
jmp 0x4bde
movq 0x8(%rsp), %rax
movq 0x7390(%rax), %rax
movl 0x1c(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movl 0x18(%rsp), %ecx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
cmpb $0x0, 0x1(%rax)
je 0x4c42
movq 0x8(%rsp), %rax
movq 0x7390(%rax), %rax
movl 0x1c(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movl 0x18(%rsp), %ecx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movzbl 0x3(%rax), %eax
cmpl $0x0, %eax
jne 0x4c42
movq 0x8(%rsp), %rax
movq 0x102d8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x102d8(%rax)
movq 0x8(%rsp), %rax
movq 0x7390(%rax), %rax
movl 0x1c(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movl 0x18(%rsp), %ecx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x4c8b
movq 0x8(%rsp), %rax
movq 0x7390(%rax), %rax
movl 0x1c(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movl 0x18(%rsp), %ecx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x1, (%rax)
movq 0x8(%rsp), %rax
movq 0x7390(%rax), %rcx
movl 0x1c(%rsp), %edx
movq (%rcx,%rdx,8), %rcx
movl 0x18(%rsp), %edx
imulq $0x50, %rdx, %rdx
addq %rdx, %rcx
movb $0x0, 0x2(%rcx)
movq 0x10(%rsp), %rcx
movzbl 0x32f(%rcx), %esi
xorl %ecx, %ecx
movl $0x1, %edx
cmpl $0x2, %esi
cmovel %edx, %ecx
movb %cl, %dl
movq 0x7390(%rax), %rcx
movl 0x1c(%rsp), %esi
movq (%rcx,%rsi,8), %rcx
movl 0x18(%rsp), %esi
imulq $0x50, %rsi, %rsi
addq %rsi, %rcx
movb %dl, 0x1(%rcx)
movq 0x7390(%rax), %rcx
movl 0x1c(%rsp), %edx
movq (%rcx,%rdx,8), %rcx
movl 0x18(%rsp), %edx
imulq $0x50, %rdx, %rdx
addq %rdx, %rcx
movb $0x0, 0x3(%rcx)
movq 0x7390(%rax), %rax
movl 0x1c(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movl 0x18(%rsp), %ecx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
cmpb $0x0, 0x1(%rax)
je 0x4d3b
movq 0x8(%rsp), %rax
movq 0x102e0(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x102e0(%rax)
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
movl 0x18(%rcx), %edx
movq 0x7390(%rax), %rcx
movl 0x1c(%rsp), %esi
movq (%rcx,%rsi,8), %rcx
movl 0x18(%rsp), %esi
imulq $0x50, %rsi, %rsi
addq %rsi, %rcx
movl %edx, 0x4(%rcx)
movq 0x10(%rsp), %rcx
movl 0x1c(%rcx), %edx
movq 0x7390(%rax), %rcx
movl 0x1c(%rsp), %esi
movq (%rcx,%rsi,8), %rcx
movl 0x18(%rsp), %esi
imulq $0x50, %rsi, %rsi
addq %rsi, %rcx
movl %edx, 0x8(%rcx)
movq 0x10(%rsp), %rcx
movl 0x20(%rcx), %edx
movq 0x7390(%rax), %rcx
movl 0x1c(%rsp), %esi
movq (%rcx,%rsi,8), %rcx
movl 0x18(%rsp), %esi
imulq $0x50, %rsi, %rsi
addq %rsi, %rcx
movl %edx, 0xc(%rcx)
movq 0x10(%rsp), %rcx
movl 0x24(%rcx), %edx
movq 0x7390(%rax), %rcx
movl 0x1c(%rsp), %esi
movq (%rcx,%rsi,8), %rcx
movl 0x18(%rsp), %esi
imulq $0x50, %rsi, %rsi
addq %rsi, %rcx
movl %edx, 0x10(%rcx)
movq 0x10(%rsp), %rcx
movq 0x340(%rcx), %rdx
movq 0x7390(%rax), %rcx
movl 0x1c(%rsp), %esi
movq (%rcx,%rsi,8), %rcx
movl 0x18(%rsp), %esi
imulq $0x50, %rsi, %rsi
addq %rsi, %rcx
movq %rdx, 0x28(%rcx)
movq 0x10(%rsp), %rcx
movq 0x340(%rcx), %rdx
movq 0x7390(%rax), %rcx
movl 0x1c(%rsp), %esi
movq (%rcx,%rsi,8), %rcx
movl 0x18(%rsp), %esi
imulq $0x50, %rsi, %rsi
addq %rsi, %rcx
movq %rdx, 0x18(%rcx)
movq 0x10(%rsp), %rcx
movq 0x348(%rcx), %rdx
movq 0x7390(%rax), %rcx
movl 0x1c(%rsp), %esi
movq (%rcx,%rsi,8), %rcx
movl 0x18(%rsp), %esi
imulq $0x50, %rsi, %rsi
addq %rsi, %rcx
movq %rdx, 0x20(%rcx)
movq 0x10(%rsp), %rcx
movq 0x360(%rcx), %rdx
movq 0x7390(%rax), %rcx
movl 0x1c(%rsp), %esi
movq (%rcx,%rsi,8), %rcx
movl 0x18(%rsp), %esi
imulq $0x50, %rsi, %rsi
addq %rsi, %rcx
movq %rdx, 0x30(%rcx)
movq 0x10(%rsp), %rcx
movl 0x330(%rcx), %ecx
movl %ecx, %edx
movq 0x7390(%rax), %rcx
movl 0x1c(%rsp), %esi
movq (%rcx,%rsi,8), %rcx
movl 0x18(%rsp), %esi
imulq $0x50, %rsi, %rsi
addq %rsi, %rcx
movq %rdx, 0x38(%rcx)
movq 0x10(%rsp), %rcx
movq 0x368(%rcx), %rcx
movq 0x7390(%rax), %rax
movl 0x1c(%rsp), %edx
movq (%rax,%rdx,8), %rax
movl 0x18(%rsp), %edx
imulq $0x50, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x40(%rax)
addq $0x28, %rsp
retq
nopw %cs:(%rax,%rax)