From: Sandipan Das <hidden> Date: 2018-09-03 15:19:50
This series adds emulation support for some additional ISA 3.0
instructions, most of which are now generated by a recent compiler
(e.g. gcc-8.x) when building the kernel with CONFIG_POWER9_CPU = y.
PrasannaKumar Muralidharan (1):
powerpc sstep: Add modsw, moduw instruction emulation
Sandipan Das (5):
powerpc sstep: Add maddhd, maddhdu, maddld instruction emulation
powerpc sstep: Add darn instruction emulation
powerpc sstep: Add cnttzw, cnttzd instruction emulation
powerpc sstep: Add extswsli instruction emulation
powerpc sstep: Add modsd, modud instruction emulation
arch/powerpc/lib/sstep.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 109 insertions(+), 2 deletions(-)
--
2.14.4
From: Sandipan Das <hidden> Date: 2018-09-03 15:19:53
This adds emulation support for the following integer instructions:
* Deliver A Random Number (darn)
Signed-off-by: Sandipan Das <redacted>
---
arch/powerpc/lib/sstep.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
From: Sandipan Das <hidden> Date: 2018-09-03 15:19:59
This adds emulation support for the following integer instructions:
* Extend-Sign Word and Shift Left Immediate (extswsli[.])
Signed-off-by: Sandipan Das <redacted>
---
arch/powerpc/lib/sstep.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
From: Sandipan Das <hidden> Date: 2018-09-03 15:20:01
This adds emulation support for the following integer instructions:
* Count Trailing Zeros Word (cnttzw[.])
* Count Trailing Zeros Doubleword (cnttzd[.])
Signed-off-by: Sandipan Das <redacted>
---
arch/powerpc/lib/sstep.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
From: Sandipan Das <hidden> Date: 2018-09-03 15:20:02
From: PrasannaKumar Muralidharan <redacted>
This adds emulation support for the following integer instructions:
* Modulo Signed Word (modsw)
* Modulo Unsigned Word (moduw)
Signed-off-by: PrasannaKumar Muralidharan <redacted>
Signed-off-by: Sandipan Das <redacted>
---
arch/powerpc/lib/sstep.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
From: Sandipan Das <hidden> Date: 2018-09-03 15:20:04
This adds emulation support for the following integer instructions:
* Modulo Signed Doubleword (modsd)
* Modulo Unsigned Doubleword (modud)
Signed-off-by: Sandipan Das <redacted>
---
arch/powerpc/lib/sstep.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
The mod instruction has special cases that aren't handled by this C code,
too (divide by 0, or signed division of the most negative number by -1).
For the mod intruction the behaviour is undefined in those cases, but you
probably should force some specific behaviour. You don't want the kernel
to execute a trap instruction, etc. :-)
Segher
If running maddhd does not work, will running it in kernel mode work?
I think you should *actually* emulate it.
(Same for the next patch, "darn", but emulation of that is much more
interesting).
Segher
From: Paul Mackerras <hidden> Date: 2018-09-05 06:36:57
On Tue, Sep 04, 2018 at 04:12:07PM -0500, Segher Boessenkool wrote:
On Mon, Sep 03, 2018 at 08:49:35PM +0530, Sandipan Das wrote:
quoted
+ case 538: /* cnttzw */
+ if (!cpu_has_feature(CPU_FTR_ARCH_300))
+ return -1;
+ val = (unsigned int) regs->gpr[rd];
+ op->val = ( val ? __builtin_ctz(val) : 32 );
+ goto logical_done;
+#ifdef __powerpc64__
+ case 570: /* cnttzd */
+ if (!cpu_has_feature(CPU_FTR_ARCH_300))
+ return -1;
+ val = regs->gpr[rd];
+ op->val = ( val ? __builtin_ctzl(val) : 64 );
+ goto logical_done;
__builtin_ctz(val) is undefined for val == 0.
Which would be why he only calls it when val != 0, presumably, and
uses 64 when val == 0. Apart from idiosyncratic whitespace his code
looks correct to me.
Are you saying there is a bug in his code, or that his patch
description is incomplete, or what?
Paul.
If running maddhd does not work, will running it in kernel mode work?
Not sure what you meant here but one of the scenarios that I'm aware of
where this is will be used is if we place a probe at a location having
an maddhd instruction. The kernel would first attempt to emulate its
behaviour, which in this case is done by executing the same instruction
(similar to what is done for mulhd and mulhw) and if that fails, try to
execute the instruction natively.
- Sandipan
The mod instruction has special cases that aren't handled by this C code,
too (divide by 0, or signed division of the most negative number by -1).
For the mod intruction the behaviour is undefined in those cases, but you
probably should force some specific behaviour. You don't want the kernel
to execute a trap instruction, etc. :-)
Agreed. In that case, the same would apply to the divw, divwu, divd and divdu
instructions as well, right? Cause I don't see these cases being handled for
them currently.
Also, if I execute a modulo or division instruction for any of these special
cases in a userspace binary, I don't see any exceptions being generated. It's
just that the result is undefined (usually same as one of the source operands,
I don't remember if it was the dividend or the divisor). So, I'm wondering if
this would be necessary.
- Sandipan
From: Michael Ellerman <mpe@ellerman.id.au> Date: 2019-02-20 00:52:25
Sandipan Das [off-list ref] writes:
This adds emulation support for the following integer instructions:
* Deliver A Random Number (darn)
This doesn't build with old binutils. We need to support old binutils.
{standard input}:4343: Error: Unrecognized opcode: `darn'
You need to use PPC_DARN().
cheers
From: Michael Ellerman <mpe@ellerman.id.au> Date: 2019-02-20 00:53:56
Sandipan Das [off-list ref] writes:
This adds emulation support for the following integer instructions:
* Multiply-Add High Doubleword (maddhd)
* Multiply-Add High Doubleword Unsigned (maddhdu)
* Multiply-Add Low Doubleword (maddld)
This doesn't build with old binutils.
{standard input}:2089: Error: Unrecognized opcode: `maddld'
{standard input}:2104: Error: Unrecognized opcode: `maddhdu'
{standard input}:1141: Error: Unrecognized opcode: `maddhd'
You'll need to add hand built versions, see ppc-opcode.h for examples.
cheers
From: Sandipan Das <hidden> Date: 2019-02-20 09:51:33
Hi Michael,
On 20/02/19 6:20 AM, Michael Ellerman wrote:
Sandipan Das [off-list ref] writes:
quoted
This adds emulation support for the following integer instructions:
* Deliver A Random Number (darn)
This doesn't build with old binutils. We need to support old binutils.
{standard input}:4343: Error: Unrecognized opcode: `darn'
You need to use PPC_DARN().
cheers
[...]
Thanks for pointing these out. Will post v2 with the required changes.
- Sandipan