3 ms·
Correction: if you want to do that in two dimensions, you have to do that twice, and the second dimension is going to have worse locality of reference, especial
by kragen 6y ago
Correction: if you want to do that in two dimensions, you have to do that twice, and the second dimension is going to have worse locality of reference, especially if you don't tile your images. I still think that's efficient and practical.
GCC unrolled the loop twice, so it was 34 instructions that processed two samples per iteration. The instructions are mostly things like this:
addq (%rax), %rbp
subq %rdi, %rcx
addq %rbx, %rdi
subq %rcx, %rdx
movq %rcx, -2064(%rax)
movq -2056(%rax), %rcx
That should clarify a bit how one core of my mere 2.8GHz Core i7 is managing to run over ten billion instructions per second.
Godbolt link for those who want to play: https://godbolt.org/z/MfEqYn3Pd https://godbolt.org/z/MfEqYn3Pd
Gaussian blur gets used for this a lot precisely because it's so easy to compute this way — it's the only convolution kernel that's anisotropic and separable. So people press it into service doing things like camera bokeh that it's not really very good at.
- johncostella 6y agoAh nice, I will correct that statement, which I was sure was bound to have a counterargument. :)
- kragen 6y agoHappy to help!
- kragen 6y agoI see that now your page links to my comment, saying, "More efficient ways of performing Gaussian blur have been noted; the Magic Blur was convenient in that it made use of existing hardware libraries and calling code stack." But in fact what I described above is the Magic Blur algorithm, just in a slightly different guise, and it can probably take advantage of existing hardware libraries in the same way. However, I don't know what your hardware libraries are doing in the blur case!