| 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.1 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_H |
| 21 | #define EXEC_TB_HASH_H |
| 22 | |
| 23 | #include "exec/vaddr.h" |
| 24 | #include "exec/target_page.h" |
| 25 | #include "exec/translation-block.h" |
| 26 | #include "qemu/xxhash.h" |
| 27 | #include "tb-jmp-cache.h" |
| 28 | |
| 29 | #ifdef CONFIG_SOFTMMU |
| 30 | |
| 31 | /* Only the bottom TB_JMP_PAGE_BITS of the jump cache hash bits vary for |
| 32 | addresses on the same page. The top bits are the same. This allows |
| 33 | TLB invalidation to quickly clear a subset of the hash table. */ |
| 34 | #define TB_JMP_PAGE_BITS (TB_JMP_CACHE_BITS / 2) |
| 35 | #define TB_JMP_PAGE_SIZE (1 << TB_JMP_PAGE_BITS) |
| 36 | #define TB_JMP_ADDR_MASK (TB_JMP_PAGE_SIZE - 1) |
| 37 | #define TB_JMP_PAGE_MASK (TB_JMP_CACHE_SIZE - TB_JMP_PAGE_SIZE) |
| 38 | |
| 39 | static inline unsigned int tb_jmp_cache_hash_page(vaddr pc) |
| 40 | { |
| 41 | vaddr tmp; |
| 42 | tmp = pc ^ (pc >> (TARGET_PAGE_BITS - TB_JMP_PAGE_BITS)); |
| 43 | return (tmp >> (TARGET_PAGE_BITS - TB_JMP_PAGE_BITS)) & TB_JMP_PAGE_MASK; |
| 44 | } |
| 45 | |
| 46 | static inline unsigned int tb_jmp_cache_hash_func(vaddr pc) |
| 47 | { |
| 48 | vaddr tmp; |
| 49 | tmp = pc ^ (pc >> (TARGET_PAGE_BITS - TB_JMP_PAGE_BITS)); |
| 50 | return (((tmp >> (TARGET_PAGE_BITS - TB_JMP_PAGE_BITS)) & TB_JMP_PAGE_MASK) |
| 51 | | (tmp & TB_JMP_ADDR_MASK)); |
| 52 | } |
| 53 | |
| 54 | #else |
| 55 | |
| 56 | /* In user-mode we can get better hashing because we do not have a TLB */ |
| 57 | static inline unsigned int tb_jmp_cache_hash_func(vaddr pc) |
| 58 | { |
| 59 | return (pc ^ (pc >> TB_JMP_CACHE_BITS)) & (TB_JMP_CACHE_SIZE - 1); |
| 60 | } |
| 61 | |
| 62 | #endif /* CONFIG_SOFTMMU */ |
| 63 | |
| 64 | static inline |
| 65 | uint32_t tb_hash_func(tb_page_addr_t phys_pc, vaddr pc, |
| 66 | uint32_t flags, uint64_t flags2, uint32_t cf_mask) |
| 67 | { |
| 68 | return qemu_xxhash8(phys_pc, pc, flags2, flags, cf_mask); |
| 69 | } |
| 70 | |
| 71 | #endif |