From 944df89d7a6253b9077eec1655449e74b16f1418 Mon Sep 17 00:00:00 2001 From: andreas128 Date: Mon, 21 Aug 2017 20:00:19 +0200 Subject: Increase MemlessPoly efficiency --- src/MemlessPoly.cpp | 56 ++++++++++------------------------------------------- 1 file changed, 10 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/src/MemlessPoly.cpp b/src/MemlessPoly.cpp index ba603cb..25a0a23 100644 --- a/src/MemlessPoly.cpp +++ b/src/MemlessPoly.cpp @@ -129,52 +129,16 @@ static void apply_coeff( const complexf *__restrict in, size_t start, size_t stop, complexf *__restrict out) { - for (size_t i = start; i < stop; i+=2) { - - /* Implement - a1*x + a3*x*|x|^2 + a5*x*|x|^4 + a5*x*|x|^4 + a5*x*|x|^4 + a7*x*|x|^6 - with less multiplications: - a0 + x*(a1 + x*(a2 + x*(a3 + x*(a3 + x*(a4 + a5*x))))); - */ - - /* Make sure to adapt NUM_COEFS when you change this */ - - // Complex polynomial, all operations are on complex values. - // Usually this is the representation we use when speaking - // about the real-valued passband signal that the PA receives. - float in_1_mag = std::abs(in[i]); - float in_1_2 = in_1_mag * in_1_mag; - float in_1_4 = in_1_2 * in_1_2; - float in_1_6 = in_1_2 * in_1_4; - float in_1_8 = in_1_4 * in_1_4; - float in_1_10 = in_1_6 * in_1_4; - - float in_2_mag = std::abs(in[i+1]); - float in_2_2 = in_2_mag * in_2_mag; - float in_2_4 = in_2_2 * in_2_2; - float in_2_6 = in_2_2 * in_2_4; - float in_2_8 = in_2_4 * in_2_4; - float in_2_10 = in_2_6 * in_2_4; - - out[i+0] = in[i+0] * - ( - coefs[0] + - coefs[1] * in_1_2 + - coefs[2] * in_1_4 + - coefs[3] * in_1_6 + - coefs[4] * in_1_8 + - coefs[5] * in_1_10 - ); - - out[i+1] = in[i+1] * - ( - coefs[0] + - coefs[1] * in_2_2 + - coefs[2] * in_2_4 + - coefs[3] * in_2_6 + - coefs[4] * in_2_8 + - coefs[5] * in_2_10 - ); + for (size_t i = start; i < stop; i+=1) { + + float in_mag_sq = in[i].real() * in[i].real() + in[i].imag() * in[i].imag(); + out[i] = + in[i] * + ( coefs[0] + in_mag_sq * + ( coefs[1] + in_mag_sq * + ( coefs[2] + in_mag_sq * + ( coefs[3] + in_mag_sq * + ( coefs[4] + in_mag_sq ))))); } } -- cgit v1.2.3