#C and Assembler
Recently, a time critical loop motivated me to take a look (MC68000 User's
Manual in hand) at the assembly source output of the Manx compiler for the
first time.
This is not intended to be critical of Manx. However, even to a novice, it
is pretty easy to see places where the efficiency of the compiler output
can be improved. I was able to decrease the execution time of the above
mentioned loop by 25% by making just a handful of tweaks to the code. For
most of the programs I write, this kind of tweaking probably isn't worth
the effort and, I'm certainly not inclined to start writing entire programs
in assembler. Once in a while however, it appears that the benifits of
altering the compiler output or using in-line assembly code in your C
functions can be dramatic.
Examining the compiler output is also very educational. C gives us many
alterative ways of performing the same task. The code generated by these
alternatives can differ significantly in size and efficiency. Finally,
looking at the compiler output is a good way, although perhaps not a great
way, to begin learning 68000 assembly language.
I was surprised that Manx's "optimizing" compiler doesn't detect divisions
by powers of two. I'd always been led to believe that other compilers
(MicroSoft, for example) did do this. Aztec C alway uses the CPU's divide
instructions instead of shifting. Is this a reasonable thing to do? Does
the 68000 do power of two divides as fast as it can shift?
I'd like to hear some other people's thoughts on and experiences with
mixing C and assembler.