Mercurial > octave-nkf
diff liboctave/mx-inlines.cc @ 10147:adc0143e9419
optimize any/all (x, 2) with small number of rows
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 20 Jan 2010 17:50:56 +0100 |
parents | 9597eea7fa36 |
children | 4c0cdbe0acca |
line wrap: on
line diff
--- 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>, 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; \