aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/kernel/traps.c
diff options
context:
space:
mode:
authorWill Schmidt <will_schmidt@vnet.ibm.com>2006-08-30 14:11:38 -0400
committerPaul Mackerras <paulus@samba.org>2006-09-13 04:39:52 -0400
commitc3412dcb75ff4d64b44bedc72761d5707d19edf7 (patch)
tree3e893de720ce5aca6a3e6471cd6ef0fcbcb62281 /arch/powerpc/kernel/traps.c
parentf50d4cfc98d70f919afb2924b1b53c36b2f4e62f (diff)
[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: Will Schmidt <will_schmidt@vnet.ibm.com> Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/powerpc/kernel/traps.c')
-rw-r--r--arch/powerpc/kernel/traps.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
index 9b352bd0a460..d9f10f2fc372 100644
--- a/arch/powerpc/kernel/traps.c
+++ b/arch/powerpc/kernel/traps.c
@@ -598,6 +598,9 @@ static void parse_fpe(struct pt_regs *regs)
598#define INST_STSWI 0x7c0005aa 598#define INST_STSWI 0x7c0005aa
599#define INST_STSWX 0x7c00052a 599#define INST_STSWX 0x7c00052a
600 600
601#define INST_POPCNTB 0x7c0000f4
602#define INST_POPCNTB_MASK 0xfc0007fe
603
601static int emulate_string_inst(struct pt_regs *regs, u32 instword) 604static int emulate_string_inst(struct pt_regs *regs, u32 instword)
602{ 605{
603 u8 rT = (instword >> 21) & 0x1f; 606 u8 rT = (instword >> 21) & 0x1f;
@@ -666,6 +669,23 @@ static int emulate_string_inst(struct pt_regs *regs, u32 instword)
666 return 0; 669 return 0;
667} 670}
668 671
672static int emulate_popcntb_inst(struct pt_regs *regs, u32 instword)
673{
674 u32 ra,rs;
675 unsigned long tmp;
676
677 ra = (instword >> 16) & 0x1f;
678 rs = (instword >> 21) & 0x1f;
679
680 tmp = regs->gpr[rs];
681 tmp = tmp - ((tmp >> 1) & 0x5555555555555555ULL);
682 tmp = (tmp & 0x3333333333333333ULL) + ((tmp >> 2) & 0x3333333333333333ULL);
683 tmp = (tmp + (tmp >> 4)) & 0x0f0f0f0f0f0f0f0fULL;
684 regs->gpr[ra] = tmp;
685
686 return 0;
687}
688
669static int emulate_instruction(struct pt_regs *regs) 689static int emulate_instruction(struct pt_regs *regs)
670{ 690{
671 u32 instword; 691 u32 instword;
@@ -703,6 +723,11 @@ static int emulate_instruction(struct pt_regs *regs)
703 if ((instword & INST_STRING_GEN_MASK) == INST_STRING) 723 if ((instword & INST_STRING_GEN_MASK) == INST_STRING)
704 return emulate_string_inst(regs, instword); 724 return emulate_string_inst(regs, instword);
705 725
726 /* Emulate the popcntb (Population Count Bytes) instruction. */
727 if ((instword & INST_POPCNTB_MASK) == INST_POPCNTB) {
728 return emulate_popcntb_inst(regs, instword);
729 }
730
706 return -EINVAL; 731 return -EINVAL;
707} 732}
708 733