public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Porting GCC to a register-less, stack-less architecture
@ 2002-02-27  5:06 Alexandre Courbot
  2002-02-27  6:03 ` Alan Lehotsky
  0 siblings, 1 reply; 3+ messages in thread
From: Alexandre Courbot @ 2002-02-27  5:06 UTC (permalink / raw)
  To: GCC List

Hello everybody,

I'm currently trying to port GCC to a new Smartcard architecture that
has been developped in my university labs. This architecture doesn't
have any hardware register or any stack (all the operations are handled
in memory), which raises a lot of questions about the porting.

I've seen that many MD macros are dealing with hard registers. But I
have nothing to fill them with. I had to define FIRST_PSEUDO_REGISTER to
0, and of course some registers arrays (as reg_names) have a size of 0.
Can I write a machine description for a register-less machine? Shall I
emulate hard-registers and stack by using variables, which would result
in an overhead? Do you guys have some general advices for porting GCC to
such an architecture?

Also more generally, and as writing a MD for the first time is quite a
hard sport, could someone point me to a very simple (simplistic?) MD
example or template for GCC 3, if it exists? The ones that are provided
with the sources are quite complex, and although the manual is very
complete and helpfull in that respect, I'm rather the kind of guy who
learn by example. I'd like to come as fast as possible with a very basic
"working" compiler, so I can tune it step by step and experiment code
generation.

Thank you for your time,
Alexandre Courbot.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Porting GCC to a register-less, stack-less architecture
  2002-02-27  5:06 Porting GCC to a register-less, stack-less architecture Alexandre Courbot
@ 2002-02-27  6:03 ` Alan Lehotsky
  2002-02-27  6:56   ` Alexandre Courbot
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Lehotsky @ 2002-02-27  6:03 UTC (permalink / raw)
  To: Alexandre Courbot; +Cc: GCC List

At 1:54 PM +0100 2/27/02, Alexandre Courbot wrote:

>Hello everybody,
>
>I'm currently trying to port GCC to a new Smartcard architecture that
>has been developped in my university labs. This architecture doesn't
>have any hardware register or any stack (all the operations are handled
>in memory), which raises a lot of questions about the porting.

	How are function calls handled?

	Is all program storage statically declared?

	Where are you planning on allocating compiler temporaries (e.g., if everything's a
	memory-memory operation, how do I compute

		a = (b + c - d*a);

	(You can't use 'a' as the target without great difficulty (you'll have to write an optimization pass....))
	Are you going to use static variables as temps?


>I've seen that many MD macros are dealing with hard registers. But I
>have nothing to fill them with. I had to define FIRST_PSEUDO_REGISTER to
>0, and of course some registers arrays (as reg_names) have a size of 0.
>Can I write a machine description for a register-less machine? Shall I
>emulate hard-registers and stack by using variables, which would result
>in an overhead? Do you guys have some general advices for porting GCC to
>such an architecture?

	I'd think about defining a minimal set of "dummy" registers - just to keep the
	compiler happy with the SP and FP. And so that you have SOMEWHERE to allocate
	compiler temporaries.   (or you could just reserve a small number of memory locations,
	call them "registers" and let the compiler do the "register allocation" for those locations
	to treat them as temporaries.)  Assuming you have enough memory registers, you'll never
	spill until you get to a complex program - and maybe your users won't write complex code :-)

	Then, assuming that I expect to never support function calls, I can map my "stack" onto a range of static
	variables when I emit the assembly language.  Anything that ends up "using" my pseudo registers in
	"funny ways" (like a _builtin_alloca_ would be defined with a DEFINE_INSN that prints an error message
	instead of emitting an instruction to the .s file...

>Also more generally, and as writing a MD for the first time is quite a
>hard sport, could someone point me to a very simple (simplistic?) MD
>example or template for GCC 3, if it exists? The ones that are provided
>with the sources are quite complex, and although the manual is very
>complete and helpfull in that respect, I'm rather the kind of guy who
>learn by example. I'd like to come as fast as possible with a very basic
>"working" compiler, so I can tune it step by step and experiment code
>generation.

	Good strategy.  I'd pick a MD for a machine that you thoroughly understand, so you can see what it's
	doing and figure out if there's a correspondence to your architecture.  Off hand, I can't think of any
	machine that shares the characteristics of your architecture.

-- 
------------------------------------------------------------------------

		    Quality Software Management
		http://home.earthlink.net/~qsmgmt
			apl@alum.mit.edu
			(978)287-0435 Voice
			(978)808-6836 Cell
			(978)287-0436 Fax

	Software Process Improvement and Management Consulting
	     Language Design and Compiler Implementation

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Porting GCC to a register-less, stack-less architecture
  2002-02-27  6:03 ` Alan Lehotsky
