# Optimizing the Goertzel Algorithm

**URL:** <https://ziggit.dev/t/optimizing-the-goertzel-algorithm/16233>\
**Category:** Help\
**Tags:** performance\
**Created:** [June 18, 2026, 12:33am UTC](https://ziggit.dev/t/optimizing-the-goertzel-algorithm/16233 "2026-06-18T00:33:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lufe](https://ziggit.dev/letter_avatar_proxy/v4/letter/l/b782af/32.png) [@lufe](https://ziggit.dev/u/lufe)\
**Post date:** [June 18, 2026, 12:33am UTC](https://ziggit.dev/t/optimizing-the-goertzel-algorithm/16233/1 "2026-06-18T00:33:31Z")

</div>

Hi everyone,

for some years now I have a small [tool](https://codeberg.org/lufe/goerzig) that uses the [Goertzel algorithm](https://en.wikipedia.org/wiki/Goertzel_algorithm) for spectral analysis.

Since I moved the project to 0.16.0 the performance dropped a lot. The reason being [Loop-Vectorization-Disabled](https://ziglang.org/download/0.16.0/release-notes.html#Loop-Vectorization-Disabled-to-Work-Around-Regression).

So I started to vectorize it manually, which helped a bit, but performance is still not what it was. So maybe someone can give me some hints how to further improve it (given, I do not just want to wait for the llvm fix to arrive). I compared my original implementation with the manually optimized one at [compiler explorer](https://godbolt.org/z/718cWPdsM).

- One thingt that stuck with me, was that in the manually vectorized version the `vfmadd132ps` instruction has twice the latency, because in that case it loads data from memory, whereas in the original version only registers are used
- this adds one more load/store operation in the manual version for some reason
- Also,it causes the fma operation to share one port with the load/store operations around it.
- Note that the zig version is set 0.15.2 on compiler explorer link to show the vectorized original version, but you can switch to 0.16.0.

Is there a way to implement the manual vectorization in such a way, that the fma operation is not used to load data from memory (without going for inline assembly)?

Many thanks for your help!

EDIT: as always, right after posting, I found the critical bug…performance of the manual vectorized loop is now about half of what the original one was before. So for now, there is only one remaining question.
