[sdiy] Quick C query

Jason Proctor jason at redfish.net
Sun Nov 21 22:10:36 CET 2010

>On 2010-11-21, at 12:31 PM, Jason Proctor wrote:
>>>  Which gets me back to knowing what the compiler does with code. 
>>>Output to a listing file and look can get you a very long way 
>>>before having to goto assembly.
>>  seconded. i wrote gobs of C before i did any assembler, hence i 
>>learned a lot by having the compiler compile, but not assemble or 
>>link. studying the assembler output can be very enlightening 
>>indeed, especially while varying the optimisation settings.
>A few years into my career in embedded software I found that one can 
>not rely on optimisations. The typical pattern is to write code and 
>debug it and switch optimisation to get it to run faster, often 
>leading to code was very hard to debug and could lead to unexpected 
>side effects which were now hard to debug. I learnt to write code 
>that gained little by changing options which meant I had debuggable 
>code with decent performance.

i agree on optimisation in general - in fact the strategy now seems 
to be to make code only 70-80% as fast as it needs to be, assuming 
that the optimiser will pick up the rest. but in this case i'm 
referring to learning different assembler techniques from looking at 
how the compiler does it. and with different optimisation settings, 
little chunks of C can have dramatically different resulting 
assembler code.

i found for example without optimisation GCC for 68k wouldn't even 
bother to try to save instructions on some situations (long time ago, 
no example sorry) whereas passing even a regular -O would result in 
collapsing a calculation down to one combo instruction. which is in 
fact how i learned to apply that particular instruction :-)

More information about the Synth-diy mailing list