@ 2002-02-27  6:56   ` Alexandre Courbot
  0 siblings, 0 replies; 3+ messages in thread
From: Alexandre Courbot @ 2002-02-27  6:56 UTC (permalink / raw)
  To: GCC List

> 	How are function calls handled?

Calls are performed by the Invok instruction, which takes the function
arguments as a parameter (might seems weird for an assembly language,
but it use less ressources than pushing, which is important for this
architecture). Arguments are taken back in the function body by
'.Arguments' declarations. For example, the following lines:

    .Arguments CardTB256 arg1
    .Arguments CardByte arg2 
    .Arguments CardByte arg3 

Would be the first lines of a function that takes 3 arguments.

There is also a return mechanism.

Others operations are quite classic. Arithmetic operations takes 3
arguments for example, which is just fine with GCC.

The architecture by itself might look a bit weird, but apart from the
fact it doesn't use a stack (which is only *absolutely* needed for
argument passing on others architectures anyway, right?) or hardware
registers, it's quite similar to others.

> 	Is all program storage statically declared?

You can declare new local variables with the .local statement. Note
however that my goal here isn't to have the libc working (no need for
mallocs and so on) but only to get GCC working ;) But if you asked
whether you allocate memory at the beginning of a block for example, the
answer is yes.

> 	Where are you planning on allocating compiler temporaries (e.g., if everything's a
> 	memory-memory operation, how do I compute
> 
> 		a = (b + c - d*a);
> 
> 	(You can't use 'a' as the target without great difficulty (you'll have to write an optimization pass....))
> 	Are you going to use static variables as temps?

I would use some local variables for this, as I can "dynamically"
allocate and de-allocate them.

> 	I'd think about defining a minimal set of "dummy" registers - just to keep the
> 	compiler happy with the SP and FP. And so that you have SOMEWHERE to allocate
> 	compiler temporaries.   (or you could just reserve a small number of memory locations,
> 	call them "registers" and let the compiler do the "register allocation" for those locations
> 	to treat them as temporaries.)  Assuming you have enough memory registers, you'll never
> 	spill until you get to a complex program - and maybe your users won't write complex code :-)

From what I understand, GCC use pseudo registers for temporaries, which
number isn't limited, right? So this is something I shouldn't have to
worry about, I guess. Unless I missed something. :)

> 	Then, assuming that I expect to never support function calls, I can map my "stack" onto a range of static
> 	variables when I emit the assembly language.  Anything that ends up "using" my pseudo registers in
> 	"funny ways" (like a _builtin_alloca_ would be defined with a DEFINE_INSN that prints an error message
> 	instead of emitting an instruction to the .s file...

Well, emulating a stack shouldn't be too hard on this arch anyway. But
if there is a way to do without (theorically it is possible, but I don't
know how much GCC likes such architectures) I'm taking it. :)

> 	Good strategy.  I'd pick a MD for a machine that you thoroughly understand, so you can see what it's
> 	doing and figure out if there's a correspondence to your architecture.  Off hand, I can't think of any
> 	machine that shares the characteristics of your architecture.

My knowledge is limited to the i386 architecture, which description is
quite complex (and which isn't as a "simple" architecture as I would
like). What I'm looking for is the most minimalist MD file you can set
up to get GCC to compile. Even if written for a different kind of
architecture, or a simple architecture I don't know yet, that's not a
problem - that would simply help me understanding GCC's mechanisms.

All in all, a .h and .md machine description files, the shortest
possible, which allows GCC to compile, would be paradise for me! :)

See you and thanks for the answer,
Alex.
-- 
http://www.gnurou.org


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-02-27 14:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-27  5:06 Porting GCC to a register-less, stack-less architecture Alexandre Courbot
2002-02-27  6:03 ` Alan Lehotsky
2002-02-27  6:56   ` Alexandre Courbot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).