01de21e2d9679b1c41e0a39f56daf0d84cf1c010
[sfrench/cifs-2.6.git] / arch / x86 / include / asm / jump_label.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_JUMP_LABEL_H
3 #define _ASM_X86_JUMP_LABEL_H
4
5 #define HAVE_JUMP_LABEL_BATCH
6
7 #define JUMP_LABEL_NOP_SIZE 5
8
9 #include <asm/asm.h>
10 #include <asm/nops.h>
11
12 #ifndef __ASSEMBLY__
13
14 #include <linux/stringify.h>
15 #include <linux/types.h>
16
17 static __always_inline bool arch_static_branch(struct static_key * const key, const bool branch)
18 {
19         asm_volatile_goto("1:"
20                 ".byte " __stringify(BYTES_NOP5) "\n\t"
21                 ".pushsection __jump_table,  \"aw\" \n\t"
22                 _ASM_ALIGN "\n\t"
23                 ".long 1b - ., %l[l_yes] - . \n\t"
24                 _ASM_PTR "%c0 + %c1 - .\n\t"
25                 ".popsection \n\t"
26                 : :  "i" (key), "i" (branch) : : l_yes);
27
28         return false;
29 l_yes:
30         return true;
31 }
32
33 static __always_inline bool arch_static_branch_jump(struct static_key * const key, const bool branch)
34 {
35         asm_volatile_goto("1:"
36                 ".byte 0xe9\n\t .long %l[l_yes] - 2f\n\t"
37                 "2:\n\t"
38                 ".pushsection __jump_table,  \"aw\" \n\t"
39                 _ASM_ALIGN "\n\t"
40                 ".long 1b - ., %l[l_yes] - . \n\t"
41                 _ASM_PTR "%c0 + %c1 - .\n\t"
42                 ".popsection \n\t"
43                 : :  "i" (key), "i" (branch) : : l_yes);
44
45         return false;
46 l_yes:
47         return true;
48 }
49
50 #endif  /* __ASSEMBLY__ */
51
52 #endif