Page MenuHomePhabricator

[PowerPC] vectorize Sum of Absolute Difference

Authored by inouehrs on Apr 25 2018, 7:52 PM.



This patch enables vectorization of Sum of Absolute Difference (SAD), which is already supported in x86 backend.
For example, the following code is compiled with vector max/min and sum-across instructions.

uint8_t *pix1, *pix2;
unsigned i_sum = 0;
for( unsigned x = 0; x < 16; x++ )
  i_sum += abs( pix1[x] - pix2[x] );

To implement this, I moved some helper functions defined in X86TargetLowering into the parent class TargetLowering with minor generalization to reuse them from PPC backend.
Is this an acceptable approach or is it better to implement analysis as DAG combining (and introduce a new Opcode like ISD::SAD)?

This patch supports only ppc64le so far. If accepted, I will add big endian support and also POWER9 new instruction support.

Diff Detail

Event Timeline

inouehrs created this revision.Apr 25 2018, 7:52 PM
RKSimon added a subscriber: RKSimon.
RKSimon added inline comments.

In a more general setting we probably need to support ABS(SUB(ZEXT(x)), ZEXT(y))) as well


This (and the comment) needs updating for PPC, maybe merge the 2 ifs to just:

if (VT != MVT::v16i8 && VT != MVT::v8i16)
  return SDValue();

How come PPC doesn't use the ISD::SMAX/SMIN/UMAX/UMIN opcodes? It'd remove a lot of this duplication.


Why not use utils/ ?

@inouehrs Are you still looking at this at all?

inouehrs abandoned this revision.Sep 29 2018, 9:16 AM

@RKSimon Other colleagues in IBM are working on this and hopefully they will submit a patch separately. So I abandone this.
Thank you so much for your comments.