Commit c3412dcb authored by Will Schmidt's avatar Will Schmidt Committed by Paul Mackerras

[POWERPC] Emulate power5 popcntb instruction

In an attempt to make it easier for a power5 optimized app to run on a
power4 or a 970 or random earlier machine, this provides emulation of
the popcntb instruction.
Signed-off-by: default avatarWill Schmidt <will_schmidt@vnet.ibm.com>
Signed-off-by: default avatarPaul Mackerras <paulus@samba.org>
parent f50d4cfc
...@@ -598,6 +598,9 @@ static void parse_fpe(struct pt_regs *regs) ...@@ -598,6 +598,9 @@ static void parse_fpe(struct pt_regs *regs)
#define INST_STSWI 0x7c0005aa #define INST_STSWI 0x7c0005aa
#define INST_STSWX 0x7c00052a #define INST_STSWX 0x7c00052a
#define INST_POPCNTB 0x7c0000f4
#define INST_POPCNTB_MASK 0xfc0007fe
static int emulate_string_inst(struct pt_regs *regs, u32 instword) static int emulate_string_inst(struct pt_regs *regs, u32 instword)
{ {
u8 rT = (instword >> 21) & 0x1f; u8 rT = (instword >> 21) & 0x1f;
...@@ -666,6 +669,23 @@ static int emulate_string_inst(struct pt_regs *regs, u32 instword) ...@@ -666,6 +669,23 @@ static int emulate_string_inst(struct pt_regs *regs, u32 instword)
return 0; return 0;
} }
static int emulate_popcntb_inst(struct pt_regs *regs, u32 instword)
{
u32 ra,rs;
unsigned long tmp;
ra = (instword >> 16) & 0x1f;
rs = (instword >> 21) & 0x1f;
tmp = regs->gpr[rs];
tmp = tmp - ((tmp >> 1) & 0x5555555555555555ULL);
tmp = (tmp & 0x3333333333333333ULL) + ((tmp >> 2) & 0x3333333333333333ULL);
tmp = (tmp + (tmp >> 4)) & 0x0f0f0f0f0f0f0f0fULL;
regs->gpr[ra] = tmp;
return 0;
}
static int emulate_instruction(struct pt_regs *regs) static int emulate_instruction(struct pt_regs *regs)
{ {
u32 instword; u32 instword;
...@@ -703,6 +723,11 @@ static int emulate_instruction(struct pt_regs *regs) ...@@ -703,6 +723,11 @@ static int emulate_instruction(struct pt_regs *regs)
if ((instword & INST_STRING_GEN_MASK) == INST_STRING) if ((instword & INST_STRING_GEN_MASK) == INST_STRING)
return emulate_string_inst(regs, instword); return emulate_string_inst(regs, instword);
/* Emulate the popcntb (Population Count Bytes) instruction. */
if ((instword & INST_POPCNTB_MASK) == INST_POPCNTB) {
return emulate_popcntb_inst(regs, instword);
}
return -EINVAL; return -EINVAL;
} }
......
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