Skip to content

Commit 26fb4b9

Browse files
jones-drewpalmer-dabbelt
authored andcommitted
riscv: Don't duplicate _ALTERNATIVE_CFG* macros
Reduce clutter by only defining the _ALTERNATIVE_CFG* macros once, rather than once for assembly and once for C. To do that, we need to add __ALTERNATIVE_CFG* macros to the assembly side, but those are one-liners. Also take the opportunity to do a bit of reformatting, taking full advantage of the fact checkpatch gives us 100 char lines. Signed-off-by: Andrew Jones <[email protected]> Tested-by: Lad Prabhakar <[email protected]> Acked-by: Conor Dooley <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent bb2efcd commit 26fb4b9

File tree

1 file changed

+17
-36
lines changed

1 file changed

+17
-36
lines changed

arch/riscv/include/asm/alternative-macros.h

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,14 @@
4444
ALT_NEW_CONTENT \vendor_id, \errata_id, \enable, \new_c
4545
.endm
4646

47-
#define _ALTERNATIVE_CFG(old_c, new_c, vendor_id, errata_id, CONFIG_k) \
48-
ALTERNATIVE_CFG old_c, new_c, vendor_id, errata_id, IS_ENABLED(CONFIG_k)
49-
5047
.macro ALTERNATIVE_CFG_2 old_c, new_c_1, vendor_id_1, errata_id_1, enable_1, \
5148
new_c_2, vendor_id_2, errata_id_2, enable_2
5249
ALTERNATIVE_CFG \old_c, \new_c_1, \vendor_id_1, \errata_id_1, \enable_1
5350
ALT_NEW_CONTENT \vendor_id_2, \errata_id_2, \enable_2, \new_c_2
5451
.endm
5552

56-
#define _ALTERNATIVE_CFG_2(old_c, new_c_1, vendor_id_1, errata_id_1, \
57-
CONFIG_k_1, \
58-
new_c_2, vendor_id_2, errata_id_2, \
59-
CONFIG_k_2) \
60-
ALTERNATIVE_CFG_2 old_c, new_c_1, vendor_id_1, errata_id_1, \
61-
IS_ENABLED(CONFIG_k_1), \
62-
new_c_2, vendor_id_2, errata_id_2, \
63-
IS_ENABLED(CONFIG_k_2)
53+
#define __ALTERNATIVE_CFG(...) ALTERNATIVE_CFG __VA_ARGS__
54+
#define __ALTERNATIVE_CFG_2(...) ALTERNATIVE_CFG_2 __VA_ARGS__
6455

6556
#else /* !__ASSEMBLY__ */
6657

@@ -102,27 +93,21 @@
10293
"887 :\n" \
10394
ALT_NEW_CONTENT(vendor_id, errata_id, enable, new_c)
10495

105-
#define _ALTERNATIVE_CFG(old_c, new_c, vendor_id, errata_id, CONFIG_k) \
106-
__ALTERNATIVE_CFG(old_c, new_c, vendor_id, errata_id, IS_ENABLED(CONFIG_k))
107-
108-
#define __ALTERNATIVE_CFG_2(old_c, new_c_1, vendor_id_1, errata_id_1, \
109-
enable_1, \
110-
new_c_2, vendor_id_2, errata_id_2, \
111-
enable_2) \
112-
__ALTERNATIVE_CFG(old_c, new_c_1, vendor_id_1, errata_id_1, enable_1) \
96+
#define __ALTERNATIVE_CFG_2(old_c, new_c_1, vendor_id_1, errata_id_1, enable_1, \
97+
new_c_2, vendor_id_2, errata_id_2, enable_2) \
98+
__ALTERNATIVE_CFG(old_c, new_c_1, vendor_id_1, errata_id_1, enable_1) \
11399
ALT_NEW_CONTENT(vendor_id_2, errata_id_2, enable_2, new_c_2)
114100

115-
#define _ALTERNATIVE_CFG_2(old_c, new_c_1, vendor_id_1, errata_id_1, \
116-
CONFIG_k_1, \
117-
new_c_2, vendor_id_2, errata_id_2, \
118-
CONFIG_k_2) \
119-
__ALTERNATIVE_CFG_2(old_c, new_c_1, vendor_id_1, errata_id_1, \
120-
IS_ENABLED(CONFIG_k_1), \
121-
new_c_2, vendor_id_2, errata_id_2, \
122-
IS_ENABLED(CONFIG_k_2))
123-
124101
#endif /* __ASSEMBLY__ */
125102

103+
#define _ALTERNATIVE_CFG(old_c, new_c, vendor_id, errata_id, CONFIG_k) \
104+
__ALTERNATIVE_CFG(old_c, new_c, vendor_id, errata_id, IS_ENABLED(CONFIG_k))
105+
106+
#define _ALTERNATIVE_CFG_2(old_c, new_c_1, vendor_id_1, errata_id_1, CONFIG_k_1, \
107+
new_c_2, vendor_id_2, errata_id_2, CONFIG_k_2) \
108+
__ALTERNATIVE_CFG_2(old_c, new_c_1, vendor_id_1, errata_id_1, IS_ENABLED(CONFIG_k_1), \
109+
new_c_2, vendor_id_2, errata_id_2, IS_ENABLED(CONFIG_k_2))
110+
126111
#else /* CONFIG_RISCV_ALTERNATIVE */
127112
#ifdef __ASSEMBLY__
128113

@@ -173,13 +158,9 @@
173158
* on the following sample code and then replace ALTERNATIVE() with
174159
* ALTERNATIVE_2() to append its customized content.
175160
*/
176-
#define ALTERNATIVE_2(old_content, new_content_1, vendor_id_1, \
177-
errata_id_1, CONFIG_k_1, \
178-
new_content_2, vendor_id_2, \
179-
errata_id_2, CONFIG_k_2) \
180-
_ALTERNATIVE_CFG_2(old_content, new_content_1, vendor_id_1, \
181-
errata_id_1, CONFIG_k_1, \
182-
new_content_2, vendor_id_2, \
183-
errata_id_2, CONFIG_k_2)
161+
#define ALTERNATIVE_2(old_content, new_content_1, vendor_id_1, errata_id_1, CONFIG_k_1, \
162+
new_content_2, vendor_id_2, errata_id_2, CONFIG_k_2) \
163+
_ALTERNATIVE_CFG_2(old_content, new_content_1, vendor_id_1, errata_id_1, CONFIG_k_1, \
164+
new_content_2, vendor_id_2, errata_id_2, CONFIG_k_2)
184165

185166
#endif

0 commit comments

Comments
 (0)