linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] powerpc: emulate power5 popcntb instruction
@ 2006-08-17 18:53 Will Schmidt
  2006-08-17 19:24 ` Segher Boessenkool
  0 siblings, 1 reply; 18+ messages in thread
From: Will Schmidt @ 2006-08-17 18:53 UTC (permalink / raw)
  To: linuxppc-dev, Paul Mackerras


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. 

tested on power4 and 970.  

Signed-off-by: Will Schmidt <will_schmidt@vnet.ibm.com>

---

diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
index 2105767..3e5ed30 100644
--- a/arch/powerpc/kernel/traps.c
+++ b/arch/powerpc/kernel/traps.c
@@ -588,6 +588,8 @@ #define INST_LSWX		0x7c00042a
 #define INST_STSWI		0x7c0005aa
 #define INST_STSWX		0x7c00052a
 
+#define INST_POPCNTB		0x7c0000f4
+
 static int emulate_string_inst(struct pt_regs *regs, u32 instword)
 {
 	u8 rT = (instword >> 21) & 0x1f;
@@ -656,6 +658,26 @@ static int emulate_string_inst(struct pt
 	return 0;
 }
 
+static int emulate_popcntb_inst(struct pt_regs *regs, u32 instword)
+{
+	u32 ra,rs;
+	u32 countreg,tmp;
+	u32 x,y;
+
+	ra = (instword >> 16) & 0x1f;
+	rs = (instword >> 21) & 0x1f;
+	countreg = regs->gpr[rs];
+	regs->gpr[ra] = 0;
+
+	/* y=4 bytes, x=8 bits/byte */
+	for (y = 0; y < 4; y++) {
+		for (tmp = 0, x = 0; x < 8; x++)
+			if (countreg & (0x1 << (x + 8 * y))) tmp++;
+		regs->gpr[ra] += (tmp <<  8 * y );
+	}
+	return 0;
+}
+
 static int emulate_instruction(struct pt_regs *regs)
 {
 	u32 instword;
@@ -693,6 +715,11 @@ static int emulate_instruction(struct pt
 	if ((instword & INST_STRING_GEN_MASK) == INST_STRING)
 		return emulate_string_inst(regs, instword);
 
+	/* Emulate the popcntb (Population Count Bytes) instruction. */
+	if ((instword & INST_POPCNTB) == INST_POPCNTB) {
+		return emulate_popcntb_inst(regs, instword);
+	}
+
 	return -EINVAL;
 }
 

^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2006-08-30 18:11 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-17 18:53 [PATCH] powerpc: emulate power5 popcntb instruction Will Schmidt
2006-08-17 19:24 ` Segher Boessenkool
2006-08-18 18:11   ` Will Schmidt
2006-08-18 19:05     ` Arnd Bergmann
2006-08-18 19:30       ` Kumar Gala
2006-08-19 19:10       ` segher
2006-08-19 20:19         ` Arnd Bergmann
2006-08-19 23:32           ` segher
2006-08-21 20:09             ` Will Schmidt
2006-08-24  6:36               ` Paul Mackerras
2006-08-24 15:53                 ` Segher Boessenkool
2006-08-25  9:59                   ` Gabriel Paubert
2006-08-25 12:57                   ` Paul Mackerras
2006-08-28 18:03                 ` Willschm
2006-08-29  6:43                   ` Segher Boessenkool
2006-08-30 18:11                     ` Will Schmidt
2006-08-18 19:42     ` Kumar Gala
2006-08-19 19:09       ` segher

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).