reducing stack size by breaking SPARC ABI for OS-less environments

2008-12-15 Thread David Meggy
Hi, I'm working on a very embedded project where we have no operating
system, and there is no window overflow trap handler.  I'm really
stretched for memory and I'd like to reduce the stack size.  I haven't
not being able to find anyone else who is looking at reducing the stack
usage by google searching, but it seems like there is room to be saved,
and I need the extra space.

As I have no window overflow trap handler the space reserved on the
stack for saving in and local registers is just wasted memory.  Is there
any way I can reclaim this space by forcing the compiler to not honour
the standard SPARC ABI?

Would it be possible to take this one step further and drop the stack
space for arguments?  We don't have functions with large numbers of
arguments, so all arguments should be passed in registers.

Although only a single word, the One-word hidden parameter, seems like a
waste if none of our code ever uses it.

David


RE: reducing stack size by breaking SPARC ABI for OS-less environments

2008-12-15 Thread David Meggy
Hi Seongbae

This would reduce the stack memory, but I'd lose the advantage of all of those 
register windows.  I'd like to still have the fast register windows, and if I 
could avoid the mflat the callee wouldn't need to save all those registers and 
consume stack space for this.

David

-Original Message-
From: Seongbae Park 박성배 朴成培 [mailto:seongbae.p...@gmail.com] 
Sent: Monday, December 15, 2008 2:40 PM
To: David Meggy
Cc: gcc@gcc.gnu.org
Subject: Re: reducing stack size by breaking SPARC ABI for OS-less environments

On Mon, Dec 15, 2008 at 2:20 PM, David Meggy  wrote:
> Hi, I'm working on a very embedded project where we have no operating
> system, and there is no window overflow trap handler.  I'm really
> stretched for memory and I'd like to reduce the stack size.  I haven't
> not being able to find anyone else who is looking at reducing the stack
> usage by google searching, but it seems like there is room to be saved,
> and I need the extra space.
>
> As I have no window overflow trap handler the space reserved on the
> stack for saving in and local registers is just wasted memory.  Is there
> any way I can reclaim this space by forcing the compiler to not honour
> the standard SPARC ABI?
>
> Would it be possible to take this one step further and drop the stack
> space for arguments?  We don't have functions with large numbers of
> arguments, so all arguments should be passed in registers.
>
> Although only a single word, the One-word hidden parameter, seems like a
> waste if none of our code ever uses it.
>
> David

With gcc 3.x, you can use -mflat which would do what you want.
gcc 4.x completely dropped the support for -mflat, so unless you (or
someone) work on reintroducing it,
IHMO, you're out of luck with gcc 4.x.

Seongbae



bare metal SPARC

2012-07-31 Thread David Meggy
Hi All

Here at Icron we are using the Leon SPARC CPU in a very minimal setting with no 
operating system.  We have set the CPU for a large number of register windows, 
and have defined register window overflow and underflow traps as fatal 
conditions that do not need to be supported.  This model of operation has no 
need to reserve stack space for the register overflow and underflow trap 
handlers, so we have created a new SPARC ABI to reduce the stack space 
allocation in our system.  We have called this ABI metal, as it is for programs 
running close to the bare metal without an operating system.

We're not sure if there is interest in this change outside of Icron.  If so 
this is the patch that we apply on 4.7.1.  Please note that we are not GCC 
developers, we are not entirely sure how to make the three options (-mflat, 
-mnoflat, and -mmetal) mutually exclusive.  We would appreciate any feedback on 
this change, especially if it has any consequences that is not obvious to us.

diff -urN gcc-4.7.1.orig/gcc/config/sparc/sparc.h 
gcc-4.7.1/gcc/config/sparc/sparc.h
--- gcc-4.7.1.orig/gcc/config/sparc/sparc.h2012-03-24 11:47:55.0 
-0700
+++ gcc-4.7.1/gcc/config/sparc/sparc.h 2012-06-15 10:39:16.0 -0700
@@ -309,6 +309,7 @@
 #define CPP_OTHER_SPEC "\
 %{mflat:-D_FLAT} \
 %{msoft-float:-D_SOFT_FLOAT} \
+%{mmetal:-D_METAL} \
 "
 
 /* Macros to distinguish the particular subtarget.  */
@@ -801,7 +802,7 @@
Must reserve 64 bytes for the in and local registers.
v9: Functions which return large structures get the address to place the
wanted value from an invisible first argument.  */
-#define STRUCT_VALUE_OFFSET 64
+#define STRUCT_VALUE_OFFSET (TARGET_METAL ? 0 : 64)
 
 /* Define the classes of registers for register constraints in the
machine description.  Also define ranges of constants.
diff -urN gcc-4.7.1.orig/gcc/config/sparc/sparc.opt 
gcc-4.7.1/gcc/config/sparc/sparc.opt
--- gcc-4.7.1.orig/gcc/config/sparc/sparc.opt  2011-11-30 08:10:24.0 
-0800
+++ gcc-4.7.1/gcc/config/sparc/sparc.opt   2012-06-15 10:37:15.0 
-0700
@@ -38,9 +38,17 @@
 Do not use hardware FP
 
 mflat
-Target Report Mask(FLAT)
+Target Report Mask(FLAT) RejectNegative Negative(mno-flat)
 Use flat register window model
 
+mno-flat
+Target Report InverseMask(FLAT) RejectNegative Negative(mmetal)
+Do not use flat register window model
+
+mmetal
+Target Report Mask(METAL) RejectNegative Negative(mflat)
+Use metal register window model
+
 munaligned-doubles
 Target Report Mask(UNALIGNED_DOUBLES)
 Assume possible double misalignment


Thanks for the excellent compiler
David