From 43dfec07c92149ba71743c893d231a7efd3c25d2 Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Mon, 16 Feb 2015 13:38:11 +1300 Subject: [PATCH] Cleanup DotProduct function to make it more readable. --- Source/Core/AudioCommon/DPL2Decoder.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Source/Core/AudioCommon/DPL2Decoder.cpp b/Source/Core/AudioCommon/DPL2Decoder.cpp index ca7afc9afa..355d721e15 100644 --- a/Source/Core/AudioCommon/DPL2Decoder.cpp +++ b/Source/Core/AudioCommon/DPL2Decoder.cpp @@ -39,21 +39,25 @@ static float *filter_coefs_lfe; static unsigned int len125; template -static _ftype_t DotProduct(int count,const T *buf,const _ftype_t *coefficients) +static _ftype_t DotProduct(int count, const T *buf, const _ftype_t *coefficients) { - float sum0=0,sum1=0,sum2=0,sum3=0; - for (;count>=4;buf+=4,coefficients+=4,count-=4) + int i; + float sum0 = 0.0f, sum1 = 0.0f, sum2 = 0.0f, sum3 = 0.0f; + + // Unrolled loop + for (i = 0; (i + 3) < count; i += 4) { - sum0+=buf[0]*coefficients[0]; - sum1+=buf[1]*coefficients[1]; - sum2+=buf[2]*coefficients[2]; - sum3+=buf[3]*coefficients[3]; + sum0 += buf[i + 0] * coefficients[i + 0]; + sum1 += buf[i + 1] * coefficients[i + 1]; + sum2 += buf[i + 2] * coefficients[i + 2]; + sum3 += buf[i + 3] * coefficients[i + 3]; } - while (count--) - sum0+=*buf++**coefficients++; + // Epilogue of unrolled loop + for (; i < count; i++) + sum0 += buf[i] * coefficients[i]; - return sum0+sum1+sum2+sum3; + return sum0 + sum1 + sum2 + sum3; } template