[sdiy] Quick C query

Veronica Merryfield veronica.merryfield at shaw.ca
Sun Nov 21 21:24:41 CET 2010


On 2010-11-21, at 11:56 AM, cheater cheater wrote:

> higher level languages and you have to break out to assembler (be it
> use of SIMD, or atomic changes to data)
> 
> There is a real demand for this kind of work being performed.

You'd be surprised how much you can hand assemble in C if you understand what the compiler is doing. Most embedded application projects do not change the tools during the life of the project so tuning the C to the output is not the heinous sin it would first appear.

> With MCU's you're dealing with something that's slower than a 386.
> Most applications for the 386 were written in pure assembler.

I doubt that somehow even if by virtue of the compiler wars between Borland and Microsoft.

Going back to the OP, single logic flags are normally instantiated as ints, being the most natural size for the under lying architecture and therefore normally the most efficient. One should check the flag against 0, i.e. equal to or not equal to. Some define FALSE as 0 and TRUE as 1, but one should stick to checking against 0. THe underlying assembler to this on most machines is similar.

Whilst some compilers support bitfields, it is not universal - check the tools set text for this. Those that do support it are often expensive in code size and execution speed although some architectures offer bitfield support that the compiler writers can use. In PIC land, the register definition headers often use unions of structures that include a bitfield definition and a non-bitfield overlay.

It is common to find the bits defined in binary powers of two with defined meanings and use the | and & operators to combine and test. This is great for packing but can lead to lengthy chains of if elseif else code which can get cumbersome and expensive depending on the compiler. 

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. 

>> Obviously even if it's not strictly necessary, there's nothing wrong with
>> enthusiasts doing it to squeeze the last possible drop of performance out of
>> the hardware (which e.g. demo scene coders still do in the PC world).

Many professionals do it all the time although an equal number seem to think that buying a faster machine is a reasonable solution too. 

Veronica




More information about the Synth-diy mailing list