From d19d4ebc873a9381a68247eda181009ad765c4ca Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Hamal=20Dvo=C5=99=C3=A1k?= <mordae@anilinux.org>
Date: Sat, 27 Jan 2024 12:57:19 +0100
Subject: [PATCH] Optimize mixer using XOR
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Jan Hamal Dvořák <mordae@anilinux.org>
---
 src/main.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/main.c b/src/main.c
index 1e4da78..5c6fa6d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -486,8 +486,8 @@ static void rf_rx(void)
 			pos = (pos + 1) & (LO_WORDS - 1);
 
 #if SPEED == 3
-			I += popcount(rx_word & cos_word) - popcount(rx_word & ~cos_word);
-			Q += popcount(rx_word & sin_word) - popcount(rx_word & ~sin_word);
+			I += popcount(rx_word ^ cos_word);
+			Q += popcount(rx_word ^ sin_word);
 #elif SPEED == 2
 			interp0->accum[0] = rx_word;
 			interp0->accum[1] = rx_word;
@@ -546,6 +546,9 @@ static void rf_rx(void)
 #endif
 		}
 
+		I -= 16 * NUM_SAMPLES;
+		Q -= 16 * NUM_SAMPLES;
+
 #if EXTRA_BITS
 		I <<= EXTRA_BITS;
 		Q <<= EXTRA_BITS;