From: Will Schmidt <hidden> Date: 2006-08-17 18:54:14
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 <redacted>
---
x in, x out:
x -= (x >> 1) & 0x5555555555555555;
x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333);
x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f;
(Your code only runs on 4 bytes; shouldn't it be 8?)
Segher
From: Will Schmidt <hidden> Date: 2006-08-18 18:11:53
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. Rewritten to use a slicker algorithm as
suggested by Segher. I left a 'tmp' variable in play, as it seemed
cleaner to use tmp than referring to regs->gpr[rs] and [ra] multiple
times within the magic algorithm.
Also tested on power4 with both 32 and 64 userspace this time.
*blush*. :-)
Signed-off-by: Will Schmidt <redacted>
---
Is that the right check? The other similar traps check against a
mask of 0x7c0007fe.
I agree with Arnd here, its better to check with a larger mask to
ensure that bits that should be '0' in the minor opcode are.
For example, if you had an instruction that was 0x7c0000f7 it would
match.
- kumar
This is going to give warnings on ppc32 kernel compiles, maybe
something like:
(unsigned long) 0x5555555555555555ull
Nah, just make "tmp" an u64. And/or don't do this emulation on
32-bit machines at all.
And if the compiler warns about the non-qualified constants --
well, we should compile with -std=gnu99 anyway, eh?
Segher
Is that the right check? The other similar traps check against a
mask of 0x7c0007fe.
I hope you mean 0xfc0007fe?
No, the code in question is
#define INST_MFSPR_PVR········0x7c1f42a6
#define INST_MFSPR_PVR_MASK····0xfc1fffff
#define INST_DCBA·············0x7c0005ec
#define INST_DCBA_MASK········0x7c0007fe
#define INST_MCRXR············0x7c000400
#define INST_MCRXR_MASK·······0x7c0007fe
#define INST_STRING···········0x7c00042a
#define INST_STRING_MASK·······0x7c0007fe
#define INST_STRING_GEN_MASK···0x7c00067e
#define INST_LSWI·············0x7c0004aa
#define INST_LSWX·············0x7c00042a
#define INST_STSWI············0x7c0005aa
#define INST_STSWX············0x7c00052a
What does the MSB do in our instructions?
Bits 0..5 are the primary opcode, for all insns;
bits 21..30 are the secondary opcode, for insns that
have one (all in primary opcode 31 do).
So we have a bug here; could you take care of it please
Arnd?
Segher
From: Will Schmidt <hidden> Date: 2006-08-21 20:10:04
On Sat, 2006-19-08 at 18:32 -0500, segher@gate.crashing.org wrote:
quoted
quoted
quoted
Is that the right check? The other similar traps check against a
mask of 0x7c0007fe.
So we have a bug here; could you take care of it please
Arnd?
I'm not Arnd :-) , but since I'm poking at it anyways,.. how about
this?
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.
This version incorporates the suggestions from Arnd, Kumar and Segher;
including using a better MASK for popcntb, updating the existing masks
to include the msb for the instruction primary opcode.
Signed-off-by: Will Schmidt <redacted>
From: Paul Mackerras <hidden> Date: 2006-08-24 06:36:07
Will Schmidt writes:
I'm not Arnd :-) , but since I'm poking at it anyways,.. how about
this?
I just did a patch to fix the existing masks. 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))
Thanks,
Paul.
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
Like I asked before -- should we run this emulation on 32-bit
machines at all? The instruction only exists in the 64-bit
architecture after all.
Segher
From: Paul Mackerras <hidden> Date: 2006-08-25 12:57:28
Segher Boessenkool writes:
Like I asked before -- should we run this emulation on 32-bit
machines at all? The instruction only exists in the 64-bit
architecture after all.
It could be argued either way, but on the whole I would prefer to
minimize the number of things which could cause a 32-bit program that
runs quite happily on a 64-bit CPU to fail on a 32-bit CPU...
Paul.
On Thu, 2006-24-08 at 16:36 +1000, Paul Mackerras wrote:
Will Schmidt writes:
I just did a patch to fix the existing masks. 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..
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 <redacted>
---
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...
Segher
From: Will Schmidt <hidden> Date: 2006-08-30 18:11:51
On Tue, 2006-29-08 at 08:43 +0200, Segher Boessenkool wrote:
quoted
quoted
I just did a patch to fix the existing masks.
Thanks Paul.
quoted
quoted
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 <redacted>
---