diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-12 04:44:44 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-12 04:44:44 +0000 |
| commit | 44c6b453bc3c59961008956fbf221899bac2991c (patch) | |
| tree | 6462e4e57c94bf29feb0e7a4da4d6da67a65219f | |
| parent | 54936a45a573ce6bd6876086300461f50948efb9 (diff) | |
util/spkmodem-recv: optimise ring buffer pos calc
instead of computing next every time, just advance
two indexes. another performance optimisation on
older machines, especially old compilers, because
it reduces the amount of logical branching.
the old code was pretty much just advancing two
indexes in lockstep, when getting the next pulse,
but recalculating one of them based on the other,
each time.
this is yet another hangover from the old GNU code
that i forked three years ago.
Signed-off-by: Leah Rowe <leah@libreboot.org>
| -rw-r--r-- | util/spkmodem_recv/spkmodem-recv.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/util/spkmodem_recv/spkmodem-recv.c b/util/spkmodem_recv/spkmodem-recv.c index e141caa4..58275979 100644 --- a/util/spkmodem_recv/spkmodem-recv.c +++ b/util/spkmodem_recv/spkmodem-recv.c @@ -41,6 +41,8 @@ struct decoder_state { unsigned char pulse[MAX_SAMPLES]; int ringpos; + int sep_pos; + int freq_data; int freq_separator; int sample_count; @@ -89,6 +91,9 @@ main(int argc, char **argv) memset(&st, 0, sizeof(st)); st.ascii_bit = 7; + st.ringpos = 0; + st.sep_pos = SAMPLES_PER_FRAME; + argv0 = argv[0]; while (1) { @@ -140,15 +145,10 @@ static void decode_pulse(struct decoder_state *st) { size_t n; - int next; - - 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]; - st->freq_separator -= st->pulse[next]; + st->freq_data += st->pulse[st->sep_pos]; + st->freq_separator -= st->pulse[st->sep_pos]; n = fread(&st->frame[st->ringpos], sizeof(st->frame[0]), 1, stdin); if (n != 1) { @@ -166,6 +166,10 @@ decode_pulse(struct decoder_state *st) if (st->ringpos >= MAX_SAMPLES) st->ringpos = 0; + st->sep_pos++; + if (st->sep_pos >= MAX_SAMPLES) + st->sep_pos = 0; + st->sample_count++; } |
