gillham / logic_analyzer

Implementation of a SUMP compatible logic analyzer for the Arduino
Other
463 stars 99 forks source link

Unrolled loops? #22

Closed chino closed 9 years ago

chino commented 9 years ago

I'm very curious about this.

I understand the concept of "unrolled loops" but why couldn't the compiler have done it for you?

For example here:

https://github.com/gillham/logic_analyzer/blob/master/logic_analyzer_inline_2mhz.ino#L93

gillham commented 9 years ago

The gcc compiler bundled with the Arduino IDE ignores the unroll-loops options. For example:

pragma GCC optimize ("unroll-loops") generates "warning: ignoring #pragma GCC optimize"

attribute((optimize("unroll-loops"))) generates "warning: 'optimize' attribute directive ignored"

So as far as I know there is no way to convince it to unroll a specific loop.

chino commented 9 years ago

Hm. The optimization steps don't do it implicitly either?

Does it really matter to just use a normal loop? I guess that adds another jump instruction?

Would be cool to actually have a pre-build step that uses a script to generate the unrolled c code.

chino commented 9 years ago

It's interesting to think about. Would a jump really matter with the avr architecture? Like does it really eat up a cycle..

chino commented 9 years ago

I guess no matter what though if it can't unroll by it self then the test condition would eat up cycles.

gillham commented 9 years ago

Right, all instructions take cycles and a loop needs a check on the counter and then a branch to loop or exit. That check overhead eats cycles which reduces the sample rate.