]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
x86/alternative: Add alternative_input_2 to support alternative with two features...
authorFenghua Yu <fenghua.yu@intel.com>
Thu, 29 May 2014 18:12:32 +0000 (11:12 -0700)
committerH. Peter Anvin <hpa@linux.intel.com>
Thu, 29 May 2014 21:24:53 +0000 (14:24 -0700)
alternative_input_2() replaces old instruction with new instructions with
input based on two features.

In alternative_input_2(oldinstr, newinstr1, feature1, newinstr2, feature2,
input...),

feature2 has higher priority to replace oldinstr than feature1.

If CPU has feature2, newinstr2 replaces oldinstr and newinstr2 is
executed during run time.

If CPU doesn't have feature2, but it has feature1, newinstr1 replaces oldinstr
and newinstr1 is executed during run time.

If CPU doesn't have feature2 and feature1, oldinstr is executed during run
time.

Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Link: http://lkml.kernel.org/r/1401387164-43416-5-git-send-email-fenghua.yu@intel.com
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
arch/x86/include/asm/alternative.h

index 0a3f9c9f98d5ccf446980cfcf71b7055bb79ade8..473bdbee378a10ac2030b586dc33d3be74de5a11 100644 (file)
@@ -161,6 +161,20 @@ static inline int alternatives_text_reserved(void *start, void *end)
        asm volatile (ALTERNATIVE(oldinstr, newinstr, feature)          \
                : : "i" (0), ## input)
 
+/*
+ * This is similar to alternative_input. But it has two features and
+ * respective instructions.
+ *
+ * If CPU has feature2, newinstr2 is used.
+ * Otherwise, if CPU has feature1, newinstr1 is used.
+ * Otherwise, oldinstr is used.
+ */
+#define alternative_input_2(oldinstr, newinstr1, feature1, newinstr2,       \
+                          feature2, input...)                               \
+       asm volatile(ALTERNATIVE_2(oldinstr, newinstr1, feature1,            \
+               newinstr2, feature2)                                         \
+               : : "i" (0), ## input)
+
 /* Like alternative_input, but with a single output argument */
 #define alternative_io(oldinstr, newinstr, feature, output, input...)  \
        asm volatile (ALTERNATIVE(oldinstr, newinstr, feature)          \