Re: C code .vs. Assembly code for Microcontrollers/DSPs ?

albaugh@agames.com (Mike Albaugh)
16 Mar 1996 00:11:29 -0500

          From comp.compilers

Related articles
[25 earlier articles]
Re: C code .vs. Assembly code for Microcontrollers/DSPs ? bobduff@world.std.com (1996-03-14)
Re: C code .vs. Assembly code for Microcontrollers/DSPs ? john.r.strohm@BIX.com (1996-03-15)
Re: C code .vs. Assembly code for Microcontrollers/DSPs ? cdg@nullstone.com (1996-03-15)
Re: C code .vs. Assembly code for Microcontrollers/DSPs ? cdg@nullstone.com (1996-03-16)
Re: C code .vs. Assembly code for Microcontrollers/DSPs ? dan@watson.ibm.com (1996-03-16)
Re: C code .vs. Assembly code for Microcontrollers/DSPs ? stefan.monnier@lia.di.epfl.ch (Stefan Monnier) (1996-03-16)
Re: C code .vs. Assembly code for Microcontrollers/DSPs ? albaugh@agames.com (1996-03-16)
Re: C code .vs. Assembly code for Microcontrollers/DSPs ? preston@cs.rice.edu (1996-03-17)
Re: C code .vs. Assembly code for Microcontrollers/DSPs ? elvey@hal.com (1996-03-17)
Re: C code .vs. Assembly code for Microcontrollers/DSPs ? john.gilliver@gecm.com (1996-03-20)
Re: C code .vs. Assembly code for Microcontrollers/DSPs ? leichter@smarts.com (Jerry Leichter) (1996-03-21)
Re: C code .vs. Assembly code for Microcontrollers/DSPs ? stefan.monnier@lia.di.epfl.ch (Stefan Monnier) (1996-03-21)
Re: C code .vs. Assembly code for Microcontrollers/DSPs ? cdg@nullstone.com (1996-03-21)
[18 later articles]
| List of all articles for this month |

From: albaugh@agames.com (Mike Albaugh)
Newsgroups: comp.arch,comp.compilers,comp.dsp
Date: 16 Mar 1996 00:11:29 -0500
Organization: Time-Warner Interactive
References: 96-03-006 96-03-091
Keywords: optimize, performance

Not to sound like a broken record, as I have brought up
this point several times before...


Scott A. Berg (sberg@camtronics.com) wrote:
: ravindra@hal.com says...
: >I've heard people say so many times, that hand-crafted (assembly) code
: >is more compact than compiled C code for microcontrollers or DSPs.
: >
: >So where is the problem?


No language is a perfect match for all algorithms. C, in
particular, "dislikes" fixed-point math, multi-precision, co-routines,
and a few other features of some nice algorithms that pop up a lot in
embedded code. Before I get flamed to death by "you can do anything in
C" folks, I don't mean to say that you can't, just that the
machinations needed to do so will not likely result in code that
commonly available compilers will do very well on. Choice of algorithm
is very often _the_ first-order determinant of performance, and
rejecting what may be the best available algorithm for a task because
it is difficult to express in C is a big cause of these problems,
IMHO.


To clarify, I do _not_ write a great deal of hand-crafted
assembly anymore, unless I'm doing a debugger, exception-handler, or
_very_ high-use library routine. OTOH, when you need it, you really
need it. A seldom-mentioned approach is to generate "assembly" in
other ways, such as with a (now rare) decent macro-assembler, a
home-brew "compiler" for a very application-specific "small language",
or whatever gets you through the day. It's not "hand crafted"
assembly, but it's not 'C'. Why does everybody seem to believe those
are the only two choices?


I've made these points before. What made me decide to post
a followup to this one was the following:


: 2 - C includes some under-used features to help the compiler.
: "register", "static" and "const" are three keywords that can have a
: major impact on resulting code, but they are used too little due to
: their not being well understood.


And the comp.compilers moderator's comment:


: [Do people really not use const and static? And are there still compilers
: that pay attention to register? -John]


From personal inspection of "inherited" code, "static" is
used, but nowhere near as often as it should be. In the wider world, I
have reason to believe that "const" is also underused. About two years
ago I found a serious bug in "const" handling in a "mature" compiler
from a very-well-known vendor, who shall remain nameless. The fact
that I was the first to report this bug to them, and that it was (by
their account) not recently introduced, implies that few of their
customers (other than me :-) were using "const". This was an
embedded-systems compiler, where I would expect "const" to be if
anything _more_ popular...


As for "register", I would expect at least that the compiler
complain if I tried to take the address of a "register" variable, and
could thus warn me of the sort of slime who use the C++ "reference"
operator :-)


Mike


| Mike Albaugh (albaugh@agames.com) Time Warner Interactive
| (The entertainment company formerly known as Atari Games (_NOT_ Tramiel's))
| 675 Sycamore Dr. Milpitas, CA 95035 voice: (408)434-1709
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.