linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 1/5] powerpc/lib/sstep: Add cmpb instruction emulation
@ 2017-07-31  0:58 Matt Brown
  2017-07-31  0:58 ` [PATCH v4 2/5] powerpc/lib/sstep: Add popcnt " Matt Brown
                   ` (6 more replies)
  0 siblings, 7 replies; 13+ messages in thread
From: Matt Brown @ 2017-07-31  0:58 UTC (permalink / raw)
  To: linuxppc-dev

This patch adds emulation of the cmpb instruction, enabling xmon to
emulate this instruction.
Tested for correctness against the cmpb asm instruction on ppc64le.

Signed-off-by: Matt Brown <matthew.brown.dev@gmail.com>
---
v2: 
	- fixed opcode
	- fixed mask typecasting
---
 arch/powerpc/lib/sstep.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c
index 33117f8..87d277f 100644
--- a/arch/powerpc/lib/sstep.c
+++ b/arch/powerpc/lib/sstep.c
@@ -596,6 +596,22 @@ static nokprobe_inline void do_cmp_unsigned(struct pt_regs *regs, unsigned long
 	regs->ccr = (regs->ccr & ~(0xf << shift)) | (crval << shift);
 }
 
+static nokprobe_inline void do_cmpb(struct pt_regs *regs, unsigned long v1,
+				unsigned long v2, int rd)
+{
+	unsigned long long out_val, mask;
+	int i;
+
+	out_val = 0;
+	for (i = 0; i < 8; i++) {
+		mask = 0xffUL << (i * 8);
+		if ((v1 & mask) == (v2 & mask))
+			out_val |= mask;
+	}
+
+	regs->gpr[rd] = out_val;
+}
+
 static nokprobe_inline int trap_compare(long v1, long v2)
 {
 	int ret = 0;
@@ -1049,6 +1065,10 @@ int analyse_instr(struct instruction_op *op, struct pt_regs *regs,
 			do_cmp_unsigned(regs, val, val2, rd >> 2);
 			goto instr_done;
 
+		case 508: /* cmpb */
+			do_cmpb(regs, regs->gpr[rd], regs->gpr[rb], ra);
+			goto instr_done;
+
 /*
  * Arithmetic instructions
  */
-- 
2.9.3

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

* [PATCH v4 2/5] powerpc/lib/sstep: Add popcnt instruction emulation
  2017-07-31  0:58 [PATCH v4 1/5] powerpc/lib/sstep: Add cmpb instruction emulation Matt Brown
@ 2017-07-31  0:58 ` Matt Brown
  2017-07-31  4:15   ` Cyril Bur
  2017-07-31  0:58 ` [PATCH v4 3/5] powerpc/lib/sstep: Add bpermd " Matt Brown
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 13+ messages in thread
From: Matt Brown @ 2017-07-31  0:58 UTC (permalink / raw)
  To: linuxppc-dev

This adds emulations for the popcntb, popcntw, and popcntd instructions.
Tested for correctness against the popcnt{b,w,d} instructions on ppc64le.

Signed-off-by: Matt Brown <matthew.brown.dev@gmail.com>
---
v4:
	- change ifdef macro from __powerpc64__ to CONFIG_PPC64
	- slight optimisations 
	(now identical to the popcntb implementation in kernel/traps.c)
v3:
	- optimised using the Giles-Miller method of side-ways addition
v2:
	- fixed opcodes
	- fixed typecasting
	- fixed bitshifting error for both 32 and 64bit arch
---
 arch/powerpc/lib/sstep.c | 42 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c
index 87d277f..2fd7377 100644
--- a/arch/powerpc/lib/sstep.c
+++ b/arch/powerpc/lib/sstep.c
@@ -612,6 +612,34 @@ static nokprobe_inline void do_cmpb(struct pt_regs *regs, unsigned long v1,
 	regs->gpr[rd] = out_val;
 }
 
+/*
+ * The size parameter is used to adjust the equivalent popcnt instruction.
+ * popcntb = 8, popcntw = 32, popcntd = 64
+ */
+static nokprobe_inline void do_popcnt(struct pt_regs *regs, unsigned long v1,
+				int size, int ra)
+{
+	unsigned long long out = v1;
+
+	out -= (out >> 1) & 0x5555555555555555;
+	out = (0x3333333333333333 & out) + (0x3333333333333333 & (out >> 2));
+	out = (out + (out >> 4)) & 0x0f0f0f0f0f0f0f0f;
+
+	if (size == 8) {	/* popcntb */
+		regs->gpr[ra] = out;
+		return;
+	}
+	out += out >> 8;
+	out += out >> 16;
+	if (size == 32) {	/* popcntw */
+		regs->gpr[ra] = out & 0x0000003f0000003f;
+		return;
+	}
+
+	out = (out + (out >> 32)) & 0x7f;
+	regs->gpr[ra] = out;	/* popcntd */
+}
+
 static nokprobe_inline int trap_compare(long v1, long v2)
 {
 	int ret = 0;
@@ -1194,6 +1222,10 @@ int analyse_instr(struct instruction_op *op, struct pt_regs *regs,
 			regs->gpr[ra] = regs->gpr[rd] & ~regs->gpr[rb];
 			goto logical_done;
 
+		case 122:	/* popcntb */
+			do_popcnt(regs, regs->gpr[rd], 8, ra);
+			goto logical_done;
+
 		case 124:	/* nor */
 			regs->gpr[ra] = ~(regs->gpr[rd] | regs->gpr[rb]);
 			goto logical_done;
@@ -1206,6 +1238,10 @@ int analyse_instr(struct instruction_op *op, struct pt_regs *regs,
 			regs->gpr[ra] = regs->gpr[rd] ^ regs->gpr[rb];
 			goto logical_done;
 
+		case 378:	/* popcntw */
+			do_popcnt(regs, regs->gpr[rd], 32, ra);
+			goto logical_done;
+
 		case 412:	/* orc */
 			regs->gpr[ra] = regs->gpr[rd] | ~regs->gpr[rb];
 			goto logical_done;
@@ -1217,7 +1253,11 @@ int analyse_instr(struct instruction_op *op, struct pt_regs *regs,
 		case 476:	/* nand */
 			regs->gpr[ra] = ~(regs->gpr[rd] & regs->gpr[rb]);
 			goto logical_done;
-
+#ifdef CONFIG_PPC64
+		case 506:	/* popcntd */
+			do_popcnt(regs, regs->gpr[rd], 64, ra);
+			goto logical_done;
+#endif
 		case 922:	/* extsh */
 			regs->gpr[ra] = (signed short) regs->gpr[rd];
 			goto logical_done;
-- 
2.9.3

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

* [PATCH v4 3/5] powerpc/lib/sstep: Add bpermd instruction emulation
  2017-07-31  0:58 [PATCH v4 1/5] powerpc/lib/sstep: Add cmpb instruction emulation Matt Brown
  2017-07-31  0:58 ` [PATCH v4 2/5] powerpc/lib/sstep: Add popcnt " Matt Brown
@ 2017-07-31  0:58 ` Matt Brown
  2017-07-31  3:42   ` Cyril Bur
  2017-07-31  0:58 ` [PATCH v4 4/5] powerpc/lib/sstep: Add prty " Matt Brown
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 13+ messages in thread
From: Matt Brown @ 2017-07-31  0:58 UTC (permalink / raw)
  To: linuxppc-dev

This adds emulation for the bpermd instruction.
Tested for correctness against the bpermd instruction on ppc64le.

Signed-off-by: Matt Brown <matthew.brown.dev@gmail.com>
---
v4:
	- change ifdef macro from __powerpc64__ to CONFIG_PPC64
v2:
	- fixed opcode
	- added ifdef tags to do_bpermd func
	- fixed bitshifting errors
---
 arch/powerpc/lib/sstep.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c
index 2fd7377..c9fd613 100644
--- a/arch/powerpc/lib/sstep.c
+++ b/arch/powerpc/lib/sstep.c
@@ -640,6 +640,24 @@ static nokprobe_inline void do_popcnt(struct pt_regs *regs, unsigned long v1,
 	regs->gpr[ra] = out;	/* popcntd */
 }
 
+#ifdef CONFIG_PPC64
+static nokprobe_inline void do_bpermd(struct pt_regs *regs, unsigned long v1,
+				unsigned long v2, int ra)
+{
+	unsigned char perm, idx;
+	unsigned int i;
+
+	perm = 0;
+	for (i = 0; i < 8; i++) {
+		idx = (v1 >> (i * 8)) & 0xff;
+		if (idx < 64)
+			if (v2 & PPC_BIT(idx))
+				perm |= 1 << i;
+	}
+	regs->gpr[ra] = perm;
+}
+#endif /* CONFIG_PPC64 */
+
 static nokprobe_inline int trap_compare(long v1, long v2)
 {
 	int ret = 0;
@@ -1229,7 +1247,11 @@ int analyse_instr(struct instruction_op *op, struct pt_regs *regs,
 		case 124:	/* nor */
 			regs->gpr[ra] = ~(regs->gpr[rd] | regs->gpr[rb]);
 			goto logical_done;
-
+#ifdef CONFIG_PPC64
+		case 252:	/* bpermd */
+			do_bpermd(regs, regs->gpr[rd], regs->gpr[rb], ra);
+			goto logical_done;
+#endif
 		case 284:	/* xor */
 			regs->gpr[ra] = ~(regs->gpr[rd] ^ regs->gpr[rb]);
 			goto logical_done;
-- 
2.9.3

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

* [PATCH v4 4/5] powerpc/lib/sstep: Add prty instruction emulation
  2017-07-31  0:58 [PATCH v4 1/5] powerpc/lib/sstep: Add cmpb instruction emulation Matt Brown
  2017-07-31  0:58 ` [PATCH v4 2/5] powerpc/lib/sstep: Add popcnt " Matt Brown
  2017-07-31  0:58 ` [PATCH v4 3/5] powerpc/lib/sstep: Add bpermd " Matt Brown
@ 2017-07-31  0:58 ` Matt Brown
  2017-07-31  3:55   ` Cyril Bur
  2017-07-31  0:58 ` [PATCH v4 5/5] powerpc/lib/sstep: Add isel " Matt Brown
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 13+ messages in thread
From: Matt Brown @ 2017-07-31  0:58 UTC (permalink / raw)
  To: linuxppc-dev

This adds emulation for the prtyw and prtyd instructions.
Tested for logical correctness against the prtyw and prtyd instructions
on ppc64le.

Signed-off-by: Matt Brown <matthew.brown.dev@gmail.com>
---
v4:
	- use simpler xor method
v3:
	- optimised using the Giles-Miller method of side-ways addition
v2:
	- fixed opcodes
	- fixed bitshifting and typecast errors
	- merged do_prtyw and do_prtyd into single function
---
 arch/powerpc/lib/sstep.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c
index c9fd613..af4eef9 100644
--- a/arch/powerpc/lib/sstep.c
+++ b/arch/powerpc/lib/sstep.c
@@ -657,6 +657,24 @@ static nokprobe_inline void do_bpermd(struct pt_regs *regs, unsigned long v1,
 	regs->gpr[ra] = perm;
 }
 #endif /* CONFIG_PPC64 */
+/*
+ * The size parameter adjusts the equivalent prty instruction.
+ * prtyw = 32, prtyd = 64
+ */
+static nokprobe_inline void do_prty(struct pt_regs *regs, unsigned long v,
+				int size, int ra)
+{
+	unsigned long long res = v ^ (v >> 8);
+
+	res ^= res >> 16;
+	if (size == 32) {		/* prtyw */
+		regs->gpr[ra] = res & 0x0000000100000001;
+		return;
+	}
+
+	res ^= res >> 32;
+	regs->gpr[ra] = res & 1;	/*prtyd */
+}
 
 static nokprobe_inline int trap_compare(long v1, long v2)
 {
@@ -1247,6 +1265,14 @@ int analyse_instr(struct instruction_op *op, struct pt_regs *regs,
 		case 124:	/* nor */
 			regs->gpr[ra] = ~(regs->gpr[rd] | regs->gpr[rb]);
 			goto logical_done;
+
+		case 154:	/* prtyw */
+			do_prty(regs, regs->gpr[rd], 32, ra);
+			goto logical_done;
+
+		case 186:	/* prtyd */
+			do_prty(regs, regs->gpr[rd], 64, ra);
+			goto logical_done;
 #ifdef CONFIG_PPC64
 		case 252:	/* bpermd */
 			do_bpermd(regs, regs->gpr[rd], regs->gpr[rb], ra);
-- 
2.9.3

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

* [PATCH v4 5/5] powerpc/lib/sstep: Add isel instruction emulation
  2017-07-31  0:58 [PATCH v4 1/5] powerpc/lib/sstep: Add cmpb instruction emulation Matt Brown
                   ` (2 preceding siblings ...)
  2017-07-31  0:58 ` [PATCH v4 4/5] powerpc/lib/sstep: Add prty " Matt Brown
@ 2017-07-31  0:58 ` Matt Brown
  2017-07-31  4:11   ` Cyril Bur
  2017-07-31  1:42 ` [PATCH v4 1/5] powerpc/lib/sstep: Add cmpb " Cyril Bur
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 13+ messages in thread
From: Matt Brown @ 2017-07-31  0:58 UTC (permalink / raw)
  To: linuxppc-dev

This adds emulation for the isel instruction.
Tested for correctness against the isel instruction and its extended
mnemonics (lt, gt, eq) on ppc64le.

Signed-off-by: Matt Brown <matthew.brown.dev@gmail.com>
---
v4:
	- simplify if statement to ternary op
	(same as isel emulation in kernel/traps.c)
v2:
	- fixed opcode
	- fixed definition to include the 'if RA=0, a=0' clause
	- fixed ccr bitshifting error
---
 arch/powerpc/lib/sstep.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c
index af4eef9..473bab5 100644
--- a/arch/powerpc/lib/sstep.c
+++ b/arch/powerpc/lib/sstep.c
@@ -1240,6 +1240,14 @@ int analyse_instr(struct instruction_op *op, struct pt_regs *regs,
 /*
  * Logical instructions
  */
+		case 15:	/* isel */
+			mb = (instr >> 6) & 0x1f; /* bc */
+			val = (regs->ccr >> (31 - mb)) & 1;
+			val2 = (ra) ? regs->gpr[ra] : 0;
+
+			regs->gpr[rd] = (val) ? val2 : regs->gpr[rb];
+			goto logical_done;
+
 		case 26:	/* cntlzw */
 			asm("cntlzw %0,%1" : "=r" (regs->gpr[ra]) :
 			    "r" (regs->gpr[rd]));
-- 
2.9.3

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

* Re: [PATCH v4 1/5] powerpc/lib/sstep: Add cmpb instruction emulation
  2017-07-31  0:58 [PATCH v4 1/5] powerpc/lib/sstep: Add cmpb instruction emulation Matt Brown
                   ` (3 preceding siblings ...)
  2017-07-31  0:58 ` [PATCH v4 5/5] powerpc/lib/sstep: Add isel " Matt Brown
@ 2017-07-31  1:42 ` Cyril Bur
  2017-08-01 12:44 ` Segher Boessenkool
  2017-08-11 12:19 ` [v4,1/5] " Michael Ellerman
  6 siblings, 0 replies; 13+ messages in thread
From: Cyril Bur @ 2017-07-31  1:42 UTC (permalink / raw)
  To: Matt Brown, linuxppc-dev

On Mon, 2017-07-31 at 10:58 +1000, Matt Brown wrote:
> This patch adds emulation of the cmpb instruction, enabling xmon to
> emulate this instruction.
> Tested for correctness against the cmpb asm instruction on ppc64le.
> 
> Signed-off-by: Matt Brown <matthew.brown.dev@gmail.com>

Reviewed-by: Cyril Bur <cyrilbur@gmail.com>

> ---
> v2: 
> 	- fixed opcode
> 	- fixed mask typecasting
> ---
>  arch/powerpc/lib/sstep.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c
> index 33117f8..87d277f 100644
> --- a/arch/powerpc/lib/sstep.c
> +++ b/arch/powerpc/lib/sstep.c
> @@ -596,6 +596,22 @@ static nokprobe_inline void do_cmp_unsigned(struct pt_regs *regs, unsigned long
>  	regs->ccr = (regs->ccr & ~(0xf << shift)) | (crval << shift);
>  }
>  
> +static nokprobe_inline void do_cmpb(struct pt_regs *regs, unsigned long v1,
> +				unsigned long v2, int rd)
> +{
> +	unsigned long long out_val, mask;
> +	int i;
> +
> +	out_val = 0;
> +	for (i = 0; i < 8; i++) {
> +		mask = 0xffUL << (i * 8);
> +		if ((v1 & mask) == (v2 & mask))
> +			out_val |= mask;
> +	}
> +
> +	regs->gpr[rd] = out_val;
> +}
> +
>  static nokprobe_inline int trap_compare(long v1, long v2)
>  {
>  	int ret = 0;
> @@ -1049,6 +1065,10 @@ int analyse_instr(struct instruction_op *op, struct pt_regs *regs,
>  			do_cmp_unsigned(regs, val, val2, rd >> 2);
>  			goto instr_done;
>  
> +		case 508: /* cmpb */
> +			do_cmpb(regs, regs->gpr[rd], regs->gpr[rb], ra);
> +			goto instr_done;
> +
>  /*
>   * Arithmetic instructions
>   */

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

* Re: [PATCH v4 3/5] powerpc/lib/sstep: Add bpermd instruction emulation
  2017-07-31  0:58 ` [PATCH v4 3/5] powerpc/lib/sstep: Add bpermd " Matt Brown
@ 2017-07-31  3:42   ` Cyril Bur
  0 siblings, 0 replies; 13+ messages in thread
From: Cyril Bur @ 2017-07-31  3:42 UTC (permalink / raw)
  To: Matt Brown, linuxppc-dev

On Mon, 2017-07-31 at 10:58 +1000, Matt Brown wrote:
> This adds emulation for the bpermd instruction.
> Tested for correctness against the bpermd instruction on ppc64le.
> 
> Signed-off-by: Matt Brown <matthew.brown.dev@gmail.com>

Reviewed-by: Cyril Bur <cyrilbur@gmail.com>

> ---
> v4:
> 	- change ifdef macro from __powerpc64__ to CONFIG_PPC64
> v2:
> 	- fixed opcode
> 	- added ifdef tags to do_bpermd func
> 	- fixed bitshifting errors
> ---
>  arch/powerpc/lib/sstep.c | 24 +++++++++++++++++++++++-
>  1 file changed, 23 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c
> index 2fd7377..c9fd613 100644
> --- a/arch/powerpc/lib/sstep.c
> +++ b/arch/powerpc/lib/sstep.c
> @@ -640,6 +640,24 @@ static nokprobe_inline void do_popcnt(struct pt_regs *regs, unsigned long v1,
>  	regs->gpr[ra] = out;	/* popcntd */
>  }
>  
> +#ifdef CONFIG_PPC64
> +static nokprobe_inline void do_bpermd(struct pt_regs *regs, unsigned long v1,
> +				unsigned long v2, int ra)
> +{
> +	unsigned char perm, idx;
> +	unsigned int i;
> +
> +	perm = 0;
> +	for (i = 0; i < 8; i++) {
> +		idx = (v1 >> (i * 8)) & 0xff;
> +		if (idx < 64)
> +			if (v2 & PPC_BIT(idx))
> +				perm |= 1 << i;
> +	}
> +	regs->gpr[ra] = perm;
> +}
> +#endif /* CONFIG_PPC64 */
> +
>  static nokprobe_inline int trap_compare(long v1, long v2)
>  {
>  	int ret = 0;
> @@ -1229,7 +1247,11 @@ int analyse_instr(struct instruction_op *op, struct pt_regs *regs,
>  		case 124:	/* nor */
>  			regs->gpr[ra] = ~(regs->gpr[rd] | regs->gpr[rb]);
>  			goto logical_done;
> -
> +#ifdef CONFIG_PPC64
> +		case 252:	/* bpermd */
> +			do_bpermd(regs, regs->gpr[rd], regs->gpr[rb], ra);
> +			goto logical_done;
> +#endif
>  		case 284:	/* xor */
>  			regs->gpr[ra] = ~(regs->gpr[rd] ^ regs->gpr[rb]);
>  			goto logical_done;

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

* Re: [PATCH v4 4/5] powerpc/lib/sstep: Add prty instruction emulation
  2017-07-31  0:58 ` [PATCH v4 4/5] powerpc/lib/sstep: Add prty " Matt Brown
@ 2017-07-31  3:55   ` Cyril Bur
  0 siblings, 0 replies; 13+ messages in thread
From: Cyril Bur @ 2017-07-31  3:55 UTC (permalink / raw)
  To: Matt Brown, linuxppc-dev

On Mon, 2017-07-31 at 10:58 +1000, Matt Brown wrote:
> This adds emulation for the prtyw and prtyd instructions.
> Tested for logical correctness against the prtyw and prtyd instructions
> on ppc64le.
> 
> Signed-off-by: Matt Brown <matthew.brown.dev@gmail.com>

Reviewed-by: Cyril Bur <cyrilbur@gmail.com>

> ---
> v4:
> 	- use simpler xor method
> v3:
> 	- optimised using the Giles-Miller method of side-ways addition
> v2:
> 	- fixed opcodes
> 	- fixed bitshifting and typecast errors
> 	- merged do_prtyw and do_prtyd into single function
> ---
>  arch/powerpc/lib/sstep.c | 26 ++++++++++++++++++++++++++
>  1 file changed, 26 insertions(+)
> 
> diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c
> index c9fd613..af4eef9 100644
> --- a/arch/powerpc/lib/sstep.c
> +++ b/arch/powerpc/lib/sstep.c
> @@ -657,6 +657,24 @@ static nokprobe_inline void do_bpermd(struct pt_regs *regs, unsigned long v1,
>  	regs->gpr[ra] = perm;
>  }
>  #endif /* CONFIG_PPC64 */
> +/*
> + * The size parameter adjusts the equivalent prty instruction.
> + * prtyw = 32, prtyd = 64
> + */
> +static nokprobe_inline void do_prty(struct pt_regs *regs, unsigned long v,
> +				int size, int ra)
> +{
> +	unsigned long long res = v ^ (v >> 8);
> +
> +	res ^= res >> 16;
> +	if (size == 32) {		/* prtyw */
> +		regs->gpr[ra] = res & 0x0000000100000001;
> +		return;
> +	}
> +
> +	res ^= res >> 32;
> +	regs->gpr[ra] = res & 1;	/*prtyd */
> +}
>  
>  static nokprobe_inline int trap_compare(long v1, long v2)
>  {
> @@ -1247,6 +1265,14 @@ int analyse_instr(struct instruction_op *op, struct pt_regs *regs,
>  		case 124:	/* nor */
>  			regs->gpr[ra] = ~(regs->gpr[rd] | regs->gpr[rb]);
>  			goto logical_done;
> +
> +		case 154:	/* prtyw */
> +			do_prty(regs, regs->gpr[rd], 32, ra);
> +			goto logical_done;
> +
> +		case 186:	/* prtyd */
> +			do_prty(regs, regs->gpr[rd], 64, ra);
> +			goto logical_done;
>  #ifdef CONFIG_PPC64
>  		case 252:	/* bpermd */
>  			do_bpermd(regs, regs->gpr[rd], regs->gpr[rb], ra);

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

* Re: [PATCH v4 5/5] powerpc/lib/sstep: Add isel instruction emulation
  2017-07-31  0:58 ` [PATCH v4 5/5] powerpc/lib/sstep: Add isel " Matt Brown
@ 2017-07-31  4:11   ` Cyril Bur
  0 siblings, 0 replies; 13+ messages in thread
From: Cyril Bur @ 2017-07-31  4:11 UTC (permalink / raw)
  To: Matt Brown, linuxppc-dev

On Mon, 2017-07-31 at 10:58 +1000, Matt Brown wrote:
> This adds emulation for the isel instruction.
> Tested for correctness against the isel instruction and its extended
> mnemonics (lt, gt, eq) on ppc64le.
> 
> Signed-off-by: Matt Brown <matthew.brown.dev@gmail.com>

Reviewed-by: Cyril Bur <cyrilbur@gmail.com>

> ---
> v4:
> 	- simplify if statement to ternary op
> 	(same as isel emulation in kernel/traps.c)
> v2:
> 	- fixed opcode
> 	- fixed definition to include the 'if RA=0, a=0' clause
> 	- fixed ccr bitshifting error
> ---
>  arch/powerpc/lib/sstep.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c
> index af4eef9..473bab5 100644
> --- a/arch/powerpc/lib/sstep.c
> +++ b/arch/powerpc/lib/sstep.c
> @@ -1240,6 +1240,14 @@ int analyse_instr(struct instruction_op *op, struct pt_regs *regs,
>  /*
>   * Logical instructions
>   */
> +		case 15:	/* isel */
> +			mb = (instr >> 6) & 0x1f; /* bc */
> +			val = (regs->ccr >> (31 - mb)) & 1;
> +			val2 = (ra) ? regs->gpr[ra] : 0;
> +
> +			regs->gpr[rd] = (val) ? val2 : regs->gpr[rb];
> +			goto logical_done;
> +
>  		case 26:	/* cntlzw */
>  			asm("cntlzw %0,%1" : "=r" (regs->gpr[ra]) :
>  			    "r" (regs->gpr[rd]));

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

* Re: [PATCH v4 2/5] powerpc/lib/sstep: Add popcnt instruction emulation
  2017-07-31  0:58 ` [PATCH v4 2/5] powerpc/lib/sstep: Add popcnt " Matt Brown
@ 2017-07-31  4:15   ` Cyril Bur
  0 siblings, 0 replies; 13+ messages in thread
From: Cyril Bur @ 2017-07-31  4:15 UTC (permalink / raw)
  To: Matt Brown, linuxppc-dev

On Mon, 2017-07-31 at 10:58 +1000, Matt Brown wrote:
> This adds emulations for the popcntb, popcntw, and popcntd instructions.
> Tested for correctness against the popcnt{b,w,d} instructions on ppc64le.
> 
> Signed-off-by: Matt Brown <matthew.brown.dev@gmail.com>

Unlike the rest of this series, it isn't immediately clear that it is
correct, we're definitely on the other side of the optimisation vs
readability line. It looks like it is, perhaps some comments to
clarify.

Otherwise,

Reviewed-by: Cyril Bur <cyrilbur@gmail.com>

> ---
> v4:
> 	- change ifdef macro from __powerpc64__ to CONFIG_PPC64
> 	- slight optimisations 
> 	(now identical to the popcntb implementation in kernel/traps.c)
> v3:
> 	- optimised using the Giles-Miller method of side-ways addition
> v2:
> 	- fixed opcodes
> 	- fixed typecasting
> 	- fixed bitshifting error for both 32 and 64bit arch
> ---
>  arch/powerpc/lib/sstep.c | 42 +++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 41 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c
> index 87d277f..2fd7377 100644
> --- a/arch/powerpc/lib/sstep.c
> +++ b/arch/powerpc/lib/sstep.c
> @@ -612,6 +612,34 @@ static nokprobe_inline void do_cmpb(struct pt_regs *regs, unsigned long v1,
>  	regs->gpr[rd] = out_val;
>  }
>  
> +/*
> + * The size parameter is used to adjust the equivalent popcnt instruction.
> + * popcntb = 8, popcntw = 32, popcntd = 64
> + */
> +static nokprobe_inline void do_popcnt(struct pt_regs *regs, unsigned long v1,
> +				int size, int ra)
> +{
> +	unsigned long long out = v1;
> +
> +	out -= (out >> 1) & 0x5555555555555555;
> +	out = (0x3333333333333333 & out) + (0x3333333333333333 & (out >> 2));
> +	out = (out + (out >> 4)) & 0x0f0f0f0f0f0f0f0f;
> +
> +	if (size == 8) {	/* popcntb */
> +		regs->gpr[ra] = out;
> +		return;
> +	}
> +	out += out >> 8;
> +	out += out >> 16;
> +	if (size == 32) {	/* popcntw */
> +		regs->gpr[ra] = out & 0x0000003f0000003f;
> +		return;
> +	}
> +
> +	out = (out + (out >> 32)) & 0x7f;
> +	regs->gpr[ra] = out;	/* popcntd */
> +}
> +
>  static nokprobe_inline int trap_compare(long v1, long v2)
>  {
>  	int ret = 0;
> @@ -1194,6 +1222,10 @@ int analyse_instr(struct instruction_op *op, struct pt_regs *regs,
>  			regs->gpr[ra] = regs->gpr[rd] & ~regs->gpr[rb];
>  			goto logical_done;
>  
> +		case 122:	/* popcntb */
> +			do_popcnt(regs, regs->gpr[rd], 8, ra);
> +			goto logical_done;
> +
>  		case 124:	/* nor */
>  			regs->gpr[ra] = ~(regs->gpr[rd] | regs->gpr[rb]);
>  			goto logical_done;
> @@ -1206,6 +1238,10 @@ int analyse_instr(struct instruction_op *op, struct pt_regs *regs,
>  			regs->gpr[ra] = regs->gpr[rd] ^ regs->gpr[rb];
>  			goto logical_done;
>  
> +		case 378:	/* popcntw */
> +			do_popcnt(regs, regs->gpr[rd], 32, ra);
> +			goto logical_done;
> +
>  		case 412:	/* orc */
>  			regs->gpr[ra] = regs->gpr[rd] | ~regs->gpr[rb];
>  			goto logical_done;
> @@ -1217,7 +1253,11 @@ int analyse_instr(struct instruction_op *op, struct pt_regs *regs,
>  		case 476:	/* nand */
>  			regs->gpr[ra] = ~(regs->gpr[rd] & regs->gpr[rb]);
>  			goto logical_done;
> -
> +#ifdef CONFIG_PPC64
> +		case 506:	/* popcntd */
> +			do_popcnt(regs, regs->gpr[rd], 64, ra);
> +			goto logical_done;
> +#endif
>  		case 922:	/* extsh */
>  			regs->gpr[ra] = (signed short) regs->gpr[rd];
>  			goto logical_done;

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

* Re: [PATCH v4 1/5] powerpc/lib/sstep: Add cmpb instruction emulation
  2017-07-31  0:58 [PATCH v4 1/5] powerpc/lib/sstep: Add cmpb instruction emulation Matt Brown
                   ` (4 preceding siblings ...)
  2017-07-31  1:42 ` [PATCH v4 1/5] powerpc/lib/sstep: Add cmpb " Cyril Bur
@ 2017-08-01 12:44 ` Segher Boessenkool
  2017-08-02  1:23   ` Matt Brown
  2017-08-11 12:19 ` [v4,1/5] " Michael Ellerman
  6 siblings, 1 reply; 13+ messages in thread
From: Segher Boessenkool @ 2017-08-01 12:44 UTC (permalink / raw)
  To: Matt Brown; +Cc: linuxppc-dev

Hi!

On Mon, Jul 31, 2017 at 10:58:22AM +1000, Matt Brown wrote:
> @@ -1049,6 +1065,10 @@ int analyse_instr(struct instruction_op *op, struct pt_regs *regs,
>  			do_cmp_unsigned(regs, val, val2, rd >> 2);
>  			goto instr_done;
>  
> +		case 508: /* cmpb */
> +			do_cmpb(regs, regs->gpr[rd], regs->gpr[rb], ra);
> +			goto instr_done;

Should this then be under an ifdef for 64-bit?


Segher

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

* Re: [PATCH v4 1/5] powerpc/lib/sstep: Add cmpb instruction emulation
  2017-08-01 12:44 ` Segher Boessenkool
@ 2017-08-02  1:23   ` Matt Brown
  0 siblings, 0 replies; 13+ messages in thread
From: Matt Brown @ 2017-08-02  1:23 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: open list:LINUX FOR POWERPC (32-BIT AND 64-BIT)

On Tue, Aug 1, 2017 at 10:44 PM, Segher Boessenkool
<segher@kernel.crashing.org> wrote:
> Hi!
>
> On Mon, Jul 31, 2017 at 10:58:22AM +1000, Matt Brown wrote:
>> @@ -1049,6 +1065,10 @@ int analyse_instr(struct instruction_op *op, struct pt_regs *regs,
>>                       do_cmp_unsigned(regs, val, val2, rd >> 2);
>>                       goto instr_done;
>>
>> +             case 508: /* cmpb */
>> +                     do_cmpb(regs, regs->gpr[rd], regs->gpr[rb], ra);
>> +                     goto instr_done;
>
> Should this then be under an ifdef for 64-bit?

I don't think so, the cmpb instruction should be 32 and 64-bit.
It isn't listed under the '64-bit Fixed-point Logical Instructions'
section in the ISA either.

Thanks,
Matt
>
>
> Segher

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

* Re: [v4,1/5] powerpc/lib/sstep: Add cmpb instruction emulation
  2017-07-31  0:58 [PATCH v4 1/5] powerpc/lib/sstep: Add cmpb instruction emulation Matt Brown
                   ` (5 preceding siblings ...)
  2017-08-01 12:44 ` Segher Boessenkool
@ 2017-08-11 12:19 ` Michael Ellerman
  6 siblings, 0 replies; 13+ messages in thread
From: Michael Ellerman @ 2017-08-11 12:19 UTC (permalink / raw)
  To: Matt Brown, linuxppc-dev

On Mon, 2017-07-31 at 00:58:22 UTC, Matt Brown wrote:
> This patch adds emulation of the cmpb instruction, enabling xmon to
> emulate this instruction.
> Tested for correctness against the cmpb asm instruction on ppc64le.
> 
> Signed-off-by: Matt Brown <matthew.brown.dev@gmail.com>
> Reviewed-by: Cyril Bur <cyrilbur@gmail.com>

Series applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/02c0f62a60b67d6c9bfe9429cbe3aa

cheers

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

end of thread, other threads:[~2017-08-11 12:19 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-31  0:58 [PATCH v4 1/5] powerpc/lib/sstep: Add cmpb instruction emulation Matt Brown
2017-07-31  0:58 ` [PATCH v4 2/5] powerpc/lib/sstep: Add popcnt " Matt Brown
2017-07-31  4:15   ` Cyril Bur
2017-07-31  0:58 ` [PATCH v4 3/5] powerpc/lib/sstep: Add bpermd " Matt Brown
2017-07-31  3:42   ` Cyril Bur
2017-07-31  0:58 ` [PATCH v4 4/5] powerpc/lib/sstep: Add prty " Matt Brown
2017-07-31  3:55   ` Cyril Bur
2017-07-31  0:58 ` [PATCH v4 5/5] powerpc/lib/sstep: Add isel " Matt Brown
2017-07-31  4:11   ` Cyril Bur
2017-07-31  1:42 ` [PATCH v4 1/5] powerpc/lib/sstep: Add cmpb " Cyril Bur
2017-08-01 12:44 ` Segher Boessenkool
2017-08-02  1:23   ` Matt Brown
2017-08-11 12:19 ` [v4,1/5] " Michael Ellerman

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).