// File: NishadSaraf[P]Championship-Simulator/src/cache.cc
// Function: CACHE::invalidate_entry(unsigned long)
int CACHE::invalidate_entry(uint64_t inval_addr)
{
    uint32_t set = get_set(inval_addr);
    int match_way = -1;

    if (NUM_SET < set) {
        cerr << "[" << NAME << "_ERROR] " << __func__ << " invalid set index: " << set << " NUM_SET: " << NUM_SET;
        cerr << " inval_addr: " << hex << inval_addr << dec << endl;
        assert(0);
    }

    // invalidate
    for (uint32_t way=0; way<NUM_WAY; way++) {
        if (block[set][way].valid && (block[set][way].tag == inval_addr)) {

            block[set][way].valid = 0;

            match_way = way;

            DP ( if (warmup_complete[cpu]) {
            cout << "[" << NAME << "] " << __func__ << " inval_addr: " << hex << inval_addr;  
            cout << " tag: " << block[set][way].tag << " data: " << block[set][way].data << dec;
            cout << " set: " << set << " way: " << way << " lru: " << block[set][way].lru << " cycle: " << current_core_cycle[cpu] << endl; });

            break;
        }
    }

    return match_way;
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movq 0x20(%rsp), %rdi
movq %rdi, (%rsp)
movq 0x18(%rsp), %rsi
callq 0x49b0
movl %eax, %ecx
movq (%rsp), %rax
movl %ecx, 0x14(%rsp)
movl $0xffffffff, 0x10(%rsp) # imm = 0xFFFFFFFF
movl 0x7370(%rax), %eax
cmpl 0x14(%rsp), %eax
jae 0x812f
movq 0x20fa6(%rip), %rdi     # 0x28ff0
leaq 0x1afdc(%rip), %rsi     # 0x2302d
callq 0x3220
movq (%rsp), %rsi
movq %rax, %rdi
addq $0x7350, %rsi           # imm = 0x7350
callq 0x31c0
movq %rax, %rdi
leaq 0x1bb72(%rip), %rsi     # 0x23be5
callq 0x3220
movq %rax, %rdi
leaq 0x1b0de(%rip), %rsi     # 0x23160
callq 0x3220
movq %rax, %rdi
leaq 0x1b06f(%rip), %rsi     # 0x23100
callq 0x3220
movq %rax, %rdi
movl 0x14(%rsp), %esi
callq 0x32c0
movq %rax, %rdi
leaq 0x1b069(%rip), %rsi     # 0x23115
callq 0x3220
movq %rax, %rdi
movq (%rsp), %rax
movl 0x7370(%rax), %esi
callq 0x32c0
movq 0x20f26(%rip), %rdi     # 0x28ff0
leaq 0x1b0a0(%rip), %rsi     # 0x23171
callq 0x3220
movq %rax, %rdi
leaq 0x17d0(%rip), %rsi      # 0x98b0
callq 0x30d0
movq %rax, %rdi
movq 0x18(%rsp), %rsi
callq 0x3080
movq %rax, %rdi
leaq 0x17d4(%rip), %rsi      # 0x98d0
callq 0x30d0
movq %rax, %rdi
movq 0x20ead(%rip), %rsi     # 0x28fb8
callq 0x3250
leaq 0x1aeed(%rip), %rdi     # 0x23004
leaq 0x1aee8(%rip), %rsi     # 0x23006
movl $0x389, %edx            # imm = 0x389
leaq 0x1b055(%rip), %rcx     # 0x2317f
callq 0x3160
movl $0x0, 0xc(%rsp)
movq (%rsp), %rcx
movl 0xc(%rsp), %eax
cmpl 0x7374(%rcx), %eax
jae 0x81d4
movq (%rsp), %rax
movq 0x7390(%rax), %rax
movl 0x14(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movl 0xc(%rsp), %ecx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
cmpb $0x0, (%rax)
je 0x81c2
movq (%rsp), %rax
movq 0x7390(%rax), %rax
movl 0x14(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movl 0xc(%rsp), %ecx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq 0x28(%rax), %rax
cmpq 0x18(%rsp), %rax
jne 0x81c2
movq (%rsp), %rax
movq 0x7390(%rax), %rax
movl 0x14(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movl 0xc(%rsp), %ecx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl 0xc(%rsp), %eax
movl %eax, 0x10(%rsp)
jmp 0x81d4
jmp 0x81c4
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x8137
movl 0x10(%rsp), %eax
addq $0x28, %rsp
retq
nopl (%rax)