Commit 077c4ded authored by Christophe Leroy's avatar Christophe Leroy Committed by Michael Ellerman

powerpc/inst: Refactor PPC32 and PPC64 versions

ppc_inst() ppc_inst_prefixed() ppc_inst_swab() can easily be made common
to both PPC32 and PPC64.
Signed-off-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/d54c63dcac6d190e1cc0d2fe3259d6e621928cdf.1621516826.git.christophe.leroy@csgroup.eu
parent 69d4d6e5
...@@ -60,9 +60,9 @@ static inline int ppc_inst_primary_opcode(struct ppc_inst x) ...@@ -60,9 +60,9 @@ static inline int ppc_inst_primary_opcode(struct ppc_inst x)
return ppc_inst_val(x) >> 26; return ppc_inst_val(x) >> 26;
} }
#ifdef CONFIG_PPC64
#define ppc_inst(x) ((struct ppc_inst){ .val = (x) }) #define ppc_inst(x) ((struct ppc_inst){ .val = (x) })
#ifdef CONFIG_PPC64
#define ppc_inst_prefix(x, y) ((struct ppc_inst){ .val = (x), .suffix = (y) }) #define ppc_inst_prefix(x, y) ((struct ppc_inst){ .val = (x), .suffix = (y) })
static inline u32 ppc_inst_suffix(struct ppc_inst x) static inline u32 ppc_inst_suffix(struct ppc_inst x)
...@@ -70,57 +70,34 @@ static inline u32 ppc_inst_suffix(struct ppc_inst x) ...@@ -70,57 +70,34 @@ static inline u32 ppc_inst_suffix(struct ppc_inst x)
return x.suffix; return x.suffix;
} }
static inline bool ppc_inst_prefixed(struct ppc_inst x) #else
{ #define ppc_inst_prefix(x, y) ppc_inst(x)
return ppc_inst_primary_opcode(x) == OP_PREFIX;
}
static inline struct ppc_inst ppc_inst_swab(struct ppc_inst x) static inline u32 ppc_inst_suffix(struct ppc_inst x)
{ {
return ppc_inst_prefix(swab32(ppc_inst_val(x)), swab32(ppc_inst_suffix(x))); return 0;
} }
#endif /* CONFIG_PPC64 */
static inline struct ppc_inst ppc_inst_read(const u32 *ptr) static inline struct ppc_inst ppc_inst_read(const u32 *ptr)
{ {
u32 val, suffix; if (IS_ENABLED(CONFIG_PPC64) && (*ptr >> 26) == OP_PREFIX)
return ppc_inst_prefix(*ptr, *(ptr + 1));
val = *ptr; else
if ((val >> 26) == OP_PREFIX) { return ppc_inst(*ptr);
suffix = *(ptr + 1);
return ppc_inst_prefix(val, suffix);
} else {
return ppc_inst(val);
}
} }
#else
#define ppc_inst(x) ((struct ppc_inst){ .val = x })
#define ppc_inst_prefix(x, y) ppc_inst(x)
static inline bool ppc_inst_prefixed(struct ppc_inst x) static inline bool ppc_inst_prefixed(struct ppc_inst x)
{ {
return false; return IS_ENABLED(CONFIG_PPC64) && ppc_inst_primary_opcode(x) == OP_PREFIX;
}
static inline u32 ppc_inst_suffix(struct ppc_inst x)
{
return 0;
} }
static inline struct ppc_inst ppc_inst_swab(struct ppc_inst x) static inline struct ppc_inst ppc_inst_swab(struct ppc_inst x)
{ {
return ppc_inst(swab32(ppc_inst_val(x))); return ppc_inst_prefix(swab32(ppc_inst_val(x)), swab32(ppc_inst_suffix(x)));
}
static inline struct ppc_inst ppc_inst_read(const u32 *ptr)
{
return ppc_inst(*ptr);
} }
#endif /* CONFIG_PPC64 */
static inline bool ppc_inst_equal(struct ppc_inst x, struct ppc_inst y) static inline bool ppc_inst_equal(struct ppc_inst x, struct ppc_inst y)
{ {
if (ppc_inst_val(x) != ppc_inst_val(y)) if (ppc_inst_val(x) != ppc_inst_val(y))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment