]> git.proxmox.com Git - mirror_qemu.git/blob - include/exec/tb-hash.h
tb hash: hash phys_pc, pc, and flags with xxhash
[mirror_qemu.git] / include / exec / tb-hash.h
1 /*
2 * internal execution defines for qemu
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef EXEC_TB_HASH
21 #define EXEC_TB_HASH
22
23 #include "exec/exec-all.h"
24 #include "exec/tb-hash-xx.h"
25
26 /* Only the bottom TB_JMP_PAGE_BITS of the jump cache hash bits vary for
27 addresses on the same page. The top bits are the same. This allows
28 TLB invalidation to quickly clear a subset of the hash table. */
29 #define TB_JMP_PAGE_BITS (TB_JMP_CACHE_BITS / 2)
30 #define TB_JMP_PAGE_SIZE (1 << TB_JMP_PAGE_BITS)
31 #define TB_JMP_ADDR_MASK (TB_JMP_PAGE_SIZE - 1)
32 #define TB_JMP_PAGE_MASK (TB_JMP_CACHE_SIZE - TB_JMP_PAGE_SIZE)
33
34 static inline unsigned int tb_jmp_cache_hash_page(target_ulong pc)
35 {
36 target_ulong tmp;
37 tmp = pc ^ (pc >> (TARGET_PAGE_BITS - TB_JMP_PAGE_BITS));
38 return (tmp >> (TARGET_PAGE_BITS - TB_JMP_PAGE_BITS)) & TB_JMP_PAGE_MASK;
39 }
40
41 static inline unsigned int tb_jmp_cache_hash_func(target_ulong pc)
42 {
43 target_ulong tmp;
44 tmp = pc ^ (pc >> (TARGET_PAGE_BITS - TB_JMP_PAGE_BITS));
45 return (((tmp >> (TARGET_PAGE_BITS - TB_JMP_PAGE_BITS)) & TB_JMP_PAGE_MASK)
46 | (tmp & TB_JMP_ADDR_MASK));
47 }
48
49 static inline
50 uint32_t tb_hash_func(tb_page_addr_t phys_pc, target_ulong pc, uint32_t flags)
51 {
52 return tb_hash_func5(phys_pc, pc, flags) & (CODE_GEN_PHYS_HASH_SIZE - 1);
53 }
54
55 #endif