Peter Crosthwaite | e1b8932 | 2015-05-30 23:11:45 -0700 | [diff] [blame] | 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 |
Chetan Pant | d6ea423 | 2020-10-23 12:33:53 +0000 | [diff] [blame] | 9 | * version 2.1 of the License, or (at your option) any later version. |
Peter Crosthwaite | e1b8932 | 2015-05-30 23:11:45 -0700 | [diff] [blame] | 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 Armbruster | 2a6a407 | 2016-06-29 13:47:03 +0200 | [diff] [blame] | 20 | #ifndef EXEC_TB_HASH_H |
| 21 | #define EXEC_TB_HASH_H |
Peter Crosthwaite | e1b8932 | 2015-05-30 23:11:45 -0700 | [diff] [blame] | 22 | |
Markus Armbruster | ec150c7 | 2019-08-12 07:23:31 +0200 | [diff] [blame] | 23 | #include "exec/cpu-defs.h" |
| 24 | #include "exec/exec-all.h" |
Emilio G. Cota | fe656e3 | 2018-10-20 18:49:53 -0400 | [diff] [blame] | 25 | #include "qemu/xxhash.h" |
Richard Henderson | a976a99 | 2022-08-15 15:13:05 -0500 | [diff] [blame] | 26 | #include "tb-jmp-cache.h" |
Emilio G. Cota | 42bd322 | 2016-06-08 14:55:25 -0400 | [diff] [blame] | 27 | |
Emilio G. Cota | 6f16531 | 2017-04-26 23:29:24 -0400 | [diff] [blame] | 28 | #ifdef CONFIG_SOFTMMU |
| 29 | |
Peter Crosthwaite | 41da4bd | 2015-05-30 23:11:46 -0700 | [diff] [blame] | 30 | /* Only the bottom TB_JMP_PAGE_BITS of the jump cache hash bits vary for |
| 31 | addresses on the same page. The top bits are the same. This allows |
| 32 | TLB invalidation to quickly clear a subset of the hash table. */ |
| 33 | #define TB_JMP_PAGE_BITS (TB_JMP_CACHE_BITS / 2) |
| 34 | #define TB_JMP_PAGE_SIZE (1 << TB_JMP_PAGE_BITS) |
| 35 | #define TB_JMP_ADDR_MASK (TB_JMP_PAGE_SIZE - 1) |
| 36 | #define TB_JMP_PAGE_MASK (TB_JMP_CACHE_SIZE - TB_JMP_PAGE_SIZE) |
| 37 | |
Anton Johansson | 06f3831 | 2023-06-21 15:56:28 +0200 | [diff] [blame] | 38 | static inline unsigned int tb_jmp_cache_hash_page(vaddr pc) |
Peter Crosthwaite | e1b8932 | 2015-05-30 23:11:45 -0700 | [diff] [blame] | 39 | { |
Anton Johansson | 06f3831 | 2023-06-21 15:56:28 +0200 | [diff] [blame] | 40 | vaddr tmp; |
Peter Crosthwaite | e1b8932 | 2015-05-30 23:11:45 -0700 | [diff] [blame] | 41 | tmp = pc ^ (pc >> (TARGET_PAGE_BITS - TB_JMP_PAGE_BITS)); |
| 42 | return (tmp >> (TARGET_PAGE_BITS - TB_JMP_PAGE_BITS)) & TB_JMP_PAGE_MASK; |
| 43 | } |
| 44 | |
Anton Johansson | 06f3831 | 2023-06-21 15:56:28 +0200 | [diff] [blame] | 45 | static inline unsigned int tb_jmp_cache_hash_func(vaddr pc) |
Peter Crosthwaite | e1b8932 | 2015-05-30 23:11:45 -0700 | [diff] [blame] | 46 | { |
Anton Johansson | 06f3831 | 2023-06-21 15:56:28 +0200 | [diff] [blame] | 47 | vaddr tmp; |
Peter Crosthwaite | e1b8932 | 2015-05-30 23:11:45 -0700 | [diff] [blame] | 48 | tmp = pc ^ (pc >> (TARGET_PAGE_BITS - TB_JMP_PAGE_BITS)); |
| 49 | return (((tmp >> (TARGET_PAGE_BITS - TB_JMP_PAGE_BITS)) & TB_JMP_PAGE_MASK) |
| 50 | | (tmp & TB_JMP_ADDR_MASK)); |
| 51 | } |
| 52 | |
Emilio G. Cota | 6f16531 | 2017-04-26 23:29:24 -0400 | [diff] [blame] | 53 | #else |
| 54 | |
| 55 | /* In user-mode we can get better hashing because we do not have a TLB */ |
Anton Johansson | 06f3831 | 2023-06-21 15:56:28 +0200 | [diff] [blame] | 56 | static inline unsigned int tb_jmp_cache_hash_func(vaddr pc) |
Emilio G. Cota | 6f16531 | 2017-04-26 23:29:24 -0400 | [diff] [blame] | 57 | { |
| 58 | return (pc ^ (pc >> TB_JMP_CACHE_BITS)) & (TB_JMP_CACHE_SIZE - 1); |
| 59 | } |
| 60 | |
| 61 | #endif /* CONFIG_SOFTMMU */ |
| 62 | |
Emilio G. Cota | 42bd322 | 2016-06-08 14:55:25 -0400 | [diff] [blame] | 63 | static inline |
Anton Johansson | 06f3831 | 2023-06-21 15:56:28 +0200 | [diff] [blame] | 64 | uint32_t tb_hash_func(tb_page_addr_t phys_pc, vaddr pc, |
Alex Bennée | 367189e | 2023-05-26 17:54:01 +0100 | [diff] [blame] | 65 | uint32_t flags, uint64_t flags2, uint32_t cf_mask) |
Peter Crosthwaite | e1b8932 | 2015-05-30 23:11:45 -0700 | [diff] [blame] | 66 | { |
Alex Bennée | 367189e | 2023-05-26 17:54:01 +0100 | [diff] [blame] | 67 | return qemu_xxhash8(phys_pc, pc, flags2, flags, cf_mask); |
Peter Crosthwaite | e1b8932 | 2015-05-30 23:11:45 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | #endif |