On Wed, Mar 24, 2021 at 3:53 PM Johnny Billquist <b...@softjar.se> wrote: > > Perfectly expected. > With volatile, the compiler are not allowed to optimize away the memory > accesses for updating the loop variable. So you are suddenly getting a > lot of memory read/write cycles that probably didn't happen before. > I would even have expected that prior to the volatile, that loop would > be totally optimized away.
Yes, that's exactly right. Be careful with volatile: https://blog.regehr.org/archives/28 Enjoy, Nathan