EmbeddedRelated.com
Forums
Memfault State of IoT Report

mixing C and assembly

Started by Lax April 22, 2008
In article <seCdnTwTA7tRdZLVnZ2dnUVZ_gmdnZ2d@visi>,
Grant Edwards  <grante@visi.com> wrote:
<SNIP>
> >For example, two ways to sum the bytes in a buffer: > > unsigned char buf[128]; > unsigned sum = 0; > > unsigned i; > for (i=0; i<sizeof buf; ++i) > sum += buf[i]; > > unsigned char *p; > p = buf; > while (p < buf + (sizeof buf)) > sum += *p++; > >Those two blocks of code do the same thing. On some >target/toolchain combinations, they're both about the same >number of bytes/clocks. On some platforms I've used the first >was significantly smaller/faster. On others, the second was >significantly smaller/faster.
Going from the first to the second is a standard optimisation technique called strength reduction (with regard to an address calculation).
> >In the fist case, are you better off with an index that's an >"unsigned" or an "unsigned char" or an "int"? They can be >significatly different. Always pick something that will work >on as many platforms as possible, but if there are multiple >"correct" ways to do something, you might as well pick the one >that's going to generate the smallest/fastest code for the >target.
A good compiler knows that those are equivalent and do the picking for you.
> >If you want to be more than an amateur doing trivial projects, >you've got to know your target's instruction set and know what >code the compiler is going to generate each time you write a >line of C. > >I always set up my makefile so that the toolchain produces a >mixed C/assembly listing for each module. Anytime I'm not sure >what the compiler is going to do with a particular construct, I >look at the listing and see.
That is a good advice. You can learn something. However ... Did you look at some Itanium code or SEAforth code lately? Did you learn something or did you awake with a headache?
>-- >Grant Edwards grante Yow! I invented skydiving
Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- like all pyramid schemes -- ultimately falters. albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
On 2008-05-09, Albert van der Horst <albert@spenarnc.xs4all.nl> wrote:

> A good compiler knows that those are equivalent and do the > picking for you.
True. One doesn't always have the pleasure of using a good compiler. :)
> That is a good advice. You can learn something. However ... > Did you look at some Itanium code or SEAforth code lately?
Can't say that I have.
> Did you learn something or did you awake with a headache?
What I'm usually looking at are pretty standard CISC micros like the H8 or MSP430, or vanilla RISC CPUs like the ARM or NIOS2. Never had a chance to embed an Itanium in anything. -- Grant Edwards grante Yow! Here I am in the at POSTERIOR OLFACTORY LOBULE visi.com but I don't see CARL SAGAN anywhere!!
Grant Edwards wrote:
> On 2008-05-09, Albert van der Horst <albert@spenarnc.xs4all.nl> wrote: > >> A good compiler knows that those are equivalent and do the >> picking for you. > > True. One doesn't always have the pleasure of using a good > compiler. :) > >> That is a good advice. You can learn something. However ... >> Did you look at some Itanium code or SEAforth code lately? > > Can't say that I have. > >> Did you learn something or did you awake with a headache? > > What I'm usually looking at are pretty standard CISC micros > like the H8 or MSP430, or vanilla RISC CPUs like the ARM or > NIOS2. > > Never had a chance to embed an Itanium in anything. >
I was once involved in a prototype for a very large power supply. Because of its odd design, it had a high minimum output current, so in idle we had to burn off about 800W. We used a panel oven, but an embedded Itanium would have given a more compact solution.
On 2008-05-09, David Brown <david@westcontrol.removethisbit.com> wrote:

>> Never had a chance to embed an Itanium in anything. > > I was once involved in a prototype for a very large power > supply. Because of its odd design, it had a high minimum > output current, so in idle we had to burn off about 800W. We > used a panel oven, but an embedded Itanium would have given a > more compact solution.
The worlds first power supply that runs protien folding simulations while idle... -- Grant Edwards grante Yow! Now, let's SEND OUT at for QUICHE!! visi.com
Grant Edwards wrote:
> On 2008-05-09, David Brown <david@westcontrol.removethisbit.com> wrote: > >>> Never had a chance to embed an Itanium in anything. >> I was once involved in a prototype for a very large power >> supply. Because of its odd design, it had a high minimum >> output current, so in idle we had to burn off about 800W. We >> used a panel oven, but an embedded Itanium would have given a >> more compact solution. > > The worlds first power supply that runs protien folding > simulations while idle... >
"Protein folding" - that's like cooking a steak on top of the box?

Memfault State of IoT Report