From a22ae9f0c579793f411e2bd7a8db557091a3a4ae Mon Sep 17 00:00:00 2001 From: Ben Avison Date: Mon, 5 Aug 2013 13:12:49 +0100 Subject: mpegts: Remove one 64-bit integer modulus operation per packet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The common case of the pointer having increased by one packet (which results in no change to the modulus) can be detected with a 64-bit subtraction, which is far cheaper than a division on many platforms. Before After Mean StdDev Mean StdDev Change Divisions 248.3 8.8 51.5 7.4 +381.7% Overall 2773.2 25.6 2372.5 43.1 +16.9% Signed-off-by: Martin Storsjö --- libavcodec/mathops.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'libavcodec/mathops.h') diff --git a/libavcodec/mathops.h b/libavcodec/mathops.h index 551017e8d9..8a2ce90d6a 100644 --- a/libavcodec/mathops.h +++ b/libavcodec/mathops.h @@ -195,6 +195,15 @@ if ((y) < (x)) {\ # define FASTDIV(a,b) ((uint32_t)((((uint64_t)a) * ff_inverse[b]) >> 32)) #endif /* FASTDIV */ +#ifndef MOD_UNLIKELY +# define MOD_UNLIKELY(modulus, dividend, divisor, prev_dividend) \ + do { \ + if ((prev_dividend) == 0 || (dividend) - (prev_dividend) != (divisor)) \ + (modulus) = (dividend) % (divisor); \ + (prev_dividend) = (dividend); \ + } while (0) +#endif + static inline av_const unsigned int ff_sqrt(unsigned int a) { unsigned int b; -- cgit v1.2.3