// File: gvaumour[P]cache-simulator/src/FeaturesFunction.cc
// Function: hashing_function1(params_hash, unsigned long, unsigned long)
int hashing_function1(params_hash a , uint64_t addr , uint64_t missPC)
{
	string index = a.index;
	bool hash_with_PC = a.xorWithPC;
	int block = a.nbBlock;
	//string b = hash_with_PC ? "TRUE" : "FALSE";
	//cout << "index = " << index << " block = " << block << " hash_with_PC = " << b << endl;
	assert( block < 8);
	uint64_t tag = 0;
	
	if( index == "MissPC")
		tag = bitSelect( missPC , 8*block , 8*block+7);
	else if( index == "Addr")
		tag = bitSelect( addr , 8*block , 8*block+7);
	else if( index == "currentPC")
		tag = bitSelect( Predictor::m_global_PChistory[0] , 8*block , 8*block+7);
	else if( index == "currentPC1")
		tag = bitSelect( Predictor::m_global_PChistory[1] , 8*block , 8*block+7);
	else if( index == "currentPC2")
		tag = bitSelect( Predictor::m_global_PChistory[2] , 8*block , 8*block+7);
	else if( index == "currentPC3")
		tag = bitSelect( Predictor::m_global_PChistory[3] , 8*block , 8*block+7);
	else
		assert(false && "Hashing Function failed");
	
	if( hash_with_PC)
		tag = (tag ^ Predictor::m_global_PChistory[0])%256;

	return tag;
}

