xref: /openbmc/qemu/accel/tcg/tb-hash.h (revision 4329d049d5b8d4af71c6b399d64a6d1b98856318)
1e5ceadffSPhilippe Mathieu-Daudé /*
2e5ceadffSPhilippe Mathieu-Daudé  * internal execution defines for qemu
3e5ceadffSPhilippe Mathieu-Daudé  *
4e5ceadffSPhilippe Mathieu-Daudé  *  Copyright (c) 2003 Fabrice Bellard
5e5ceadffSPhilippe Mathieu-Daudé  *
6e5ceadffSPhilippe Mathieu-Daudé  * This library is free software; you can redistribute it and/or
7e5ceadffSPhilippe Mathieu-Daudé  * modify it under the terms of the GNU Lesser General Public
8e5ceadffSPhilippe Mathieu-Daudé  * License as published by the Free Software Foundation; either
9e5ceadffSPhilippe Mathieu-Daudé  * version 2.1 of the License, or (at your option) any later version.
10e5ceadffSPhilippe Mathieu-Daudé  *
11e5ceadffSPhilippe Mathieu-Daudé  * This library is distributed in the hope that it will be useful,
12e5ceadffSPhilippe Mathieu-Daudé  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13e5ceadffSPhilippe Mathieu-Daudé  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14e5ceadffSPhilippe Mathieu-Daudé  * Lesser General Public License for more details.
15e5ceadffSPhilippe Mathieu-Daudé  *
16e5ceadffSPhilippe Mathieu-Daudé  * You should have received a copy of the GNU Lesser General Public
17e5ceadffSPhilippe Mathieu-Daudé  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18e5ceadffSPhilippe Mathieu-Daudé  */
19e5ceadffSPhilippe Mathieu-Daudé 
20e5ceadffSPhilippe Mathieu-Daudé #ifndef EXEC_TB_HASH_H
21e5ceadffSPhilippe Mathieu-Daudé #define EXEC_TB_HASH_H
22e5ceadffSPhilippe Mathieu-Daudé 
23e5ceadffSPhilippe Mathieu-Daudé #include "exec/cpu-defs.h"
24e5ceadffSPhilippe Mathieu-Daudé #include "exec/exec-all.h"
25e5ceadffSPhilippe Mathieu-Daudé #include "qemu/xxhash.h"
26a976a99aSRichard Henderson #include "tb-jmp-cache.h"
27e5ceadffSPhilippe Mathieu-Daudé 
28e5ceadffSPhilippe Mathieu-Daudé #ifdef CONFIG_SOFTMMU
29e5ceadffSPhilippe Mathieu-Daudé 
30e5ceadffSPhilippe Mathieu-Daudé /* Only the bottom TB_JMP_PAGE_BITS of the jump cache hash bits vary for
31e5ceadffSPhilippe Mathieu-Daudé    addresses on the same page.  The top bits are the same.  This allows
32e5ceadffSPhilippe Mathieu-Daudé    TLB invalidation to quickly clear a subset of the hash table.  */
33e5ceadffSPhilippe Mathieu-Daudé #define TB_JMP_PAGE_BITS (TB_JMP_CACHE_BITS / 2)
34e5ceadffSPhilippe Mathieu-Daudé #define TB_JMP_PAGE_SIZE (1 << TB_JMP_PAGE_BITS)
35e5ceadffSPhilippe Mathieu-Daudé #define TB_JMP_ADDR_MASK (TB_JMP_PAGE_SIZE - 1)
36e5ceadffSPhilippe Mathieu-Daudé #define TB_JMP_PAGE_MASK (TB_JMP_CACHE_SIZE - TB_JMP_PAGE_SIZE)
37e5ceadffSPhilippe Mathieu-Daudé 
tb_jmp_cache_hash_page(vaddr pc)38*06f3831cSAnton Johansson static inline unsigned int tb_jmp_cache_hash_page(vaddr pc)
39e5ceadffSPhilippe Mathieu-Daudé {
40*06f3831cSAnton Johansson     vaddr tmp;
41e5ceadffSPhilippe Mathieu-Daudé     tmp = pc ^ (pc >> (TARGET_PAGE_BITS - TB_JMP_PAGE_BITS));
42e5ceadffSPhilippe Mathieu-Daudé     return (tmp >> (TARGET_PAGE_BITS - TB_JMP_PAGE_BITS)) & TB_JMP_PAGE_MASK;
43e5ceadffSPhilippe Mathieu-Daudé }
44e5ceadffSPhilippe Mathieu-Daudé 
tb_jmp_cache_hash_func(vaddr pc)45*06f3831cSAnton Johansson static inline unsigned int tb_jmp_cache_hash_func(vaddr pc)
46e5ceadffSPhilippe Mathieu-Daudé {
47*06f3831cSAnton Johansson     vaddr tmp;
48e5ceadffSPhilippe Mathieu-Daudé     tmp = pc ^ (pc >> (TARGET_PAGE_BITS - TB_JMP_PAGE_BITS));
49e5ceadffSPhilippe Mathieu-Daudé     return (((tmp >> (TARGET_PAGE_BITS - TB_JMP_PAGE_BITS)) & TB_JMP_PAGE_MASK)
50e5ceadffSPhilippe Mathieu-Daudé            | (tmp & TB_JMP_ADDR_MASK));
51e5ceadffSPhilippe Mathieu-Daudé }
52e5ceadffSPhilippe Mathieu-Daudé 
53e5ceadffSPhilippe Mathieu-Daudé #else
54e5ceadffSPhilippe Mathieu-Daudé 
55e5ceadffSPhilippe Mathieu-Daudé /* In user-mode we can get better hashing because we do not have a TLB */
tb_jmp_cache_hash_func(vaddr pc)56*06f3831cSAnton Johansson static inline unsigned int tb_jmp_cache_hash_func(vaddr pc)
57e5ceadffSPhilippe Mathieu-Daudé {
58e5ceadffSPhilippe Mathieu-Daudé     return (pc ^ (pc >> TB_JMP_CACHE_BITS)) & (TB_JMP_CACHE_SIZE - 1);
59e5ceadffSPhilippe Mathieu-Daudé }
60e5ceadffSPhilippe Mathieu-Daudé 
61e5ceadffSPhilippe Mathieu-Daudé #endif /* CONFIG_SOFTMMU */
62e5ceadffSPhilippe Mathieu-Daudé 
63e5ceadffSPhilippe Mathieu-Daudé static inline
tb_hash_func(tb_page_addr_t phys_pc,vaddr pc,uint32_t flags,uint64_t flags2,uint32_t cf_mask)64*06f3831cSAnton Johansson uint32_t tb_hash_func(tb_page_addr_t phys_pc, vaddr pc,
65367189efSAlex Bennée                       uint32_t flags, uint64_t flags2, uint32_t cf_mask)
66e5ceadffSPhilippe Mathieu-Daudé {
67367189efSAlex Bennée     return qemu_xxhash8(phys_pc, pc, flags2, flags, cf_mask);
68e5ceadffSPhilippe Mathieu-Daudé }
69e5ceadffSPhilippe Mathieu-Daudé 
70e5ceadffSPhilippe Mathieu-Daudé #endif
71