5 ms·
And here I am using for loops like a caveman
by tmerr 8y ago
And here I am using for loops like a caveman
- alexeldeib 8y agoI think loop unrolling is super cool. We're typically trained in programming to try to eliminate the kind of reuse that unrolling typically looks like, but when applied properly it can work really well. I guess that applies to most tools, though.
- tzahola 8y agoCan you give us an example where manual loop unrolling would be desired over a for loop?
- andrepd 8y agoLanguages/compilers that don't do loop-unrolling automatically. If they do, then yes, it's probably best to let the compiler do it.
- monkpit 8y agoLike which?
- staticassertion 8y agoAll of the languages I can think of rely on the compiler backend for loop unrolling, which means it isn't a guarantee. You might want this if you need to guarantee the unroll. But I wasn't doing this for a loop unroll. I had a fixed size array that I wanted to serialize/ deserialize to/ from capnproto - there are no fixed size arrays in capnproto, so I wrote a message that just had b1, b2, b3... b16, and then some code to pull it out into a statically sized array. It allowed me to pull a bunch of bytes into a much larger statically allocated array without any allocation or bounds checking.
- alexeldeib 8y agoWhat actually brought it to mind was a hardware class where we were instantiating a bunch of the same module but didn't have a programmatic way to do it with our tooling. So...sorta like loop unrolling :)