Re: mixing C and assembly



CBFalconer wrote:
David Brown wrote:
... snip ...
A quick test on avr-gcc 4.2.2, using 16-bit and 8-bit ints rather
than 32-bit and 16-bit (since it's an 8-bit cpu) reveals that
avr-gcc is smart enough to do a 8-bit x 8-bit -> 16-bit multiply
as desired. It's a little harder to see exactly what is
happening for bigger numbers and for division, since these use
library calls - certainly the compiler will generalise some of
these functions. But for the very common case of the multiply
like this, you get optimal code.

Defining 'optimal' is a varying target. Among others, see Knuth. In particular, in the past I have compromised on an 8 * 16 -> 24
bit heart, two of which, with an addition, produced a 16 * 16 -> 32
multiplication. This had, on the machine of interest (an 8080),
significant advantages, i.e. about a 50% decrease in multiplication
times. Other games are available at the compile stage where one
operand is constant, especially those where the multiplier consists
of some solid string of 1 bits.


Yes, "optimal" can mean different things - code size, speed, stack use and ram size being the most common points. "optimal" also depends on things like shared library code, and any other information that the compiler may have. That's why I restricted my test to a simple 8x8->16 multiply on the AVR - the generated code is simple enough to be optimal in every way.
.



Relevant Pages

  • Re: A C Adventure: your comments are welcome
    ... I feed it to the compiler and step though the ... and warnings. ...  It's quite common to find some of the errors are due ...
    (comp.lang.c)
  • Re: Obstacles for Tcl/Tk commercial application development ?
    ... this is no problem: the compiler will refuse to ... previous message, it is impossible to check all execution paths, ... kilometers, which is clearly a type error. ...
    (comp.lang.tcl)
  • Re: Microsoft style:
    ... I do like the compiler to remind me, and when I *know* I've just set a short equal to an int, and it is deliberate, I put an explicit cast in to shut the compiler up. ... common words like the verb 'to be' are short and irregular but less used ... Part of the reason was commercial: by making US spellings different, it gave a boost to the nascent US publishing industry and made it less dependent on imports. ... And 'programme' has already changed to 'program' in UK English when it means a computer program, but retaining our quirkiness, it's still 'programme' when it refers to anything else :-) ...
    (microsoft.public.vc.mfc)
  • Re: Comparision of C Sharp and C performance
    ... It wasn't a compiler, and it wasn't complete. ... I am given to understand that the vendor had to threaten a law-suit to get the money, but that doesn't mean Gates stole the software. ... I've never been fired from a programming job. ...
    (comp.lang.c)
  • Re: Wit-to-whine ratios
    ... He has stated publicly that he modified a compiler that he ... called me a liar. ... scratch compiler. ...
    (comp.lang.c)