Path: blob/master/arch/loongarch/include/asm/alternative-asm.h
26488 views
/* SPDX-License-Identifier: GPL-2.0 */1#ifndef _ASM_ALTERNATIVE_ASM_H2#define _ASM_ALTERNATIVE_ASM_H34#ifdef __ASSEMBLER__56#include <asm/asm.h>78/*9* Issue one struct alt_instr descriptor entry (need to put it into10* the section .altinstructions, see below). This entry contains11* enough information for the alternatives patching code to patch an12* instruction. See apply_alternatives().13*/14.macro altinstruction_entry orig alt feature orig_len alt_len15.long \orig - .16.long \alt - .17.short \feature18.byte \orig_len19.byte \alt_len20.endm2122/*23* Define an alternative between two instructions. If @feature is24* present, early code in apply_alternatives() replaces @oldinstr with25* @newinstr. ".fill" directive takes care of proper instruction padding26* in case @newinstr is longer than @oldinstr.27*/28.macro ALTERNATIVE oldinstr, newinstr, feature29140 :30\oldinstr31141 :32.fill - (((144f-143f)-(141b-140b)) > 0) * ((144f-143f)-(141b-140b)) / 4, 4, 0x0340000033142 :3435.pushsection .altinstructions, "a"36altinstruction_entry 140b, 143f, \feature, 142b-140b, 144f-143f37.popsection3839.subsection 140143 :41\newinstr42144 :43.previous44.endm4546#define old_len (141b-140b)47#define new_len1 (144f-143f)48#define new_len2 (145f-144f)4950#define alt_max_short(a, b) ((a) ^ (((a) ^ (b)) & -(-((a) < (b)))))5152/*53* Same as ALTERNATIVE macro above but for two alternatives. If CPU54* has @feature1, it replaces @oldinstr with @newinstr1. If CPU has55* @feature2, it replaces @oldinstr with @feature2.56*/57.macro ALTERNATIVE_2 oldinstr, newinstr1, feature1, newinstr2, feature258140 :59\oldinstr60141 :61.fill - ((alt_max_short(new_len1, new_len2) - (old_len)) > 0) * \62(alt_max_short(new_len1, new_len2) - (old_len)) / 4, 4, 0x0340000063142 :6465.pushsection .altinstructions, "a"66altinstruction_entry 140b, 143f, \feature1, 142b-140b, 144f-143f, 142b-141b67altinstruction_entry 140b, 144f, \feature2, 142b-140b, 145f-144f, 142b-141b68.popsection6970.subsection 171143 :72\newinstr173144 :74\newinstr275145 :76.previous77.endm7879#endif /* __ASSEMBLER__ */8081#endif /* _ASM_ALTERNATIVE_ASM_H */828384