linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Will Schmidt <will_schmidt@vnet.ibm.com>
To: Segher Boessenkool <segher@kernel.crashing.org>
Cc: linuxppc-dev@ozlabs.org, Paul Mackerras <paulus@samba.org>,
	segher@gate.crashing.org, arnd@arndb.de
Subject: Re: [PATCH] powerpc: emulate power5 popcntb instruction
Date: Wed, 30 Aug 2006 13:11:38 -0500	[thread overview]
Message-ID: <1156961498.5959.53.camel@localhost> (raw)
In-Reply-To: <6DCD2C4D-BB97-487D-A094-7F288970F3F3@kernel.crashing.org>

On Tue, 2006-29-08 at 08:43 +0200, Segher Boessenkool wrote:
> >> I just did a patch to fix the existing masks.
> 
> Thanks Paul.
> 
> >> Could you do a new
> >> version of this patch that doesn't include the unrelated mask fixes
> >> please?  Also it would be really nice if you could figure out a  
> >> way to
> >> avoid doing the unnecessary 64-bit logical operations on 32-bit
> >> machines - i.e. using an unsigned long for tmp, but then the  
> >> constants
> >> become problematic.  Maybe you need something like
> >>
> >> #define LCONST(x)	((unsigned long)(x##ULL))
> >
> > Ok, how about this..
> 
> Hrm.  The LCONST() thing is butt ugly though; you can just write
> 0x3333333333333333ULL etc. and GCC will do the right thing (i.e.
> efficient code), and not warn (don't need the "ULL" even when in
> C99/gnu99 mode, as we should be but aren't, heh).
> 
> You want to make tmp and unsigned long instead of an u64...

Ok, so back to unsigned-long to let the 32-bit stuff be happy..

Now a bit of a tangent question:  As far as just 64-bit is concerned, is
there actually any difference between u64 and unsigned long?   Am
wondering why you suggested that change to u64 from unsigned long
earlier in the thread.


this version looks to build clean with arch=ppc (32-bit). 

This provides emulation of the power5 instruction popcntb.

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..4014d71 100644
--- a/arch/powerpc/kernel/traps.c
+++ b/arch/powerpc/kernel/traps.c
@@ -588,6 +588,9 @@ #define INST_LSWX		0x7c00042a
 #define INST_STSWI		0x7c0005aa
 #define INST_STSWX		0x7c00052a
 
+#define INST_POPCNTB		0x7c0000f4
+#define INST_POPCNTB_MASK	0xfc0007fe
+
 static int emulate_string_inst(struct pt_regs *regs, u32 instword)
 {
 	u8 rT = (instword >> 21) & 0x1f;
@@ -656,6 +659,23 @@ static int emulate_string_inst(struct pt
 	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)
 {
 	u32 instword;
@@ -693,6 +713,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_MASK) == INST_POPCNTB) {
+		return emulate_popcntb_inst(regs, instword);
+	}
+
 	return -EINVAL;
 }
 

  reply	other threads:[~2006-08-30 18:11 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2006-08-18 19:42     ` Kumar Gala
2006-08-19 19:09       ` segher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1156961498.5959.53.camel@localhost \
    --to=will_schmidt@vnet.ibm.com \
    --cc=arnd@arndb.de \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=paulus@samba.org \
    --cc=segher@gate.crashing.org \
    --cc=segher@kernel.crashing.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).