aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSandipan Das <sandipan@linux.vnet.ibm.com>2017-10-10 02:45:30 -0400
committerMichael Ellerman <mpe@ellerman.id.au>2017-10-10 05:16:32 -0400
commitb0490a04e736356e427e227902b17f9927a56caf (patch)
treedc96af57600fdc47d874e933103265e4dff79233
parente36a82ee4c514a2f4f8fa30c780ad059282f5d64 (diff)
powerpc/lib/sstep: Fix count leading zeros instructions
According to the GCC documentation, the behaviour of __builtin_clz() and __builtin_clzl() is undefined if the value of the input argument is zero. Without handling this special case, these builtins have been used for emulating the following instructions: * Count Leading Zeros Word (cntlzw[.]) * Count Leading Zeros Doubleword (cntlzd[.]) This fixes the emulated behaviour of these instructions by adding an additional check for this special case. Fixes: 3cdfcbfd32b9d ("powerpc: Change analyse_instr so it doesn't modify *regs") Signed-off-by: Sandipan Das <sandipan@linux.vnet.ibm.com> Reviewed-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
-rw-r--r--arch/powerpc/lib/sstep.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c
index 5e8418c28bd8..f208f560aecd 100644
--- a/arch/powerpc/lib/sstep.c
+++ b/arch/powerpc/lib/sstep.c
@@ -1684,11 +1684,13 @@ int analyse_instr(struct instruction_op *op, const struct pt_regs *regs,
1684 * Logical instructions 1684 * Logical instructions
1685 */ 1685 */
1686 case 26: /* cntlzw */ 1686 case 26: /* cntlzw */
1687 op->val = __builtin_clz((unsigned int) regs->gpr[rd]); 1687 val = (unsigned int) regs->gpr[rd];
1688 op->val = ( val ? __builtin_clz(val) : 32 );
1688 goto logical_done; 1689 goto logical_done;
1689#ifdef __powerpc64__ 1690#ifdef __powerpc64__
1690 case 58: /* cntlzd */ 1691 case 58: /* cntlzd */
1691 op->val = __builtin_clzl(regs->gpr[rd]); 1692 val = regs->gpr[rd];
1693 op->val = ( val ? __builtin_clzl(val) : 64 );
1692 goto logical_done; 1694 goto logical_done;
1693#endif 1695#endif
1694 case 28: /* and */ 1696 case 28: /* and */