blob: 805235d321c27390f6e85fc3586c65aec5b16992 [file] [log] [blame]
Peter Crosthwaitee1b89322015-05-30 23:11:45 -07001/*
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
Markus Armbruster2a6a4072016-06-29 13:47:03 +020020#ifndef EXEC_TB_HASH_H
21#define EXEC_TB_HASH_H
Peter Crosthwaitee1b89322015-05-30 23:11:45 -070022
Markus Armbrusterec150c72019-08-12 07:23:31 +020023#include "exec/cpu-defs.h"
24#include "exec/exec-all.h"
Emilio G. Cotafe656e32018-10-20 18:49:53 -040025#include "qemu/xxhash.h"
Emilio G. Cota42bd3222016-06-08 14:55:25 -040026
Emilio G. Cota6f165312017-04-26 23:29:24 -040027#ifdef CONFIG_SOFTMMU
28
Peter Crosthwaite41da4bd2015-05-30 23:11:46 -070029/* Only the bottom TB_JMP_PAGE_BITS of the jump cache hash bits vary for
30 addresses on the same page. The top bits are the same. This allows
31 TLB invalidation to quickly clear a subset of the hash table. */
32#define TB_JMP_PAGE_BITS (TB_JMP_CACHE_BITS / 2)
33#define TB_JMP_PAGE_SIZE (1 << TB_JMP_PAGE_BITS)
34#define TB_JMP_ADDR_MASK (TB_JMP_PAGE_SIZE - 1)
35#define TB_JMP_PAGE_MASK (TB_JMP_CACHE_SIZE - TB_JMP_PAGE_SIZE)
36
Peter Crosthwaitee1b89322015-05-30 23:11:45 -070037static inline unsigned int tb_jmp_cache_hash_page(target_ulong pc)
38{
39 target_ulong tmp;
40 tmp = pc ^ (pc >> (TARGET_PAGE_BITS - TB_JMP_PAGE_BITS));
41 return (tmp >> (TARGET_PAGE_BITS - TB_JMP_PAGE_BITS)) & TB_JMP_PAGE_MASK;
42}
43
44static inline unsigned int tb_jmp_cache_hash_func(target_ulong pc)
45{
46 target_ulong tmp;
47 tmp = pc ^ (pc >> (TARGET_PAGE_BITS - TB_JMP_PAGE_BITS));
48 return (((tmp >> (TARGET_PAGE_BITS - TB_JMP_PAGE_BITS)) & TB_JMP_PAGE_MASK)
49 | (tmp & TB_JMP_ADDR_MASK));
50}
51
Emilio G. Cota6f165312017-04-26 23:29:24 -040052#else
53
54/* In user-mode we can get better hashing because we do not have a TLB */
55static inline unsigned int tb_jmp_cache_hash_func(target_ulong pc)
56{
57 return (pc ^ (pc >> TB_JMP_CACHE_BITS)) & (TB_JMP_CACHE_SIZE - 1);
58}
59
60#endif /* CONFIG_SOFTMMU */
61
Emilio G. Cota42bd3222016-06-08 14:55:25 -040062static inline
LluĂ­s Vilanova61a67f72017-07-04 10:42:32 +020063uint32_t tb_hash_func(tb_page_addr_t phys_pc, target_ulong pc, uint32_t flags,
Emilio G. Cota4e2ca832017-07-11 14:29:37 -040064 uint32_t cf_mask, uint32_t trace_vcpu_dstate)
Peter Crosthwaitee1b89322015-05-30 23:11:45 -070065{
Emilio G. Cotac971d8f2018-10-20 18:46:28 -040066 return qemu_xxhash7(phys_pc, pc, flags, cf_mask, trace_vcpu_dstate);
Peter Crosthwaitee1b89322015-05-30 23:11:45 -070067}
68
69#endif