This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: gcc for any microcontroller?


On 24 Mar 2003, Petr Danecek wrote:

> thank you for your answer, Toshi.
> if i understand it correctly, HC08 would be difficult to port, though
> not impossible. now, is it worth of it? maybe there is a more suitable c
> compiler somewhere. i doubt that writing cc from scratch is a good
> choice...?
> petr

I took a look at the 68HC08, and it looks like a straight 6800
implementation afaict - it has one 8-bit accumulator and a 16-bit
register.

I haven't ported gcc to an accumulator machine, but did I port lcc to
the 65816 a while back. Based on this, you would probably fake a machine
with 8 16-bit virtual registers, then do post-reload splits to break the
virtual insns manipulating virtual 16-bit  registers down into hardware
machine insns manipulating the real accumulator.

This will create a lot of redundant load/store instructions from the
virtual registers, so you will need to create a machine-dependent pass to
slice the 16-bit operations into two 8-bit operations which will require
fewer load/stores when possible.

Consider:

	sint16_t a, b, c;
	a = (b + c) & d;

If you do this naively, it will generate something like:
(ignoring the carry issues for moment)

	accum = low(b);
	accum += low(c);
	temp1 = accum;
	accum = high(b);
	accum += high(c);
	temp2 = accum;
	accum = temp1;
	accum &= low(d);
	low(a) = accum;
	accum = temp2;
	accum &= high(d);
	high(a) = accum;

If you reorder the sequence of operations, you can do this instead,
assuming AND doesn't modify the carry bit:

	accum = low(b);
	accum += low(c);
	accum &= low(d);
	low(a) = accum;
	accum = high(b);
	accum += high(c);
	accum 7= high(d);
	high(a) = accum;

...which eliminates two loads and two stores.

Toshi



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]