# HG changeset patch # User Jaroslav Hajek # Date 1264006256 -3600 # Node ID adc0143e94195fd77933b7f57f29c825f32e2c87 # Parent 9597eea7fa36fe34b2c33934c5b3bdb7608fcc63 optimize any/all (x, 2) with small number of rows diff -r 9597eea7fa36 -r adc0143e9419 liboctave/ChangeLog --- a/liboctave/ChangeLog Wed Jan 20 13:56:52 2010 +0100 +++ b/liboctave/ChangeLog Wed Jan 20 17:50:56 2010 +0100 @@ -1,3 +1,10 @@ +2010-01-20 Jaroslav Hajek + + * mx-inlines.cc (mx_inline_any_r, mx_inline_all_r): New helper + reductors. + (mx_inline_any, mx_inline_all): Call the here in row-wise reduction + with few enough columns. + 2010-01-20 Jaroslav Hajek * lo-mappers.h (xmin (double, double), xmax (double, double), diff -r 9597eea7fa36 -r adc0143e9419 liboctave/mx-inlines.cc --- a/liboctave/mx-inlines.cc Wed Jan 20 13:56:52 2010 +0100 +++ b/liboctave/mx-inlines.cc Wed Jan 20 17:50:56 2010 +0100 @@ -553,6 +553,12 @@ OP_RED_FCN2 (mx_inline_sumsq, T, T, OP_RED_SUMSQ, 0) OP_RED_FCN2 (mx_inline_sumsq, std::complex, T, OP_RED_SUMSQC, 0) +#define OP_RED_ANYR(ac, el) ac |= xis_true (el) +#define OP_RED_ALLR(ac, el) ac &= xis_true (el) + +OP_RED_FCN2 (mx_inline_any_r, T, bool, OP_RED_ANYR, false) +OP_RED_FCN2 (mx_inline_all_r, T, bool, OP_RED_ALLR, true) + // Using the general code for any/all would sacrifice short-circuiting. // OTOH, going by rows would sacrifice cache-coherence. The following algorithm // will achieve both, at the cost of a temporary octave_idx_type array. @@ -562,6 +568,9 @@ inline void \ F (const T* v, bool *r, octave_idx_type m, octave_idx_type n) \ { \ + if (n <= 8) \ + return F ## _r (v, r, m, n); \ + \ /* FIXME: it may be sub-optimal to allocate the buffer here. */ \ OCTAVE_LOCAL_BUFFER (octave_idx_type, iact, m); \ for (octave_idx_type i = 0; i < m; i++) iact[i] = i; \