1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_ALTERNATIVE_ASM_H
3 #define _ASM_X86_ALTERNATIVE_ASM_H
12 .pushsection
.smp_locks
,"a"
23 * Issue one struct alt_instr descriptor entry (need to put it into
24 * the section .altinstructions, see below). This entry contains
25 * enough information for the alternatives patching code to patch an
26 * instruction. See apply_alternatives().
28 .macro altinstruction_entry orig alt feature orig_len alt_len pad_len
38 * Define an alternative between two instructions. If @feature is
39 * present, early code in apply_alternatives() replaces @oldinstr with
40 * @newinstr. ".skip" directive takes care of proper instruction padding
41 * in case @newinstr is longer than @oldinstr.
43 .macro ALTERNATIVE oldinstr
, newinstr
, feature
47 .skip
-(((144f
-143f
)-(141b
-140b
)) > 0) * ((144f
-143f
)-(141b
-140b
)),0x90
50 .pushsection
.altinstructions
,"a"
51 altinstruction_entry
140b
,143f
,\feature
,142b
-140b
,144f
-143f
,142b
-141b
54 .pushsection
.altinstr_replacement
,"ax"
61 #define old_len 141b-140b
62 #define new_len1 144f-143f
63 #define new_len2 145f-144f
66 * gas compatible max based on the idea from:
67 * http://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax
69 * The additional "-" is needed because gas uses a "true" value of -1.
71 #define alt_max_short(a, b) ((a) ^ (((a) ^ (b)) & -(-((a) < (b)))))
75 * Same as ALTERNATIVE macro above but for two alternatives. If CPU
76 * has @feature1, it replaces @oldinstr with @newinstr1. If CPU has
77 * @feature2, it replaces @oldinstr with @feature2.
79 .macro ALTERNATIVE_2 oldinstr
, newinstr1
, feature1
, newinstr2
, feature2
83 .skip
-((alt_max_short(new_len1
, new_len2
) - (old_len
)) > 0) * \
84 (alt_max_short(new_len1
, new_len2
) - (old_len
)),0x90
87 .pushsection
.altinstructions
,"a"
88 altinstruction_entry
140b
,143f
,\feature
1,142b
-140b
,144f
-143f
,142b
-141b
89 altinstruction_entry
140b
,144f
,\feature
2,142b
-140b
,145f
-144f
,142b
-141b
92 .pushsection
.altinstr_replacement
,"ax"
101 #endif /* __ASSEMBLY__ */
103 #endif /* _ASM_X86_ALTERNATIVE_ASM_H */