This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


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

Re: typedef void * SCM



> > I already talked about this to Jim and Maciej, but this is probably a
> > no-go. As you point out, passing structs around will affect
> > performance negatively, so a it would be a compilation-only feature.
> 
> Passing structs does not damage performance for gcc users and other
> suitably optimised compilers:
> 
> `-freg-struct-return'
>      Use the convention that `struct' and `union' values are returned
>      in registers when possible.  This is more efficient for small
>      structures than `-fpcc-struct-return'.
> 
>      If you specify neither `-fpcc-struct-return' nor its contrary
>      `-freg-struct-return', GNU CC defaults to whichever convention is
>      standard for the target.  If there is no standard convention, GNU
>      CC defaults to `-fpcc-struct-return', except on targets where GNU
>      CC is the principal compiler.  In those cases, we can choose the
>      standard, and we chose the more efficient register return
>      alternative.

Well, yeah, but code compiled with this flag can't pass structures or
unions correctly to libraries compiled without this flag.  You can't
just mix-and-match.  I think that's a recipe for a real mess.

I also think it's ugly that you couldn't just produce a .o file and
link it against -lguile; you'd have to dig around in the manual and
find the right flag, or else the first call you make to a Guile
function crashes.  Not a great first experience.

> Anyhow, performance should not be the issue against doing something
> that is philosophically the correct way to do it and for which
> optimisations can be made at a later date. At a basic level, it is
> the C programmers responsibility to use the language in the most
> correct way and the compiler's responsibility to adapt that to the
> machine in the most optimal way.

I sympathize with this sentiment, but this isn't an optimization issue
--- it's an ABI issue.  The i386 supplement to the SysV ABI, which
Linux follows, specifies how aggregates should be passed.  You can
deviate from that ABI for intra-module calls, but all inter-module
calls should follow that rule.  So it's not going to get better when
the compilers get smarter.

Keep in mind that that paragraph from the GCC manual has been around
since the late '80s.  At that time, it wasn't uncommon for passing
structures by value to simply not work at all.  (Or maybe I was just
unlucky.)  In the presence of chaos, it made sense for GCC to offer
you the option of various ways to deal with that chaos.  Nowadays,
these things seem to be much more orderly, and it doesn't make as much
sense for GCC to offer options that go against a much more clearly
established precedent.

> > I think that a compilation-only check will be too much work for a
> > developer. I for one, can't see myself using
> > -DGUILE_COMPILE_TIME_DEBUG_MODE on a regular basis, if it is an extra
> > action I have to consciously make during development.
> 
> It should be a conscious extra action to switch it OFF.

You may be right, but you're approaching an unpleasant conclusion.

I think the best you can do is to have SCM be a pointer to an
incomplete structure type normally, which provides some checking, and
also provide a CPP switch that says to use a struct or union.  If
you're having troubles, you do a 'make clean' of your project, 'make
all CFLAGS=-DGUILE_STRICT_TYPING', fix your errors, and then do 'make
clean; make all'.

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