C code optimization
ersmith
Posts: 6,099
I just noticed a funny thing about the pong game I posted in the other forum. I was trying to squeeze its code into COG memory, so I wanted to avoid pulling in the divide function from the library. So I wrote code that looks like:
Imagine my surprise when I found __UDIVSI (the low level divide function) in the symbol table for the output. It turns out that GCC recognized that we were setting "tens = number/10" and re-wrote the loop accordingly!
In this particular case it wasn't really what I wanted, but in the general case it would very much be an improvement. I'm constantly amazed by how good the machine independent optimization in GCC is. I guess that's what you get when you have an open source compiler that's worked on by top people all over the world for 20+ years.
Eric
tens = 0; while (number >= 10) { tens++; number -= 10; }to calculate the digits of the score.
Imagine my surprise when I found __UDIVSI (the low level divide function) in the symbol table for the output. It turns out that GCC recognized that we were setting "tens = number/10" and re-wrote the loop accordingly!
In this particular case it wasn't really what I wanted, but in the general case it would very much be an improvement. I'm constantly amazed by how good the machine independent optimization in GCC is. I guess that's what you get when you have an open source compiler that's worked on by top people all over the world for 20+ years.
Eric
Comments
Now I get it, what GCC did with my FFT is to throw it away and put in a better one:)