Re: mixing C and assembly
- From: David Brown <david.brown@xxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 27 Apr 2008 22:22:48 +0200
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.
.
- References:
- mixing C and assembly
- From: Lax
- Re: mixing C and assembly
- From: Hans-Bernhard Bröker
- Re: mixing C and assembly
- From: Chris H
- Re: mixing C and assembly
- From: Walter Banks
- Re: mixing C and assembly
- From: Mark Borgerson
- Re: mixing C and assembly
- From: Walter Banks
- Re: mixing C and assembly
- From: Stefan Reuther
- Re: mixing C and assembly
- From: Walter Banks
- Re: mixing C and assembly
- From: cbarn24050
- Re: mixing C and assembly
- From: David Brown
- Re: mixing C and assembly
- From: Walter Banks
- Re: mixing C and assembly
- From: CBFalconer
- Re: mixing C and assembly
- From: cbarn24050
- Re: mixing C and assembly
- From: Walter Banks
- Re: mixing C and assembly
- From: cbarn24050
- Re: mixing C and assembly
- From: Walter Banks
- Re: mixing C and assembly
- From: CBFalconer
- Re: mixing C and assembly
- From: Walter Banks
- Re: mixing C and assembly
- From: Robert Adsett
- Re: mixing C and assembly
- From: David Brown
- Re: mixing C and assembly
- From: CBFalconer
- mixing C and assembly
- Prev by Date: Re: mixing C and assembly
- Next by Date: Re: Bug in latest IAR MSP430 compiler optimization???
- Previous by thread: Re: mixing C and assembly
- Next by thread: Re: mixing C and assembly
- Index(es):
Relevant Pages
|