From 24796333680e03884b77595c386cc2d6f2aa4f62 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Thu, 12 Mar 2026 05:31:00 +0000 Subject: util/spkmodem-recv: optimise pulse check the last change was good, but this code, again, has to do these calculations 48,000 times a second. trivial on new computers. but now try it on a computer from 1992. we should try to make this as fast as possible :) older compilers especially don't optimise these checks. this patch shifts it to one subtraction and one unsigned comparison, rather than checking less than or greater than both. often used in... literally exactly this type of program. on a good compiler this will compile to an add, cmp and conditional jump. less readable, but the results (set 1 or 0) make it pretty obvious what it does, after a few seconds. Signed-off-by: Leah Rowe --- util/spkmodem_recv/spkmodem-recv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'util') diff --git a/util/spkmodem_recv/spkmodem-recv.c b/util/spkmodem_recv/spkmodem-recv.c index d448c84b..238c10b2 100644 --- a/util/spkmodem_recv/spkmodem-recv.c +++ b/util/spkmodem_recv/spkmodem-recv.c @@ -174,8 +174,8 @@ decode_pulse(struct decoder_state *st) st->frame[st->ringpos] = read_sample(st); - if (st->frame[st->ringpos] > THRESHOLD || - st->frame[st->ringpos] < -THRESHOLD) + if ((unsigned)(st->frame[st->ringpos] + THRESHOLD) + > (unsigned)(2 * THRESHOLD)) new_pulse = 1; else new_pulse = 0; -- cgit v1.2.1