From 54936a45a573ce6bd6876086300461f50948efb9 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Thu, 12 Mar 2026 04:39:00 +0000 Subject: util/spkmodem-recv: don't use modulus on decode it's slow on older compilers/systems that don't optimise. instead, we branch (cheaper) and just do an above or equal comparison), resetting appropriately or subtracting. should yield an actually useful performance gain, on older systems. a bit theoretical on modern systems, which optimise well (modern compilers will produce assembly code much like what the new C code is doing) Signed-off-by: Leah Rowe --- util/spkmodem_recv/spkmodem-recv.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'util') diff --git a/util/spkmodem_recv/spkmodem-recv.c b/util/spkmodem_recv/spkmodem-recv.c index 504121ab..e141caa4 100644 --- a/util/spkmodem_recv/spkmodem-recv.c +++ b/util/spkmodem_recv/spkmodem-recv.c @@ -142,7 +142,9 @@ decode_pulse(struct decoder_state *st) size_t n; int next; - next = (st->ringpos + SAMPLES_PER_FRAME) % MAX_SAMPLES; + next = st->ringpos + SAMPLES_PER_FRAME; + if (next >= MAX_SAMPLES) + next -= MAX_SAMPLES; st->freq_data -= st->pulse[st->ringpos]; st->freq_data += st->pulse[next]; @@ -155,14 +157,15 @@ decode_pulse(struct decoder_state *st) err(errno, "stdin read"); } - if (abs(st->frame[st->ringpos]) > THRESHOLD) - st->pulse[st->ringpos] = 1; - else - st->pulse[st->ringpos] = 0; + st->pulse[st->ringpos] = + abs(st->frame[st->ringpos]) > THRESHOLD; st->freq_separator += st->pulse[st->ringpos]; - st->ringpos = (st->ringpos + 1) % MAX_SAMPLES; + st->ringpos++; + if (st->ringpos >= MAX_SAMPLES) + st->ringpos = 0; + st->sample_count++; } -- cgit v1.2.1