// Assembly:
subq $0xd8, %rsp
movq %rsi, %rax
movq %rdi, %rsi
movq %rsi, 0x78(%rsp)
movq %rsi, 0xd0(%rsp)
movq %rax, 0xc8(%rsp)
movq %rdx, 0xc0(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x51b0
movq 0x78(%rsp), %rdi
movb 0x20(%rdi), %al
andb $0x1, %al
movb %al, 0x9f(%rsp)
movl 0x24(%rdi), %eax
movl %eax, 0x98(%rsp)
cmpl $0x8, 0x98(%rsp)
jge 0x2ff9e
jmp 0x2ffbd
leaq 0x42290(%rip), %rdi     # 0x72235
leaq 0x42293(%rip), %rsi     # 0x7223f
movl $0x12, %edx
leaq 0x4229f(%rip), %rcx     # 0x72257
callq 0x5260
movq $0x0, 0x90(%rsp)
leaq 0x422be(%rip), %rsi     # 0x7228e
leaq 0xa0(%rsp), %rdi
callq 0xfa60
movb %al, 0x77(%rsp)
jmp 0x2ffe3
movb 0x77(%rsp), %al
testb $0x1, %al
jne 0x2ffed
jmp 0x3004e
movq 0xc0(%rsp), %rdi
movl 0x98(%rsp), %ecx
movl %ecx, %esi
shll $0x3, %esi
movl %ecx, %eax
leal 0x7(,%rax,8), %edx
callq 0x65540
movq %rax, 0x68(%rsp)
jmp 0x30016
movq 0x68(%rsp), %rax
movq %rax, 0x90(%rsp)
jmp 0x3027e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x88(%rsp)
movl %eax, 0x84(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x5768
jmp 0x302e3
leaq 0x42240(%rip), %rsi     # 0x72295
leaq 0xa0(%rsp), %rdi
callq 0xfa60
movb %al, 0x67(%rsp)
jmp 0x30068
movb 0x67(%rsp), %al
testb $0x1, %al
jne 0x30072
jmp 0x300ad
movq 0xc8(%rsp), %rdi
movl 0x98(%rsp), %ecx
movl %ecx, %esi
shll $0x3, %esi
movl %ecx, %eax
leal 0x7(,%rax,8), %edx
callq 0x65540
movq %rax, 0x58(%rsp)
jmp 0x3009b
movq 0x58(%rsp), %rax
movq %rax, 0x90(%rsp)
jmp 0x3027c
leaq 0x421e6(%rip), %rsi     # 0x7229a
leaq 0xa0(%rsp), %rdi
callq 0xfa60
movb %al, 0x57(%rsp)
jmp 0x300c7
movb 0x57(%rsp), %al
testb $0x1, %al
jne 0x300d1
jmp 0x30117
leaq 0x63c28(%rip), %rdi     # 0x93d00
xorl %eax, %eax
movl %eax, %esi
callq 0x30840
movq (%rax), %rdi
movl 0x98(%rsp), %ecx
movl %ecx, %esi
shll $0x3, %esi
movl %ecx, %eax
leal 0x7(,%rax,8), %edx
callq 0x65540
movq %rax, 0x48(%rsp)
jmp 0x30105
movq 0x48(%rsp), %rax
movq %rax, 0x90(%rsp)
jmp 0x3027a
leaq 0x42186(%rip), %rsi     # 0x722a4
leaq 0xa0(%rsp), %rdi
callq 0xfa60
movb %al, 0x47(%rsp)
jmp 0x30131
movb 0x47(%rsp), %al
testb $0x1, %al
jne 0x3013b
jmp 0x30182
leaq 0x63bbe(%rip), %rdi     # 0x93d00
movl $0x1, %esi
callq 0x30840
movq (%rax), %rdi
movl 0x98(%rsp), %ecx
movl %ecx, %esi
shll $0x3, %esi
movl %ecx, %eax
leal 0x7(,%rax,8), %edx
callq 0x65540
movq %rax, 0x38(%rsp)
jmp 0x30170
movq 0x38(%rsp), %rax
movq %rax, 0x90(%rsp)
jmp 0x30278
leaq 0x42126(%rip), %rsi     # 0x722af
leaq 0xa0(%rsp), %rdi
callq 0xfa60
movb %al, 0x37(%rsp)
jmp 0x3019c
movb 0x37(%rsp), %al
testb $0x1, %al
jne 0x301a6
jmp 0x301ed
leaq 0x63b53(%rip), %rdi     # 0x93d00
movl $0x2, %esi
callq 0x30840
movq (%rax), %rdi
movl 0x98(%rsp), %ecx
movl %ecx, %esi
shll $0x3, %esi
movl %ecx, %eax
leal 0x7(,%rax,8), %edx
callq 0x65540
movq %rax, 0x28(%rsp)
jmp 0x301db
movq 0x28(%rsp), %rax
movq %rax, 0x90(%rsp)
jmp 0x30276
leaq 0x420c6(%rip), %rsi     # 0x722ba
leaq 0xa0(%rsp), %rdi
callq 0xfa60
movb %al, 0x27(%rsp)
jmp 0x30207
movb 0x27(%rsp), %al
testb $0x1, %al
jne 0x30211
jmp 0x30255
leaq 0x63ae8(%rip), %rdi     # 0x93d00
movl $0x3, %esi
callq 0x30840
movq (%rax), %rdi
movl 0x98(%rsp), %ecx
movl %ecx, %esi
shll $0x3, %esi
movl %ecx, %eax
leal 0x7(,%rax,8), %edx
callq 0x65540
movq %rax, 0x18(%rsp)
jmp 0x30246
movq 0x18(%rsp), %rax
movq %rax, 0x90(%rsp)
jmp 0x30274
leaq 0x42069(%rip), %rdi     # 0x722c5
leaq 0x41fdc(%rip), %rsi     # 0x7223f
movl $0x22, %edx
leaq 0x41fe8(%rip), %rcx     # 0x72257
callq 0x5260
jmp 0x30276
jmp 0x30278
jmp 0x3027a
jmp 0x3027c
jmp 0x3027e
testb $0x1, 0x9f(%rsp)
je 0x302be
movq 0x90(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0x63a64(%rip), %rdi     # 0x93d00
xorl %eax, %eax
movl %eax, %esi
callq 0x30840
movq %rax, %rcx
movq 0x10(%rsp), %rax
xorq (%rcx), %rax
andq $0xff, %rax
movq %rax, 0x90(%rsp)
movq 0x90(%rsp), %rax
movl %eax, 0xc(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x5768
movl 0xc(%rsp), %eax
addq $0xd8, %rsp
retq
movq 0x88(%rsp), %rdi
callq 0x5690