public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* PATCH: Re: optimization/6162: gcc 3.0.4: certain i386 asm reloader ice
@ 2002-10-30 21:14 Nathanael Nerode
  2002-11-10  8:17 ` [PATCH] Fastcall support on cygwin and mingw targets Casper Hornstrup
  0 siblings, 1 reply; 26+ messages in thread
From: Nathanael Nerode @ 2002-10-30 21:14 UTC (permalink / raw)
  To: user42, gcc-gnats, gcc-patches, gcc-bugs, nobody

Here's a documentation fix.  I suspect this is enough to allow the PR to 
be closed, given that
* this asm syntax is a gcc extension, I believe, and as such we
can specify it to behave however we like.
* the behavior isn't going to change any time in the near future.
* in general the problem can be worked around if people are aware of it.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6162

	PR optimization/6162
	* md.texi: Document restriction on commutative operand
	specification.

Index: md.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/md.texi,v
retrieving revision 1.51
diff -u -r1.51 md.texi
--- md.texi     15 Sep 2002 22:48:05 -0000      1.51
+++ md.texi     31 Oct 2002 05:09:57 -0000
@@ -1256,6 +1256,8 @@
    @dots{})
  @end smallexample
  @end ifset
+GCC can only handle one commutative pair in an asm; if you use more,
+the compiler may fail.

  @cindex @samp{#} in constraint
  @item #

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

* [PATCH] Fastcall support on cygwin and mingw targets
  2002-10-30 21:14 PATCH: Re: optimization/6162: gcc 3.0.4: certain i386 asm reloader ice Nathanael Nerode
@ 2002-11-10  8:17 ` Casper Hornstrup
  2002-11-10 17:50   ` Fergus Henderson
  0 siblings, 1 reply; 26+ messages in thread
From: Casper Hornstrup @ 2002-11-10  8:17 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 2378 bytes --]

This patch implements support in gcc for the fastcall calling
convention on cygwin and mingw targets.

When using the fastcall calling convention, parameters are
(if possible) passed in registers, thereby eliminating
the need to use the stack for transferring parameters.

Binutils support for fastcall symbols is already in binutils CVS.

Casper Hornstrup


gcc/testsuite/ChangeLog

2002-11-10  Casper S. Hornstrup  <chorns@users.sourceforge.net>

	* gcc.c-torture/compile/20021110-1.c: New test.
	* gcc.c-torture/compile/20021110-1.x: Likewise.
	* gcc.c-torture/compile/20021110-2.c: Likewise.
	* gcc.c-torture/compile/20021110-2.x: Likewise.
	* gcc.c-torture/compile/20021110-3.c: Likewise.
	* gcc.c-torture/compile/20021110-3.x: Likewise.
	* gcc.c-torture/compile/20021110-4.c: Likewise.
	* gcc.c-torture/compile/20021110-4.x: Likewise.


gcc/ChangeLog

2002-11-10  Danny Smith  <dannysmith@users.sourceforge.net>

	* config/i386/i386.c (ix86_comp_type_attributes): Check for
mismatched
	fastcall types.

2002-11-10  Eric Kohl  <ekohl@rz-online.de>

	* config/i386/cygwin.h (TARGET_OS_CPP_BUILTINS): Add fastcall
	attributes.
	(ASM_OUTPUT_LABELREF): Add __imp_ prefix now rather than in
winnt.c.
	* config/i386/winnt.c (i386_pe_mark_dllimport). Convert internal
	fastcall decoration to MS-compatible decoration. Add __imp_
prefix in
	ASM_OUTPUT_LABELREF rather than here.
	* config/i386/i386.c (ix86_attribute_table): Accept 'fastcall'
as a
	valid attribute.
	(ix86_return_pops_args): Fastcall functions pop the stack.
	(init_cumulative_args): Reserve registers ECX and EDX if
function has
	fastcall attribute.
	(function_arg): Use registers ECX and EDX if function has
fastcall
	attribute.
	* config/i386/i386.h (CUMULATIVE_ARGS): Add fastcall attribute
flag.
	* config/i386/mingw32.h (TARGET_OS_CPP_BUILTINS): Add fastcall
	attributes.
	* config/i386/winnt.c (gen_fastcall_suffix): New function.
Decorates a
	label name with a preliminary fastcall prefix (+) and the
stdcall
	suffix.
	(i386_pe_encode_section_info): Call gen_fastcall_suffix() if a
symbol
	has a fastcall attribute.
	(i386_pe_strip_name_encoding): Return length of internal
fastcall
	prefix (+).
	(i386_pe_fastcall_name_p): New function. Returns wether a symbol
is a
	fastcall symbol.
	(i386_pe_asm_file_end): Output fastcall symbols correctly.
	* doc/extend.texi: Add documentation of fastcall attribute.

[-- Attachment #2: fastcall.tar.gz --]
[-- Type: application/octet-stream, Size: 5341 bytes --]

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

* Re: [PATCH] Fastcall support on cygwin and mingw targets
  2002-11-10  8:17 ` [PATCH] Fastcall support on cygwin and mingw targets Casper Hornstrup
@ 2002-11-10 17:50   ` Fergus Henderson
  2002-11-10 19:10     ` Christopher Faylor
  2002-11-11 12:47     ` Casper Hornstrup
  0 siblings, 2 replies; 26+ messages in thread
From: Fergus Henderson @ 2002-11-10 17:50 UTC (permalink / raw)
  To: Casper Hornstrup; +Cc: gcc-patches

Some comments above the definition of ASM_OUTPUT_LABELREF would be nice.

What happens if a function has multiple attributes,
e.g. both fastcall and stdcall or both fastcall and regparm(3)?
It may be worth adding a test for that case.

>+ The @code{fastcall} calling convention exists in Windows NT for Intel
>+ processors only.

That part of the documentation is wrong.
Cygwin and Mingw work on most variants of Windows, not just Windows NT.

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.

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

* Re: [PATCH] Fastcall support on cygwin and mingw targets
  2002-11-10 17:50   ` Fergus Henderson
@ 2002-11-10 19:10     ` Christopher Faylor
  2002-11-11 12:47     ` Casper Hornstrup
  1 sibling, 0 replies; 26+ messages in thread
From: Christopher Faylor @ 2002-11-10 19:10 UTC (permalink / raw)
  To: Fergus Henderson; +Cc: Casper Hornstrup, gcc-patches

On Mon, Nov 11, 2002 at 12:50:42PM +1100, Fergus Henderson wrote:
>Some comments above the definition of ASM_OUTPUT_LABELREF would be nice.
>
>What happens if a function has multiple attributes,
>e.g. both fastcall and stdcall or both fastcall and regparm(3)?
>It may be worth adding a test for that case.
>
>>+ The @code{fastcall} calling convention exists in Windows NT for Intel
>>+ processors only.
>
>That part of the documentation is wrong.
>Cygwin and Mingw work on most variants of Windows, not just Windows NT.

Fastcall does work on any version of Windows, AFAIK.

cgf

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

* Re: [PATCH] Fastcall support on cygwin and mingw targets
  2002-11-11 12:47     ` Casper Hornstrup
@ 2002-11-11 12:27       ` Fergus Henderson
  2002-11-12 10:45         ` Casper Hornstrup
  0 siblings, 1 reply; 26+ messages in thread
From: Fergus Henderson @ 2002-11-11 12:27 UTC (permalink / raw)
  To: Casper Hornstrup; +Cc: gcc-patches

On 11-Nov-2002, Casper Hornstrup <chorns@users.sourceforge.net> wrote:
> 
> > What happens if a function has multiple attributes,
> > e.g. both fastcall and stdcall or both fastcall and 
> > regparm(3)? It may be worth adding a test for that case.
> > 
> 
> stdcall attribute after fastcall attribute - fastcall calling
> convention is used, but the symbol is prefixed with _ not @.
> 
> Obviously a bug, but how should this situation be handled?
> Which attribute should win and should gcc emit a warning or
> error out?
>
> fastcall attribute after stdcall attribute - same result.
> fastcall attribute after regparm(3) attribute - fastcall wins.
> regparm(3) attribute after fastcall attribute - fastcall wins.

IMHO the desirable behaviour is for gcc to report an error
in all of these cases.

> > >+ The @code{fastcall} calling convention exists in Windows NT for Intel 
> > >+ processors only.
> > 
> > That part of the documentation is wrong.
> > Cygwin and Mingw work on most variants of Windows, not just 
> > Windows NT.
> 
> I think it is a reference to fastcall only being used on Intel
> Windows NT platforms (eg. it was not used on Windows NT/Alpha).
> Maybe it should be removed?

Either that, or just delete the "NT".

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.

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

* RE: [PATCH] Fastcall support on cygwin and mingw targets
  2002-11-10 17:50   ` Fergus Henderson
  2002-11-10 19:10     ` Christopher Faylor
@ 2002-11-11 12:47     ` Casper Hornstrup
  2002-11-11 12:27       ` Fergus Henderson
  1 sibling, 1 reply; 26+ messages in thread
From: Casper Hornstrup @ 2002-11-11 12:47 UTC (permalink / raw)
  To: 'Fergus Henderson'; +Cc: gcc-patches



> -----Original Message-----
> From: Fergus Henderson [mailto:fjh@ceres.cs.mu.OZ.AU] On 
> Behalf Of Fergus Henderson
> Sent: 11. november 2002 02:51
> To: Casper Hornstrup
> Cc: gcc-patches@gcc.gnu.org
> Subject: Re: [PATCH] Fastcall support on cygwin and mingw targets
> 
> 
> Some comments above the definition of ASM_OUTPUT_LABELREF 
> would be nice.
> 

OK.

> What happens if a function has multiple attributes,
> e.g. both fastcall and stdcall or both fastcall and 
> regparm(3)? It may be worth adding a test for that case.
> 

stdcall attribute after fastcall attribute - fastcall calling
convention is used, but the symbol is prefixed with _ not @.

Obviously a bug, but how should this situation be handled?
Which attribute should win and should gcc emit a warning or
error out?

fastcall attribute after stdcall attribute - same result.
fastcall attribute after regparm(3) attribute - fastcall wins.
regparm(3) attribute after fastcall attribute - fastcall wins.

> >+ The @code{fastcall} calling convention exists in Windows 
> NT for Intel 
> >+ processors only.
> 
> That part of the documentation is wrong.
> Cygwin and Mingw work on most variants of Windows, not just 
> Windows NT.

I think it is a reference to fastcall only being used on Intel
Windows NT platforms (eg. it was not used on Windows NT/Alpha).
Maybe it should be removed?

Casper

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

* RE: [PATCH] Fastcall support on cygwin and mingw targets
  2002-11-11 12:27       ` Fergus Henderson
@ 2002-11-12 10:45         ` Casper Hornstrup
  2002-11-12 22:08           ` Fergus Henderson
  0 siblings, 1 reply; 26+ messages in thread
From: Casper Hornstrup @ 2002-11-12 10:45 UTC (permalink / raw)
  To: 'Fergus Henderson'; +Cc: gcc-patches



> -----Original Message-----
> From: Fergus Henderson [mailto:fjh@ceres.cs.mu.OZ.AU] On 
> Behalf Of Fergus Henderson
> Sent: 11. november 2002 20:28
> To: Casper Hornstrup
> Cc: gcc-patches@gcc.gnu.org
> Subject: Re: [PATCH] Fastcall support on cygwin and mingw targets
> 
> 
> On 11-Nov-2002, Casper Hornstrup <chorns@users.sourceforge.net> wrote:
> > 
> > > What happens if a function has multiple attributes,
> > > e.g. both fastcall and stdcall or both fastcall and
> > > regparm(3)? It may be worth adding a test for that case.
> > > 
> > 
> > stdcall attribute after fastcall attribute - fastcall calling 
> > convention is used, but the symbol is prefixed with _ not @.
> > 
> > Obviously a bug, but how should this situation be handled? Which 
> > attribute should win and should gcc emit a warning or error out?
> >
> > fastcall attribute after stdcall attribute - same result. fastcall 
> > attribute after regparm(3) attribute - fastcall wins.
> > regparm(3) attribute after fastcall attribute - fastcall wins.
> 
> IMHO the desirable behaviour is for gcc to report an error
> in all of these cases.

Where/how should this check be performed? It can't be done in the
attribute handler since all attributes may not be added to the
attribute list yet.

> 
> > > >+ The @code{fastcall} calling convention exists in 
> Windows NT for 
> > > >+ Intel
> > > >+ processors only.
> > > 
> > > That part of the documentation is wrong.
> > > Cygwin and Mingw work on most variants of Windows, not just
> > > Windows NT.
> > 
> > I think it is a reference to fastcall only being used on 
> Intel Windows 
> > NT platforms (eg. it was not used on Windows NT/Alpha). Maybe it 
> > should be removed?
> 
> Either that, or just delete the "NT".

I'll delete "NT".

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

* Re: [PATCH] Fastcall support on cygwin and mingw targets
  2002-11-12 10:45         ` Casper Hornstrup
@ 2002-11-12 22:08           ` Fergus Henderson
  2002-11-13 12:17             ` Casper Hornstrup
  0 siblings, 1 reply; 26+ messages in thread
From: Fergus Henderson @ 2002-11-12 22:08 UTC (permalink / raw)
  To: Casper Hornstrup; +Cc: gcc-patches

On 12-Nov-2002, Casper Hornstrup <chorns@users.sourceforge.net> wrote:
> 
> Fergus Henderson:
> > What happens if a function has multiple attributes,
> > e.g. both fastcall and stdcall or both fastcall and
> > regparm(3)? It may be worth adding a test for that case.
> ...
> > IMHO the desirable behaviour is for gcc to report an error
> > in all of these cases.
> 
> Where/how should this check be performed? It can't be done in the
> attribute handler since all attributes may not be added to the
> attribute list yet.

Why can't the attribute handler report an error as soon as any two
attributes conflict?

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.

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

* RE: [PATCH] Fastcall support on cygwin and mingw targets
  2002-11-12 22:08           ` Fergus Henderson
@ 2002-11-13 12:17             ` Casper Hornstrup
  2002-11-13 15:47               ` Joseph S. Myers
  2002-11-13 20:27               ` Fergus Henderson
  0 siblings, 2 replies; 26+ messages in thread
From: Casper Hornstrup @ 2002-11-13 12:17 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 880 bytes --]



> -----Original Message-----
> From: Fergus Henderson [mailto:fjh@ceres.cs.mu.OZ.AU] On 
> Behalf Of Fergus Henderson
> Sent: 13. november 2002 07:08
> To: Casper Hornstrup
> Cc: gcc-patches@gcc.gnu.org
> Subject: Re: [PATCH] Fastcall support on cygwin and mingw targets
> 
> 
> On 12-Nov-2002, Casper Hornstrup <chorns@users.sourceforge.net> wrote:
> > 
> > Where/how should this check be performed? It can't be done in the 
> > attribute handler since all attributes may not be added to the 
> > attribute list yet.
> 
> Why can't the attribute handler report an error as soon as 
> any two attributes conflict?

Okay it can, though not as simple as:

if (lookup_attribute("fastcall", TYPE_ATTRIBUTES (*node))
  && lookup_attribute("stdcall", TYPE_ATTRIBUTES (*node)))
{
  error(...)
}

I have added checks for conflicts with stdcall and regparm attributes.

Casper Hornstrup

[-- Attachment #2: fastcall.tar.gz --]
[-- Type: application/octet-stream, Size: 5832 bytes --]

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

* RE: [PATCH] Fastcall support on cygwin and mingw targets
  2002-11-13 12:17             ` Casper Hornstrup
@ 2002-11-13 15:47               ` Joseph S. Myers
  2002-11-13 20:27               ` Fergus Henderson
  1 sibling, 0 replies; 26+ messages in thread
From: Joseph S. Myers @ 2002-11-13 15:47 UTC (permalink / raw)
  To: Casper Hornstrup; +Cc: gcc-patches

On Wed, 13 Nov 2002, Casper Hornstrup wrote:

> Okay it can, though not as simple as:
> 
> if (lookup_attribute("fastcall", TYPE_ATTRIBUTES (*node))
>   && lookup_attribute("stdcall", TYPE_ATTRIBUTES (*node)))
> {
>   error(...)
> }
> 
> I have added checks for conflicts with stdcall and regparm attributes.

Another case that should give errors is that of two regparm attributes
with different arguments, which conflict.  (This actually hit the Linux
kernel: a function was declared with different regparm attributes by
mistake, and things broke when which attribute overrode the other changed
as a result of GCC changes.  A hard error would detect such problems
earlier.)

-- 
Joseph S. Myers
jsm28@cam.ac.uk

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

* Re: [PATCH] Fastcall support on cygwin and mingw targets
  2002-11-13 12:17             ` Casper Hornstrup
  2002-11-13 15:47               ` Joseph S. Myers
@ 2002-11-13 20:27               ` Fergus Henderson
  2002-11-14  0:31                 ` Joseph S. Myers
  2002-11-14  8:28                 ` Casper Hornstrup
  1 sibling, 2 replies; 26+ messages in thread
From: Fergus Henderson @ 2002-11-13 20:27 UTC (permalink / raw)
  To: Casper Hornstrup; +Cc: gcc-patches

> +       if (strcmp (IDENTIFIER_POINTER (name), "fastcall") == 0)                
Won't that do the wrong thing for "__attribute__((__fastcall__))",
because of the difference in spelling ("fastcall" vs "__fastcall__")?

There should be test cases for both spellings.

> doc/extend.texi:
> + pass the fist two arguments in the registers ECX and EDX. Subsequent  

s/fist/first/

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.

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

* Re: [PATCH] Fastcall support on cygwin and mingw targets
  2002-11-13 20:27               ` Fergus Henderson
@ 2002-11-14  0:31                 ` Joseph S. Myers
  2002-11-14  8:28                 ` Casper Hornstrup
  1 sibling, 0 replies; 26+ messages in thread
From: Joseph S. Myers @ 2002-11-14  0:31 UTC (permalink / raw)
  To: Fergus Henderson; +Cc: Casper Hornstrup, gcc-patches

On Thu, 14 Nov 2002, Fergus Henderson wrote:

> > +       if (strcmp (IDENTIFIER_POINTER (name), "fastcall") == 0)                
> Won't that do the wrong thing for "__attribute__((__fastcall__))",
> because of the difference in spelling ("fastcall" vs "__fastcall__")?

is_attribute_p should be used here.

-- 
Joseph S. Myers
jsm28@cam.ac.uk

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

* RE: [PATCH] Fastcall support on cygwin and mingw targets
  2002-11-13 20:27               ` Fergus Henderson
  2002-11-14  0:31                 ` Joseph S. Myers
@ 2002-11-14  8:28                 ` Casper Hornstrup
  2002-11-25 15:39                   ` Richard Henderson
  1 sibling, 1 reply; 26+ messages in thread
From: Casper Hornstrup @ 2002-11-14  8:28 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 717 bytes --]



> -----Original Message-----
> From: Fergus Henderson [mailto:fjh@cs.mu.OZ.AU] 
> Sent: 14. november 2002 05:27
> To: Casper Hornstrup
> Cc: gcc-patches@gcc.gnu.org
> Subject: Re: [PATCH] Fastcall support on cygwin and mingw targets
> 
> 
> > +       if (strcmp (IDENTIFIER_POINTER (name), "fastcall") 
> == 0)                
> Won't that do the wrong thing for 
> "__attribute__((__fastcall__))", because of the difference in 
> spelling ("fastcall" vs "__fastcall__")?
> 

Yes it did.

> There should be test cases for both spellings.

I changed it to use is_attribute_p instead.

> > doc/extend.texi:
> > + pass the fist two arguments in the registers ECX and EDX. 
> Subsequent
> 
> s/fist/first/

Fixed this.

[-- Attachment #2: fastcall.tar.gz --]
[-- Type: application/octet-stream, Size: 5816 bytes --]

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

* Re: [PATCH] Fastcall support on cygwin and mingw targets
  2002-11-14  8:28                 ` Casper Hornstrup
@ 2002-11-25 15:39                   ` Richard Henderson
  2002-11-27 19:52                     ` Casper Hornstrup
  2002-12-02 13:25                     ` Casper Hornstrup
  0 siblings, 2 replies; 26+ messages in thread
From: Richard Henderson @ 2002-11-25 15:39 UTC (permalink / raw)
  To: Casper Hornstrup; +Cc: gcc-patches

First, please avoid putting the patch into a tarball.  It just
makes it harder to review.

On Thu, Nov 14, 2002 at 05:28:25PM +0100, Casper Hornstrup wrote:
> ! /* Output a reference to a label. Fastcall symbols are prefixed with @,
> !    whereas symbols for functions using other calling conventions don't
> !    have a prefix (unless they are marked dllimport or dllexport).
> !    Internally, @ is used as a prefix for symbols that are marked dllimport
> !    or dllexport so internally the prefix + is used for fastcall symbols. */
>   #undef ASM_OUTPUT_LABELREF
> ! #define ASM_OUTPUT_LABELREF(STREAM, NAME)		\

(1) This is now so big it should be moved to an external function.
(2) The frobbing of @ and + is confusing.  It is not *required*
    that @ be used for dllimport/export.  I'd prefer to first see
    a patch that replaced the literal @ with a macro; then the macro
    can expand to something other than @, and your life is happier.

> + The @code{fastcall} calling convention exists in Windows for Intel
> + processors only.

This is false.  It exists on all ia32 targets.  The name mangling
only happens on Windows, but that is not required for the calling
convention to be in effect.



r~

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

* RE: [PATCH] Fastcall support on cygwin and mingw targets
  2002-11-25 15:39                   ` Richard Henderson
@ 2002-11-27 19:52                     ` Casper Hornstrup
  2002-11-27 21:15                       ` Casper Hornstrup
  2002-11-27 22:19                       ` Richard Henderson
  2002-12-02 13:25                     ` Casper Hornstrup
  1 sibling, 2 replies; 26+ messages in thread
From: Casper Hornstrup @ 2002-11-27 19:52 UTC (permalink / raw)
  To: 'Richard Henderson'; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 2123 bytes --]



> -----Original Message-----
> From: Richard Henderson [mailto:rth@redhat.com] 
> Sent: 26. november 2002 00:39
> To: Casper Hornstrup
> Cc: gcc-patches@gcc.gnu.org
> Subject: Re: [PATCH] Fastcall support on cygwin and mingw targets
> 
> 
> First, please avoid putting the patch into a tarball.  It 
> just makes it harder to review.
> 

I will do that.

> On Thu, Nov 14, 2002 at 05:28:25PM +0100, Casper Hornstrup wrote:
> > ! /* Output a reference to a label. Fastcall symbols are 
> prefixed with @,
> > !    whereas symbols for functions using other calling 
> conventions don't
> > !    have a prefix (unless they are marked dllimport or dllexport).
> > !    Internally, @ is used as a prefix for symbols that are 
> marked dllimport
> > !    or dllexport so internally the prefix + is used for 
> fastcall symbols. */
> >   #undef ASM_OUTPUT_LABELREF
> > ! #define ASM_OUTPUT_LABELREF(STREAM, NAME)		\
> 
> (1) This is now so big it should be moved to an external function.
> (2) The frobbing of @ and + is confusing.  It is not *required*
>     that @ be used for dllimport/export.  I'd prefer to first see
>     a patch that replaced the literal @ with a macro; then the macro
>     can expand to something other than @, and your life is happier.
> 

Okay, lets take care of the dllimport/dllexport macro patch first then.
I have attached a patch that does this.

> > + The @code{fastcall} calling convention exists in Windows 
> for Intel 
> > + processors only.
> 
> This is false.  It exists on all ia32 targets.  The name 
> mangling only happens on Windows, but that is not required 
> for the calling convention to be in effect.

I will remove that sentence in the next version of the patch.



2002-11-27  Casper S. Hornstrup  <chorns@users.sourceforge.net>

	* config/i386/i386.h (DLL_IMPORT_EXPORT_PREFIX): Define.
	* config/i386/winnt.c (i386_pe_dllexport_name_p): Use
	DLL_IMPORT_EXPORT_PREFIX, not '@'.
	(i386_pe_dllimport_name_p): Likewise.
	(i386_pe_mark_dllexport): Likewise.
	(i386_pe_mark_dllimport): Likewise.
	(i386_pe_encode_section_info): Likewise.
	(i386_pe_strip_name_encoding): Likewise.

[-- Attachment #2: dll.diff --]
[-- Type: application/octet-stream, Size: 4546 bytes --]

Index: config/i386/i386.h
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/i386/i386.h,v
retrieving revision 1.307
diff -c -3 -p -r1.307 i386.h
*** config/i386/i386.h	21 Nov 2002 22:54:20 -0000	1.307
--- config/i386/i386.h	27 Nov 2002 19:23:34 -0000
*************** enum fp_cw_mode {FP_CW_STORED, FP_CW_UNI
*** 3444,3449 ****
--- 3444,3452 ----
  
  \f
  #define MACHINE_DEPENDENT_REORG(X) x86_machine_dependent_reorg(X)
+ 
+ #define DLL_IMPORT_EXPORT_PREFIX '@'
+ 
  /*
  Local variables:
  version-control: t
Index: config/i386/winnt.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/i386/winnt.c,v
retrieving revision 1.36
diff -c -3 -p -r1.36 winnt.c
*** config/i386/winnt.c	19 Sep 2002 13:51:23 -0000	1.36
--- config/i386/winnt.c	27 Nov 2002 19:23:34 -0000
*************** int
*** 199,205 ****
  i386_pe_dllexport_name_p (symbol)
       const char *symbol;
  {
!   return symbol[0] == '@' && symbol[1] == 'e' && symbol[2] == '.';
  }
  
  /* Return nonzero if SYMBOL is marked as being dllimport'd.  */
--- 199,206 ----
  i386_pe_dllexport_name_p (symbol)
       const char *symbol;
  {
!   return symbol[0] == DLL_IMPORT_EXPORT_PREFIX
!          && symbol[1] == 'e' && symbol[2] == '.';
  }
  
  /* Return nonzero if SYMBOL is marked as being dllimport'd.  */
*************** int
*** 208,214 ****
  i386_pe_dllimport_name_p (symbol)
       const char *symbol;
  {
!   return symbol[0] == '@' && symbol[1] == 'i' && symbol[2] == '.';
  }
  
  /* Mark a DECL as being dllexport'd.
--- 209,216 ----
  i386_pe_dllimport_name_p (symbol)
       const char *symbol;
  {
!   return symbol[0] == DLL_IMPORT_EXPORT_PREFIX
!          && symbol[1] == 'i' && symbol[2] == '.';
  }
  
  /* Mark a DECL as being dllexport'd.
*************** i386_pe_mark_dllexport (decl)
*** 237,243 ****
      return; /* already done */
  
    newname = alloca (strlen (oldname) + 4);
!   sprintf (newname, "@e.%s", oldname);
  
    /* We pass newname through get_identifier to ensure it has a unique
       address.  RTL processing can sometimes peek inside the symbol ref
--- 239,245 ----
      return; /* already done */
  
    newname = alloca (strlen (oldname) + 4);
!   sprintf (newname, "%ce.%s", DLL_IMPORT_EXPORT_PREFIX, oldname);
  
    /* We pass newname through get_identifier to ensure it has a unique
       address.  RTL processing can sometimes peek inside the symbol ref
*************** i386_pe_mark_dllimport (decl)
*** 312,318 ****
      }
  
    newname = alloca (strlen (oldname) + 11);
!   sprintf (newname, "@i._imp__%s", oldname);
  
    /* We pass newname through get_identifier to ensure it has a unique
       address.  RTL processing can sometimes peek inside the symbol ref
--- 314,320 ----
      }
  
    newname = alloca (strlen (oldname) + 11);
!   sprintf (newname, "%ci._imp__%s", DLL_IMPORT_EXPORT_PREFIX, oldname);
  
    /* We pass newname through get_identifier to ensure it has a unique
       address.  RTL processing can sometimes peek inside the symbol ref
*************** i386_pe_encode_section_info (decl, first
*** 399,406 ****
      i386_pe_mark_dllimport (decl);
    /* It might be that DECL has already been marked as dllimport, but a
       subsequent definition nullified that.  The attribute is gone but
!      DECL_RTL still has @i._imp__foo.  We need to remove that. Ditto
!      for the DECL_NON_ADDR_CONST_P flag.  */
    else if ((TREE_CODE (decl) == FUNCTION_DECL
  	    || TREE_CODE (decl) == VAR_DECL)
  	   && DECL_RTL (decl) != NULL_RTX
--- 401,408 ----
      i386_pe_mark_dllimport (decl);
    /* It might be that DECL has already been marked as dllimport, but a
       subsequent definition nullified that.  The attribute is gone but
!      DECL_RTL still has (DLL_IMPORT_EXPORT_PREFIX)i._imp__foo.  We need
!      to remove that. Ditto for the DECL_NON_ADDR_CONST_P flag.  */
    else if ((TREE_CODE (decl) == FUNCTION_DECL
  	    || TREE_CODE (decl) == VAR_DECL)
  	   && DECL_RTL (decl) != NULL_RTX
*************** const char *
*** 428,434 ****
  i386_pe_strip_name_encoding (str)
       const char *str;
  {
!   if (*str == '@')
      str += 3;
    if (*str == '*')
      str += 1;
--- 430,436 ----
  i386_pe_strip_name_encoding (str)
       const char *str;
  {
!   if (*str == DLL_IMPORT_EXPORT_PREFIX)
      str += 3;
    if (*str == '*')
      str += 1;

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

* RE: [PATCH] Fastcall support on cygwin and mingw targets
  2002-11-27 19:52                     ` Casper Hornstrup
@ 2002-11-27 21:15                       ` Casper Hornstrup
  2002-11-27 22:19                       ` Richard Henderson
  1 sibling, 0 replies; 26+ messages in thread
From: Casper Hornstrup @ 2002-11-27 21:15 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 2123 bytes --]



> -----Original Message-----
> From: Richard Henderson [mailto:rth@redhat.com] 
> Sent: 26. november 2002 00:39
> To: Casper Hornstrup
> Cc: gcc-patches@gcc.gnu.org
> Subject: Re: [PATCH] Fastcall support on cygwin and mingw targets
> 
> 
> First, please avoid putting the patch into a tarball.  It 
> just makes it harder to review.
> 

I will do that.

> On Thu, Nov 14, 2002 at 05:28:25PM +0100, Casper Hornstrup wrote:
> > ! /* Output a reference to a label. Fastcall symbols are 
> prefixed with @,
> > !    whereas symbols for functions using other calling 
> conventions don't
> > !    have a prefix (unless they are marked dllimport or dllexport).
> > !    Internally, @ is used as a prefix for symbols that are 
> marked dllimport
> > !    or dllexport so internally the prefix + is used for 
> fastcall symbols. */
> >   #undef ASM_OUTPUT_LABELREF
> > ! #define ASM_OUTPUT_LABELREF(STREAM, NAME)		\
> 
> (1) This is now so big it should be moved to an external function.
> (2) The frobbing of @ and + is confusing.  It is not *required*
>     that @ be used for dllimport/export.  I'd prefer to first see
>     a patch that replaced the literal @ with a macro; then the macro
>     can expand to something other than @, and your life is happier.
> 

Okay, lets take care of the dllimport/dllexport macro patch first then.
I have attached a patch that does this.

> > + The @code{fastcall} calling convention exists in Windows 
> for Intel 
> > + processors only.
> 
> This is false.  It exists on all ia32 targets.  The name 
> mangling only happens on Windows, but that is not required 
> for the calling convention to be in effect.

I will remove that sentence in the next version of the patch.



2002-11-27  Casper S. Hornstrup  <chorns@users.sourceforge.net>

	* config/i386/i386.h (DLL_IMPORT_EXPORT_PREFIX): Define.
	* config/i386/winnt.c (i386_pe_dllexport_name_p): Use
	DLL_IMPORT_EXPORT_PREFIX, not '@'.
	(i386_pe_dllimport_name_p): Likewise.
	(i386_pe_mark_dllexport): Likewise.
	(i386_pe_mark_dllimport): Likewise.
	(i386_pe_encode_section_info): Likewise.
	(i386_pe_strip_name_encoding): Likewise.

[-- Attachment #2: dll.diff --]
[-- Type: application/octet-stream, Size: 4546 bytes --]

Index: config/i386/i386.h
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/i386/i386.h,v
retrieving revision 1.307
diff -c -3 -p -r1.307 i386.h
*** config/i386/i386.h	21 Nov 2002 22:54:20 -0000	1.307
--- config/i386/i386.h	27 Nov 2002 19:23:34 -0000
*************** enum fp_cw_mode {FP_CW_STORED, FP_CW_UNI
*** 3444,3449 ****
--- 3444,3452 ----
  
  \f
  #define MACHINE_DEPENDENT_REORG(X) x86_machine_dependent_reorg(X)
+ 
+ #define DLL_IMPORT_EXPORT_PREFIX '@'
+ 
  /*
  Local variables:
  version-control: t
Index: config/i386/winnt.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/i386/winnt.c,v
retrieving revision 1.36
diff -c -3 -p -r1.36 winnt.c
*** config/i386/winnt.c	19 Sep 2002 13:51:23 -0000	1.36
--- config/i386/winnt.c	27 Nov 2002 19:23:34 -0000
*************** int
*** 199,205 ****
  i386_pe_dllexport_name_p (symbol)
       const char *symbol;
  {
!   return symbol[0] == '@' && symbol[1] == 'e' && symbol[2] == '.';
  }
  
  /* Return nonzero if SYMBOL is marked as being dllimport'd.  */
--- 199,206 ----
  i386_pe_dllexport_name_p (symbol)
       const char *symbol;
  {
!   return symbol[0] == DLL_IMPORT_EXPORT_PREFIX
!          && symbol[1] == 'e' && symbol[2] == '.';
  }
  
  /* Return nonzero if SYMBOL is marked as being dllimport'd.  */
*************** int
*** 208,214 ****
  i386_pe_dllimport_name_p (symbol)
       const char *symbol;
  {
!   return symbol[0] == '@' && symbol[1] == 'i' && symbol[2] == '.';
  }
  
  /* Mark a DECL as being dllexport'd.
--- 209,216 ----
  i386_pe_dllimport_name_p (symbol)
       const char *symbol;
  {
!   return symbol[0] == DLL_IMPORT_EXPORT_PREFIX
!          && symbol[1] == 'i' && symbol[2] == '.';
  }
  
  /* Mark a DECL as being dllexport'd.
*************** i386_pe_mark_dllexport (decl)
*** 237,243 ****
      return; /* already done */
  
    newname = alloca (strlen (oldname) + 4);
!   sprintf (newname, "@e.%s", oldname);
  
    /* We pass newname through get_identifier to ensure it has a unique
       address.  RTL processing can sometimes peek inside the symbol ref
--- 239,245 ----
      return; /* already done */
  
    newname = alloca (strlen (oldname) + 4);
!   sprintf (newname, "%ce.%s", DLL_IMPORT_EXPORT_PREFIX, oldname);
  
    /* We pass newname through get_identifier to ensure it has a unique
       address.  RTL processing can sometimes peek inside the symbol ref
*************** i386_pe_mark_dllimport (decl)
*** 312,318 ****
      }
  
    newname = alloca (strlen (oldname) + 11);
!   sprintf (newname, "@i._imp__%s", oldname);
  
    /* We pass newname through get_identifier to ensure it has a unique
       address.  RTL processing can sometimes peek inside the symbol ref
--- 314,320 ----
      }
  
    newname = alloca (strlen (oldname) + 11);
!   sprintf (newname, "%ci._imp__%s", DLL_IMPORT_EXPORT_PREFIX, oldname);
  
    /* We pass newname through get_identifier to ensure it has a unique
       address.  RTL processing can sometimes peek inside the symbol ref
*************** i386_pe_encode_section_info (decl, first
*** 399,406 ****
      i386_pe_mark_dllimport (decl);
    /* It might be that DECL has already been marked as dllimport, but a
       subsequent definition nullified that.  The attribute is gone but
!      DECL_RTL still has @i._imp__foo.  We need to remove that. Ditto
!      for the DECL_NON_ADDR_CONST_P flag.  */
    else if ((TREE_CODE (decl) == FUNCTION_DECL
  	    || TREE_CODE (decl) == VAR_DECL)
  	   && DECL_RTL (decl) != NULL_RTX
--- 401,408 ----
      i386_pe_mark_dllimport (decl);
    /* It might be that DECL has already been marked as dllimport, but a
       subsequent definition nullified that.  The attribute is gone but
!      DECL_RTL still has (DLL_IMPORT_EXPORT_PREFIX)i._imp__foo.  We need
!      to remove that. Ditto for the DECL_NON_ADDR_CONST_P flag.  */
    else if ((TREE_CODE (decl) == FUNCTION_DECL
  	    || TREE_CODE (decl) == VAR_DECL)
  	   && DECL_RTL (decl) != NULL_RTX
*************** const char *
*** 428,434 ****
  i386_pe_strip_name_encoding (str)
       const char *str;
  {
!   if (*str == '@')
      str += 3;
    if (*str == '*')
      str += 1;
--- 430,436 ----
  i386_pe_strip_name_encoding (str)
       const char *str;
  {
!   if (*str == DLL_IMPORT_EXPORT_PREFIX)
      str += 3;
    if (*str == '*')
      str += 1;

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

* Re: [PATCH] Fastcall support on cygwin and mingw targets
  2002-11-27 19:52                     ` Casper Hornstrup
  2002-11-27 21:15                       ` Casper Hornstrup
@ 2002-11-27 22:19                       ` Richard Henderson
  2002-11-28  2:00                         ` Richard Henderson
  1 sibling, 1 reply; 26+ messages in thread
From: Richard Henderson @ 2002-11-27 22:19 UTC (permalink / raw)
  To: Casper Hornstrup; +Cc: gcc-patches

On Wed, Nov 27, 2002 at 08:45:07PM +0100, Casper Hornstrup wrote:
> 	* config/i386/i386.h (DLL_IMPORT_EXPORT_PREFIX): Define.
> 	* config/i386/winnt.c (i386_pe_dllexport_name_p): Use
> 	DLL_IMPORT_EXPORT_PREFIX, not '@'.
> 	(i386_pe_dllimport_name_p): Likewise.
> 	(i386_pe_mark_dllexport): Likewise.
> 	(i386_pe_mark_dllimport): Likewise.
> 	(i386_pe_encode_section_info): Likewise.
> 	(i386_pe_strip_name_encoding): Likewise.

Applied, thanks.


r~

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

* Re: [PATCH] Fastcall support on cygwin and mingw targets
  2002-11-27 22:19                       ` Richard Henderson
@ 2002-11-28  2:00                         ` Richard Henderson
  0 siblings, 0 replies; 26+ messages in thread
From: Richard Henderson @ 2002-11-28  2:00 UTC (permalink / raw)
  To: gcc-patches

On Wed, Nov 27, 2002 at 08:45:07PM +0100, Casper Hornstrup wrote:
> 	* config/i386/i386.h (DLL_IMPORT_EXPORT_PREFIX): Define.
> 	* config/i386/winnt.c (i386_pe_dllexport_name_p): Use
> 	DLL_IMPORT_EXPORT_PREFIX, not '@'.
> 	(i386_pe_dllimport_name_p): Likewise.
> 	(i386_pe_mark_dllexport): Likewise.
> 	(i386_pe_mark_dllimport): Likewise.
> 	(i386_pe_encode_section_info): Likewise.
> 	(i386_pe_strip_name_encoding): Likewise.

Applied, thanks.


r~

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

* RE: [PATCH] Fastcall support on cygwin and mingw targets
  2002-11-25 15:39                   ` Richard Henderson
  2002-11-27 19:52                     ` Casper Hornstrup
@ 2002-12-02 13:25                     ` Casper Hornstrup
  2002-12-02 13:48                       ` Richard Henderson
  1 sibling, 1 reply; 26+ messages in thread
From: Casper Hornstrup @ 2002-12-02 13:25 UTC (permalink / raw)
  To: 'Richard Henderson'; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 4121 bytes --]



> -----Original Message-----
> From: gcc-patches-owner@gcc.gnu.org 
> [mailto:gcc-patches-owner@gcc.gnu.org] On Behalf Of Richard Henderson
> Sent: 26. november 2002 00:39
> To: Casper Hornstrup
> Cc: gcc-patches@gcc.gnu.org
> Subject: Re: [PATCH] Fastcall support on cygwin and mingw targets
> 
> 
> First, please avoid putting the patch into a tarball.  It 
> just makes it harder to review.
> 
> On Thu, Nov 14, 2002 at 05:28:25PM +0100, Casper Hornstrup wrote:
> > ! /* Output a reference to a label. Fastcall symbols are 
> prefixed with @,
> > !    whereas symbols for functions using other calling 
> conventions don't
> > !    have a prefix (unless they are marked dllimport or dllexport).
> > !    Internally, @ is used as a prefix for symbols that are 
> marked dllimport
> > !    or dllexport so internally the prefix + is used for 
> fastcall symbols. */
> >   #undef ASM_OUTPUT_LABELREF
> > ! #define ASM_OUTPUT_LABELREF(STREAM, NAME)		\
> 
> (1) This is now so big it should be moved to an external function.
> (2) The frobbing of @ and + is confusing.  It is not *required*
>     that @ be used for dllimport/export.  I'd prefer to first see
>     a patch that replaced the literal @ with a macro; then the macro
>     can expand to something other than @, and your life is happier.
> 
> > + The @code{fastcall} calling convention exists in Windows 
> for Intel 
> > + processors only.
> 
> This is false.  It exists on all ia32 targets.  The name 
> mangling only happens on Windows, but that is not required 
> for the calling convention to be in effect.
> 
> 
> 
> r~
> 

I have fixed these issues. Patch attached.


gcc/testsuite/ChangeLog

2002-11-13  Casper S. Hornstrup  <chorns@users.sourceforge.net>

	* gcc.c-torture/compile/20021110-1.c: New test.
	* gcc.c-torture/compile/20021110-1.x: Likewise.
	* gcc.c-torture/compile/20021110-2.c: Likewise.
	* gcc.c-torture/compile/20021110-2.x: Likewise.
	* gcc.c-torture/compile/20021110-3.c: Likewise.
	* gcc.c-torture/compile/20021110-3.x: Likewise.
	* gcc.c-torture/compile/20021110-4.c: Likewise.
	* gcc.c-torture/compile/20021110-4.x: Likewise.


gcc/ChangeLog

2002-11-13  Casper S. Hornstrup  <chorns@users.sourceforge.net>

	* config/i386/i386.c (ix86_handle_cdecl_attribute): Check for
	attributes incompatible with fastcall attribute.
	(ix86_handle_regparm_attribute): Likewise.

2002-11-13  Danny Smith  <dannysmith@users.sourceforge.net>

	* config/i386/i386.c (ix86_comp_type_attributes): Check for
mismatched
	fastcall types.

2002-11-13  Eric Kohl  <ekohl@rz-online.de>

	* config/i386/cygwin.h (TARGET_OS_CPP_BUILTINS): Add fastcall
	attributes.
	(ASM_OUTPUT_LABELREF): Define as i386_pe_output_labelref.
	* config/i386/i386-protos.h (i386_pe_output_labelref): Declare.
	* config/i386/winnt.c (i386_pe_mark_dllimport). Convert internal
	fastcall decoration to MS-compatible decoration. Add __imp_
prefix in
	i386_pe_output_labelref rather than here.
	* config/i386/i386.c (ix86_attribute_table): Accept 'fastcall'
as a
	valid attribute.
	(ix86_return_pops_args): Fastcall functions pop the stack.
	(init_cumulative_args): Reserve registers ECX and EDX if
function has
	fastcall attribute.
	(function_arg): Use registers ECX and EDX if function has
fastcall
	attribute.
	* config/i386/i386.h (CUMULATIVE_ARGS): Add fastcall attribute
flag.
	(FASTCALL_PREFIX): Define as '+'.
	* config/i386/mingw32.h (TARGET_OS_CPP_BUILTINS): Add fastcall
	attributes.
	* config/i386/winnt.c (gen_fastcall_suffix): New function.
Decorates a
	label name with a preliminary fastcall prefix (+) and the
stdcall
	suffix.
	(i386_pe_encode_section_info): Call gen_fastcall_suffix() if a
symbol
	has a fastcall attribute.
	(i386_pe_strip_name_encoding): Return length of internal
fastcall
	prefix (+).
	(i386_pe_output_labelref): New function. Outputs a label
reference.
	(i386_pe_fastcall_name_p): New function. Checks a symbol for
presence
	of internal fastcall prefix ('+' prefix).
	(i386_pe_asm_file_end): Converts internal fastcall prefix ('+'
prefix)
	into the Microsoft compatible '@' prefix.
	* doc/extend.texi: Add documentation of fastcall attribute.

[-- Attachment #2: fastcall.diff --]
[-- Type: application/octet-stream, Size: 19459 bytes --]

? testsuite/gcc.c-torture/compile/20021110-1.c
? testsuite/gcc.c-torture/compile/20021110-1.x
? testsuite/gcc.c-torture/compile/20021110-2.c
? testsuite/gcc.c-torture/compile/20021110-2.x
? testsuite/gcc.c-torture/compile/20021110-3.c
? testsuite/gcc.c-torture/compile/20021110-3.x
? testsuite/gcc.c-torture/compile/20021110-4.c
? testsuite/gcc.c-torture/compile/20021110-4.x
Index: config/i386/cygwin.h
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/i386/cygwin.h,v
retrieving revision 1.74
diff -c -3 -p -r1.74 cygwin.h
*** config/i386/cygwin.h	24 Sep 2002 12:48:55 -0000	1.74
--- config/i386/cygwin.h	2 Dec 2002 21:10:16 -0000
*************** Boston, MA 02111-1307, USA.  */
*** 61,71 ****
--- 61,73 ----
  	builtin_define ("_X86_=1");					\
  	builtin_assert ("system=winnt");				\
  	builtin_define ("__stdcall=__attribute__((__stdcall__))");	\
+ 	builtin_define ("__fastcall=__attribute__((__fastcall__))");	\
  	builtin_define ("__cdecl=__attribute__((__cdecl__))");		\
  	builtin_define ("__declspec(x)=__attribute__((x))");		\
  	if (!flag_iso)							\
  	  {								\
  	    builtin_define ("_stdcall=__attribute__((__stdcall__))");	\
+ 	    builtin_define ("_fastcall=__attribute__((__fastcall__))");	\
  	    builtin_define ("_cdecl=__attribute__((__cdecl__))");	\
  	  }								\
  	MAYBE_UWIN_CPP_BUILTINS ();					\
*************** do {									\
*** 271,279 ****
  \f
  /* Output a reference to a label.  */
  #undef ASM_OUTPUT_LABELREF
! #define ASM_OUTPUT_LABELREF(STREAM, NAME)  		\
!   fprintf (STREAM, "%s%s", USER_LABEL_PREFIX, 		\
! 	   i386_pe_strip_name_encoding (NAME))		\
  
  /* Output a common block.  */
  #undef ASM_OUTPUT_COMMON
--- 273,279 ----
  \f
  /* Output a reference to a label.  */
  #undef ASM_OUTPUT_LABELREF
! #define ASM_OUTPUT_LABELREF  i386_pe_output_labelref
  
  /* Output a common block.  */
  #undef ASM_OUTPUT_COMMON
Index: config/i386/i386-protos.h
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/i386/i386-protos.h,v
retrieving revision 1.86
diff -c -3 -p -r1.86 i386-protos.h
*** config/i386/i386-protos.h	21 Nov 2002 22:54:19 -0000	1.86
--- config/i386/i386-protos.h	2 Dec 2002 21:10:16 -0000
*************** extern void i386_pe_asm_file_end PARAMS 
*** 229,231 ****
--- 229,232 ----
  extern void i386_pe_encode_section_info PARAMS ((tree, int));
  extern const char *i386_pe_strip_name_encoding PARAMS ((const char *));
  extern const char *i386_pe_strip_name_encoding_full PARAMS ((const char *));
+ extern void i386_pe_output_labelref PARAMS ((FILE *, const char *));
Index: config/i386/i386.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/i386/i386.c,v
retrieving revision 1.493
diff -c -3 -p -r1.493 i386.c
*** config/i386/i386.c	2 Dec 2002 18:44:05 -0000	1.493
--- config/i386/i386.c	2 Dec 2002 21:10:24 -0000
*************** const struct attribute_spec ix86_attribu
*** 1355,1360 ****
--- 1355,1363 ----
    /* Stdcall attribute says callee is responsible for popping arguments
       if they are not variable.  */
    { "stdcall",   0, 0, false, true,  true,  ix86_handle_cdecl_attribute },
+   /* Fastcall attribute says callee is responsible for popping arguments
+      if they are not variable.  */
+   { "fastcall",  0, 0, false, true,  true,  ix86_handle_cdecl_attribute },
    /* Cdecl attribute says the callee is a normal C declaration */
    { "cdecl",     0, 0, false, true,  true,  ix86_handle_cdecl_attribute },
    /* Regparm attribute specifies how many integer arguments are to be
*************** const struct attribute_spec ix86_attribu
*** 1368,1374 ****
    { NULL,        0, 0, false, false, false, NULL }
  };
  
! /* Handle a "cdecl" or "stdcall" attribute;
     arguments as in struct attribute_spec.handler.  */
  static tree
  ix86_handle_cdecl_attribute (node, name, args, flags, no_add_attrs)
--- 1371,1377 ----
    { NULL,        0, 0, false, false, false, NULL }
  };
  
! /* Handle a "cdecl", "stdcall", or "fastcall" attribute;
     arguments as in struct attribute_spec.handler.  */
  static tree
  ix86_handle_cdecl_attribute (node, name, args, flags, no_add_attrs)
*************** ix86_handle_cdecl_attribute (node, name,
*** 1387,1392 ****
--- 1390,1416 ----
  	       IDENTIFIER_POINTER (name));
        *no_add_attrs = true;
      }
+   else
+     {
+       if (is_attribute_p ("fastcall", name))
+         {
+           if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
+             {
+               error ("fastcall and stdcall attributes are not compatible");
+             }
+            else if (lookup_attribute ("regparm", TYPE_ATTRIBUTES (*node)))
+             {
+               error ("fastcall and regparm attributes are not compatible");
+             }
+         }
+       else if (is_attribute_p ("stdcall", name))
+         {
+           if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
+             {
+               error ("fastcall and stdcall attributes are not compatible");
+             }
+         }
+     }
  
    if (TARGET_64BIT)
      {
*************** ix86_handle_regparm_attribute (node, nam
*** 1433,1438 ****
--- 1457,1467 ----
  		   IDENTIFIER_POINTER (name), REGPARM_MAX);
  	  *no_add_attrs = true;
  	}
+ 
+       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
+     {
+       error ("fastcall and regparm attributes are not compatible");
+     }
      }
  
    return NULL_TREE;
*************** ix86_comp_type_attributes (type1, type2)
*** 1453,1458 ****
--- 1482,1492 ----
    if (TREE_CODE (type1) != FUNCTION_TYPE)
      return 1;
  
+   /*  Check for mismatched fastcall types */ 
+   if (!lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type1))
+       != !lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type2)))
+     return 0; 
+ 
    /* Check for mismatched return types (cdecl vs stdcall).  */
    if (!lookup_attribute (rtdstr, TYPE_ATTRIBUTES (type1))
        != !lookup_attribute (rtdstr, TYPE_ATTRIBUTES (type2)))
*************** ix86_return_pops_args (fundecl, funtype,
*** 1503,1510 ****
      /* Cdecl functions override -mrtd, and never pop the stack.  */
    if (! lookup_attribute ("cdecl", TYPE_ATTRIBUTES (funtype))) {
  
!     /* Stdcall functions will pop the stack if not variable args.  */
!     if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (funtype)))
        rtd = 1;
  
      if (rtd
--- 1537,1545 ----
      /* Cdecl functions override -mrtd, and never pop the stack.  */
    if (! lookup_attribute ("cdecl", TYPE_ATTRIBUTES (funtype))) {
  
!     /* Stdcall and fastcall functions will pop the stack if not variable args. */
!     if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (funtype))
!         || lookup_attribute ("fastcall", TYPE_ATTRIBUTES (funtype)))
        rtd = 1;
  
      if (rtd
*************** init_cumulative_args (cum, fntype, libna
*** 1590,1595 ****
--- 1625,1641 ----
      }
    cum->maybe_vaarg = false;
  
+   /* Use ecx and edx registers if function has fastcall attribute */
+   if (fntype && !TARGET_64BIT)
+     {
+       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (fntype)))
+ 	{
+ 	  cum->nregs = 2;
+ 	  cum->fastcall = 1;
+ 	}
+     }
+ 
+ 
    /* Determine if this function has variable arguments.  This is
       indicated by the last argument being 'void_type_mode' if there
       are no variable arguments.  If there are variable arguments, then
*************** init_cumulative_args (cum, fntype, libna
*** 1604,1610 ****
  	  if (next_param == 0 && TREE_VALUE (param) != void_type_node)
  	    {
  	      if (!TARGET_64BIT)
! 		cum->nregs = 0;
  	      cum->maybe_vaarg = true;
  	    }
  	}
--- 1650,1659 ----
  	  if (next_param == 0 && TREE_VALUE (param) != void_type_node)
  	    {
  	      if (!TARGET_64BIT)
! 		{
! 		  cum->nregs = 0;
! 		  cum->fastcall = 0;
! 		}
  	      cum->maybe_vaarg = true;
  	    }
  	}
*************** function_arg (cum, mode, type, named)
*** 2254,2260 ****
        case HImode:
        case QImode:
  	if (words <= cum->nregs)
! 	  ret = gen_rtx_REG (mode, cum->regno);
  	break;
        case TImode:
  	if (cum->sse_nregs)
--- 2303,2324 ----
        case HImode:
        case QImode:
  	if (words <= cum->nregs)
!  	  {
!  	    int regno = cum->regno;
! 
!  	    /* Fastcall allocates the first two DWORD (SImode) or
!  	       smaller arguments to ECX and EDX.  */
!  	    if (cum->fastcall)
!  	      {
!  	        if (mode == BLKmode || mode == DImode)
!  	          break;
!  
!  	        /* ECX not EAX is the first allocated register.  */
!  	        if (regno == 0)
!  		      regno = 2;
!  	      }
!  	    ret = gen_rtx_REG (mode, regno);
!  	  }
  	break;
        case TImode:
  	if (cum->sse_nregs)
Index: config/i386/i386.h
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/i386/i386.h,v
retrieving revision 1.308
diff -c -3 -p -r1.308 i386.h
*** config/i386/i386.h	27 Nov 2002 20:04:16 -0000	1.308
--- config/i386/i386.h	2 Dec 2002 21:10:27 -0000
*************** typedef struct ix86_args {
*** 1665,1670 ****
--- 1665,1671 ----
    int words;			/* # words passed so far */
    int nregs;			/* # registers available for passing */
    int regno;			/* next available register number */
+   int fastcall;		/* fastcall calling convention is used */
    int sse_words;		/* # sse words passed so far */
    int sse_nregs;		/* # sse registers available for passing */
    int sse_regno;		/* next available sse register number */
*************** enum fp_cw_mode {FP_CW_STORED, FP_CW_UNI
*** 3446,3451 ****
--- 3447,3453 ----
  #define MACHINE_DEPENDENT_REORG(X) x86_machine_dependent_reorg(X)
  
  #define DLL_IMPORT_EXPORT_PREFIX '@'
+ #define FASTCALL_PREFIX '+'
  
  /*
  Local variables:
Index: config/i386/mingw32.h
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/i386/mingw32.h,v
retrieving revision 1.27
diff -c -3 -p -r1.27 mingw32.h
*** config/i386/mingw32.h	29 Jun 2002 09:10:04 -0000	1.27
--- config/i386/mingw32.h	2 Dec 2002 21:10:27 -0000
*************** Boston, MA 02111-1307, USA.  */
*** 50,60 ****
--- 50,62 ----
  	builtin_define_std ("WINNT");					\
  	builtin_define ("_X86_=1");					\
  	builtin_define ("__stdcall=__attribute__((__stdcall__))");	\
+ 	builtin_define ("__fastcall=__attribute__((__fastcall__))");	\
  	builtin_define ("__cdecl=__attribute__((__cdecl__))");		\
  	builtin_define ("__declspec(x)=__attribute__((x))");		\
  	if (!flag_iso)							\
  	  {								\
  	    builtin_define ("_stdcall=__attribute__((__stdcall__))");	\
+ 	    builtin_define ("_fastcall=__attribute__((__fastcall__))");	\
  	    builtin_define ("_cdecl=__attribute__((__cdecl__))");	\
  	  }								\
  	EXTRA_OS_CPP_BUILTINS ();					\
Index: config/i386/winnt.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/i386/winnt.c,v
retrieving revision 1.37
diff -c -3 -p -r1.37 winnt.c
*** config/i386/winnt.c	27 Nov 2002 20:04:16 -0000	1.37
--- config/i386/winnt.c	2 Dec 2002 21:10:27 -0000
*************** Boston, MA 02111-1307, USA.  */
*** 46,55 ****
--- 46,57 ----
  
  static tree associated_type PARAMS ((tree));
  const char * gen_stdcall_suffix PARAMS ((tree));
+ const char * gen_fastcall_suffix PARAMS ((tree));
  int i386_pe_dllexport_p PARAMS ((tree));
  int i386_pe_dllimport_p PARAMS ((tree));
  void i386_pe_mark_dllexport PARAMS ((tree));
  void i386_pe_mark_dllimport PARAMS ((tree));
+ static int i386_pe_fastcall_name_p PARAMS ((const char *));
  
  /* Handle a "dllimport" or "dllexport" attribute;
     arguments as in struct attribute_spec.handler.  */
*************** i386_pe_mark_dllimport (decl)
*** 313,320 ****
        return;
      }
  
!   newname = alloca (strlen (oldname) + 11);
!   sprintf (newname, "%ci._imp__%s", DLL_IMPORT_EXPORT_PREFIX, oldname);
  
    /* We pass newname through get_identifier to ensure it has a unique
       address.  RTL processing can sometimes peek inside the symbol ref
--- 315,322 ----
        return;
      }
  
!   newname = alloca (strlen (oldname) + 4);
!   sprintf (newname, "%ci.%s", DLL_IMPORT_EXPORT_PREFIX, oldname);
  
    /* We pass newname through get_identifier to ensure it has a unique
       address.  RTL processing can sometimes peek inside the symbol ref
*************** i386_pe_mark_dllimport (decl)
*** 332,337 ****
--- 334,378 ----
  }
  
  /* Return string which is the former assembler name modified with a 
+    prefix consisting of a plus (+) and a suffix consisting of an
+    atsign (@) followed by the number of bytes of arguments.
+    The leading plus (+) is later replaced by an atsign (@). This
+    trick is used because leading atsigns are already used internally. */
+ 
+ const char *
+ gen_fastcall_suffix (decl)
+   tree decl;
+ {
+   int total = 0;
+ 
+   const char *asmname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
+   char *newsym;
+ 
+   if (TYPE_ARG_TYPES (TREE_TYPE (decl)))
+     if (TREE_VALUE (tree_last (TYPE_ARG_TYPES (TREE_TYPE (decl))))
+         == void_type_node)
+       {
+ 	tree formal_type = TYPE_ARG_TYPES (TREE_TYPE (decl));
+ 
+ 	while (TREE_VALUE (formal_type) != void_type_node)
+ 	  {
+ 	    int parm_size
+ 	      = TREE_INT_CST_LOW (TYPE_SIZE (TREE_VALUE (formal_type)));
+ 	    /* Must round up to include padding.  This is done the same
+ 	       way as in store_one_arg.  */
+ 	    parm_size = ((parm_size + PARM_BOUNDARY - 1)
+ 			 / PARM_BOUNDARY * PARM_BOUNDARY);
+ 	    total += parm_size;
+ 	    formal_type = TREE_CHAIN (formal_type);
+ 	  }
+       }
+ 
+   newsym = xmalloc (strlen (asmname) + 11);
+   sprintf (newsym, "%c%s@%d", FASTCALL_PREFIX, asmname, total/BITS_PER_UNIT);
+   return IDENTIFIER_POINTER (get_identifier (newsym));
+ }
+ 
+ /* Return string which is the former assembler name modified with a 
     suffix consisting of an atsign (@) followed by the number of bytes of 
     arguments */
  
*************** i386_pe_encode_section_info (decl, first
*** 387,396 ****
      }
  
    if (TREE_CODE (decl) == FUNCTION_DECL)
!     if (lookup_attribute ("stdcall",
! 			  TYPE_ATTRIBUTES (TREE_TYPE (decl))))
!       XEXP (DECL_RTL (decl), 0) = 
! 	gen_rtx (SYMBOL_REF, Pmode, gen_stdcall_suffix (decl));
  
    /* Mark the decl so we can tell from the rtl whether the object is
       dllexport'd or dllimport'd.  */
--- 428,443 ----
      }
  
    if (TREE_CODE (decl) == FUNCTION_DECL)
!     {
!       if (lookup_attribute ("stdcall",
! 			    TYPE_ATTRIBUTES (TREE_TYPE (decl))))
!         XEXP (DECL_RTL (decl), 0) = 
! 	  gen_rtx (SYMBOL_REF, Pmode, gen_stdcall_suffix (decl));
!       else if (lookup_attribute ("fastcall",
! 				 TYPE_ATTRIBUTES (TREE_TYPE (decl))))
!         XEXP (DECL_RTL (decl), 0) =
! 	  gen_rtx (SYMBOL_REF, Pmode, gen_fastcall_suffix (decl));
!     }
  
    /* Mark the decl so we can tell from the rtl whether the object is
       dllexport'd or dllimport'd.  */
*************** i386_pe_strip_name_encoding (str)
*** 432,438 ****
  {
    if (*str == DLL_IMPORT_EXPORT_PREFIX)
      str += 3;
!   if (*str == '*')
      str += 1;
    return str;
  }
--- 479,485 ----
  {
    if (*str == DLL_IMPORT_EXPORT_PREFIX)
      str += 3;
!   if (*str == '*' || *str == FASTCALL_PREFIX)
      str += 1;
    return str;
  }
*************** i386_pe_strip_name_encoding_full (str)
*** 453,458 ****
--- 500,542 ----
    return name;
  }
  
+ /* Output a reference to a label. Fastcall symbols are prefixed with @,
+    whereas symbols for functions using other calling conventions don't
+    have a prefix (unless they are marked dllimport or dllexport).
+    Internally, @ is used as a prefix for symbols that are marked dllimport
+    or dllexport so internally the prefix + is used for fastcall symbols. */
+ 
+ void i386_pe_output_labelref (stream, name)
+      FILE *stream;
+      const char *name;
+ {
+   if (strncmp (name,"@i.",3) == 0)
+     {
+       if (name[3] == FASTCALL_PREFIX)
+         {
+           fprintf (stream, "__imp_@%s",
+                    i386_pe_strip_name_encoding (name));
+         }
+       else
+         {
+           fprintf (stream, "__imp__%s",
+                    i386_pe_strip_name_encoding (name));
+         }
+     }
+   else if ((name[0] == FASTCALL_PREFIX)
+            || ((name[0] == DLL_IMPORT_EXPORT_PREFIX)
+                && (name[3] == FASTCALL_PREFIX)))
+     {
+       fprintf (stream, "@%s",
+                i386_pe_strip_name_encoding (name));
+     }
+   else
+     {
+       fprintf (stream, "%s%s", USER_LABEL_PREFIX,
+                i386_pe_strip_name_encoding (name));
+     }
+ }
+ 
  void
  i386_pe_unique_section (decl, reloc)
       tree decl;
*************** i386_pe_record_exported_symbol (name, is
*** 660,665 ****
--- 744,760 ----
    export_head = p;
  }
  
+ /* Return non-zero if SYMBOL is marked as being fastcall.  */
+ 
+ static int
+ i386_pe_fastcall_name_p (symbol)
+      const char *symbol;
+ {
+   return (symbol[0] == FASTCALL_PREFIX)
+           || (symbol[0] == DLL_IMPORT_EXPORT_PREFIX
+               && symbol[3] == FASTCALL_PREFIX);
+ }
+ 
  /* This is called at the end of assembly.  For each external function
     which has not been defined, we output a declaration now.  We also
     output the .drectve section.  */
*************** i386_pe_asm_file_end (file)
*** 692,698 ****
        drectve_section ();
        for (q = export_head; q != NULL; q = q->next)
  	{
! 	  fprintf (file, "\t.ascii \" -export:%s%s\"\n",
  		   i386_pe_strip_name_encoding (q->name),
  		   (q->is_data) ? ",data" : "");
  	}
--- 787,794 ----
        drectve_section ();
        for (q = export_head; q != NULL; q = q->next)
  	{
!  	  fprintf (file, "\t.ascii \" -export:%s%s%s\"\n",
!  		   (i386_pe_fastcall_name_p(q->name)) ? "@" : "",
  		   i386_pe_strip_name_encoding (q->name),
  		   (q->is_data) ? ",data" : "");
  	}
Index: doc/extend.texi
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/doc/extend.texi,v
retrieving revision 1.108
diff -c -3 -p -r1.108 extend.texi
*** doc/extend.texi	27 Nov 2002 06:32:13 -0000	1.108
--- doc/extend.texi	2 Dec 2002 21:10:33 -0000
*************** pass arguments, unless it takes a variab
*** 2373,2378 ****
--- 2373,2386 ----
  The PowerPC compiler for Windows NT currently ignores the @code{stdcall}
  attribute.
  
+ @item fastcall
+ @cindex functions that pop the argument stack on the 386
+ On the Intel 386, the @code{fastcall} attribute causes the compiler to
+ pass the first two arguments in the registers ECX and EDX. Subsequent
+ arguments are passed on the stack. The called function will pop the 
+ arguments off the stack. If the number of arguments is variable all
+ arguments are pushed on the stack.
+ 
  @item cdecl
  @cindex functions that do pop the argument stack on the 386
  @opindex mrtd

[-- Attachment #3: 20021110-1.c --]
[-- Type: text/plain, Size: 45 bytes --]

void
__attribute__ ((fastcall))
f()
{
}

[-- Attachment #4: 20021110-1.x --]
[-- Type: application/octet-stream, Size: 161 bytes --]

# Only mingw32 and cygwin on i386 have fastcall support
if { !([istarget "i386-pc-mingw32*"] || [istarget "i386-pc-cygwin*"]) } {
  return 1;
}

return 0;

[-- Attachment #5: 20021110-2.c --]
[-- Type: text/plain, Size: 28 bytes --]

void
_fastcall
f()
{
}

[-- Attachment #6: 20021110-2.x --]
[-- Type: application/octet-stream, Size: 161 bytes --]

# Only mingw32 and cygwin on i386 have fastcall support
if { !([istarget "i386-pc-mingw32*"] || [istarget "i386-pc-cygwin*"]) } {
  return 1;
}

return 0;

[-- Attachment #7: 20021110-3.c --]
[-- Type: text/plain, Size: 29 bytes --]

void
__fastcall
f()
{
}

[-- Attachment #8: 20021110-3.x --]
[-- Type: application/octet-stream, Size: 161 bytes --]

# Only mingw32 and cygwin on i386 have fastcall support
if { !([istarget "i386-pc-mingw32*"] || [istarget "i386-pc-cygwin*"]) } {
  return 1;
}

return 0;

[-- Attachment #9: 20021110-4.c --]
[-- Type: text/plain, Size: 63 bytes --]

int
__attribute__ ((fastcall))
f(int x, int y, int z)
{
}

[-- Attachment #10: 20021110-4.x --]
[-- Type: application/octet-stream, Size: 161 bytes --]

# Only mingw32 and cygwin on i386 have fastcall support
if { !([istarget "i386-pc-mingw32*"] || [istarget "i386-pc-cygwin*"]) } {
  return 1;
}

return 0;

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

* Re: [PATCH] Fastcall support on cygwin and mingw targets
  2002-12-02 13:25                     ` Casper Hornstrup
@ 2002-12-02 13:48                       ` Richard Henderson
  2002-12-03 13:52                         ` Casper Hornstrup
  0 siblings, 1 reply; 26+ messages in thread
From: Richard Henderson @ 2002-12-02 13:48 UTC (permalink / raw)
  To: Casper Hornstrup; +Cc: gcc-patches

On Mon, Dec 02, 2002 at 10:25:23PM +0100, Casper Hornstrup wrote:
> > (2) The frobbing of @ and + is confusing.  It is not *required*
> >     that @ be used for dllimport/export.  I'd prefer to first see
> >     a patch that replaced the literal @ with a macro; then the macro
> >     can expand to something other than @, and your life is happier.
> 
> I have fixed these issues. Patch attached.

No, you still frob + and @.  The step you missed is to actually
*change* the dllimport character so that you can use @ directly.


r~

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

* RE: [PATCH] Fastcall support on cygwin and mingw targets
  2002-12-02 13:48                       ` Richard Henderson
@ 2002-12-03 13:52                         ` Casper Hornstrup
  2002-12-03 16:32                           ` Richard Henderson
  0 siblings, 1 reply; 26+ messages in thread
From: Casper Hornstrup @ 2002-12-03 13:52 UTC (permalink / raw)
  To: 'Richard Henderson'; +Cc: gcc-patches



> -----Original Message-----
> From: gcc-patches-owner@gcc.gnu.org 
> [mailto:gcc-patches-owner@gcc.gnu.org] On Behalf Of Richard Henderson
> Sent: 2. december 2002 22:48
> To: Casper Hornstrup
> Cc: gcc-patches@gcc.gnu.org
> Subject: Re: [PATCH] Fastcall support on cygwin and mingw targets
> 
> 
> On Mon, Dec 02, 2002 at 10:25:23PM +0100, Casper Hornstrup wrote:
> > > (2) The frobbing of @ and + is confusing.  It is not *required*
> > >     that @ be used for dllimport/export.  I'd prefer to first see
> > >     a patch that replaced the literal @ with a macro; 
> then the macro
> > >     can expand to something other than @, and your life 
> is happier.
> > 
> > I have fixed these issues. Patch attached.
> 
> No, you still frob + and @.  The step you missed is to actually
> *change* the dllimport character so that you can use @ directly.
> 
> 
> r~
> 

Okay, I misunderstood you. What should I change @ to? And should there
not
be a check somewhere to confirm that the dll import/export prefix will
never
be @ again? If so, where should it be?

Casper Hornstrup

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

* Re: [PATCH] Fastcall support on cygwin and mingw targets
  2002-12-03 13:52                         ` Casper Hornstrup
@ 2002-12-03 16:32                           ` Richard Henderson
  2002-12-08  4:08                             ` Casper Hornstrup
  0 siblings, 1 reply; 26+ messages in thread
From: Richard Henderson @ 2002-12-03 16:32 UTC (permalink / raw)
  To: Casper Hornstrup; +Cc: gcc-patches

On Tue, Dec 03, 2002 at 10:52:26PM +0100, Casper Hornstrup wrote:
> Okay, I misunderstood you. What should I change @ to?

I dunno.  Maybe '%'?

> And should there not be a check somewhere to confirm that the
> dll import/export prefix will never be @ again?

I wouldn't bother.


r~

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

* RE: [PATCH] Fastcall support on cygwin and mingw targets
  2002-12-03 16:32                           ` Richard Henderson
@ 2002-12-08  4:08                             ` Casper Hornstrup
  2002-12-19 14:01                               ` Richard Henderson
  0 siblings, 1 reply; 26+ messages in thread
From: Casper Hornstrup @ 2002-12-08  4:08 UTC (permalink / raw)
  To: 'Richard Henderson'; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 748 bytes --]



> -----Original Message-----
> From: gcc-patches-owner@gcc.gnu.org 
> [mailto:gcc-patches-owner@gcc.gnu.org] On Behalf Of Richard Henderson
> Sent: 4. december 2002 01:32
> To: Casper Hornstrup
> Cc: gcc-patches@gcc.gnu.org
> Subject: Re: [PATCH] Fastcall support on cygwin and mingw targets
> 
> 
> On Tue, Dec 03, 2002 at 10:52:26PM +0100, Casper Hornstrup wrote:
> > Okay, I misunderstood you. What should I change @ to?
> 
> I dunno.  Maybe '%'?
> 

Attached is a new version of this patch.

#define DLL_IMPORT_EXPORT_PREFIX '%' makes gcc ICE when compiling my
test
program:

internal compiler error: in legitimize_address, at
config/i386/i386.c:5940

I don't know what is special about that character. '#' works so I have
used
that instead.

[-- Attachment #2: ChangeLog.fastcall --]
[-- Type: application/octet-stream, Size: 2121 bytes --]

gcc/testsuite/ChangeLog

2002-12-08  Casper S. Hornstrup  <chorns@users.sourceforge.net>

	* gcc.c-torture/compile/20021208-1.c: New test.
	* gcc.c-torture/compile/20021208-1.x: Likewise.
	* gcc.c-torture/compile/20021208-2.c: Likewise.
	* gcc.c-torture/compile/20021208-2.x: Likewise.
	* gcc.c-torture/compile/20021208-3.c: Likewise.
	* gcc.c-torture/compile/20021208-3.x: Likewise.
	* gcc.c-torture/compile/20021208-4.c: Likewise.
	* gcc.c-torture/compile/20021208-4.x: Likewise.


gcc/ChangeLog

2002-12-08  Casper S. Hornstrup  <chorns@users.sourceforge.net>

	* config/i386/i386.c (ix86_handle_cdecl_attribute): Check for
	attributes incompatible with fastcall attribute.
	(ix86_handle_regparm_attribute): Likewise.

2002-12-08  Danny Smith  <dannysmith@users.sourceforge.net>

	* config/i386/i386.c (ix86_comp_type_attributes): Check for mismatched
	fastcall types.

2002-12-08  Eric Kohl  <ekohl@rz-online.de>

	* config/i386/cygwin.h (TARGET_OS_CPP_BUILTINS): Add fastcall
	attributes.
	(ASM_OUTPUT_LABELREF): Define as i386_pe_output_labelref.
	* config/i386/i386-protos.h (i386_pe_output_labelref): Declare.
	* config/i386/winnt.c (i386_pe_mark_dllimport). Add __imp_ prefix in
	i386_pe_output_labelref rather than here.
	(gen_fastcall_suffix): New function. Decorates a label name with the
	fastcall prefix (@) and the stdcall suffix.
	(i386_pe_encode_section_info): Call gen_fastcall_suffix() if a symbol
	has a fastcall attribute.
	(i386_pe_output_labelref): New function. Outputs a label reference.
	* config/i386/i386.c (ix86_attribute_table): Accept 'fastcall' as a
	valid attribute.
	(ix86_return_pops_args): Fastcall functions pop the stack.
	(init_cumulative_args): Reserve registers ECX and EDX if function has
	fastcall attribute.
	(function_arg): Use registers ECX and EDX if function has fastcall
	attribute.
	* config/i386/i386.h (CUMULATIVE_ARGS): Add fastcall attribute flag.
	(DLL_IMPORT_EXPORT_PREFIX): Redefine as '#'.
	(FASTCALL_PREFIX): Define as '@'.
	* config/i386/mingw32.h (TARGET_OS_CPP_BUILTINS): Add fastcall
	attributes.
	* doc/extend.texi: Add documentation of fastcall attribute.

[-- Attachment #3: fastcall.diff --]
[-- Type: application/octet-stream, Size: 18024 bytes --]

? testsuite/gcc.c-torture/compile/20021208-1.c
? testsuite/gcc.c-torture/compile/20021208-1.x
? testsuite/gcc.c-torture/compile/20021208-2.c
? testsuite/gcc.c-torture/compile/20021208-2.x
? testsuite/gcc.c-torture/compile/20021208-3.c
? testsuite/gcc.c-torture/compile/20021208-3.x
? testsuite/gcc.c-torture/compile/20021208-4.c
? testsuite/gcc.c-torture/compile/20021208-4.x
Index: config/i386/cygwin.h
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/i386/cygwin.h,v
retrieving revision 1.75
diff -c -3 -p -r1.75 cygwin.h
*** config/i386/cygwin.h	5 Dec 2002 23:55:15 -0000	1.75
--- config/i386/cygwin.h	7 Dec 2002 10:54:25 -0000
*************** Boston, MA 02111-1307, USA.  */
*** 61,71 ****
--- 61,73 ----
  	builtin_define ("_X86_=1");					\
  	builtin_assert ("system=winnt");				\
  	builtin_define ("__stdcall=__attribute__((__stdcall__))");	\
+ 	builtin_define ("__fastcall=__attribute__((__fastcall__))");	\
  	builtin_define ("__cdecl=__attribute__((__cdecl__))");		\
  	builtin_define ("__declspec(x)=__attribute__((x))");		\
  	if (!flag_iso)							\
  	  {								\
  	    builtin_define ("_stdcall=__attribute__((__stdcall__))");	\
+ 	    builtin_define ("_fastcall=__attribute__((__fastcall__))");	\
  	    builtin_define ("_cdecl=__attribute__((__cdecl__))");	\
  	  }								\
  	MAYBE_UWIN_CPP_BUILTINS ();					\
*************** do {									\
*** 271,279 ****
  \f
  /* Output a reference to a label.  */
  #undef ASM_OUTPUT_LABELREF
! #define ASM_OUTPUT_LABELREF(STREAM, NAME)  		\
!   fprintf (STREAM, "%s%s", USER_LABEL_PREFIX, 		\
! 	   i386_pe_strip_name_encoding (NAME))		\
  
  /* Output a common block.  */
  #undef ASM_OUTPUT_COMMON
--- 273,279 ----
  \f
  /* Output a reference to a label.  */
  #undef ASM_OUTPUT_LABELREF
! #define ASM_OUTPUT_LABELREF  i386_pe_output_labelref
  
  /* Output a common block.  */
  #undef ASM_OUTPUT_COMMON
Index: config/i386/i386-protos.h
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/i386/i386-protos.h,v
retrieving revision 1.86
diff -c -3 -p -r1.86 i386-protos.h
*** config/i386/i386-protos.h	21 Nov 2002 22:54:19 -0000	1.86
--- config/i386/i386-protos.h	7 Dec 2002 10:54:25 -0000
*************** extern void i386_pe_asm_file_end PARAMS 
*** 229,231 ****
--- 229,232 ----
  extern void i386_pe_encode_section_info PARAMS ((tree, int));
  extern const char *i386_pe_strip_name_encoding PARAMS ((const char *));
  extern const char *i386_pe_strip_name_encoding_full PARAMS ((const char *));
+ extern void i386_pe_output_labelref PARAMS ((FILE *, const char *));
Index: config/i386/i386.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/i386/i386.c,v
retrieving revision 1.493
diff -c -3 -p -r1.493 i386.c
*** config/i386/i386.c	2 Dec 2002 18:44:05 -0000	1.493
--- config/i386/i386.c	7 Dec 2002 10:54:33 -0000
*************** const struct attribute_spec ix86_attribu
*** 1355,1360 ****
--- 1355,1363 ----
    /* Stdcall attribute says callee is responsible for popping arguments
       if they are not variable.  */
    { "stdcall",   0, 0, false, true,  true,  ix86_handle_cdecl_attribute },
+   /* Fastcall attribute says callee is responsible for popping arguments
+      if they are not variable.  */
+   { "fastcall",  0, 0, false, true,  true,  ix86_handle_cdecl_attribute },
    /* Cdecl attribute says the callee is a normal C declaration */
    { "cdecl",     0, 0, false, true,  true,  ix86_handle_cdecl_attribute },
    /* Regparm attribute specifies how many integer arguments are to be
*************** const struct attribute_spec ix86_attribu
*** 1368,1374 ****
    { NULL,        0, 0, false, false, false, NULL }
  };
  
! /* Handle a "cdecl" or "stdcall" attribute;
     arguments as in struct attribute_spec.handler.  */
  static tree
  ix86_handle_cdecl_attribute (node, name, args, flags, no_add_attrs)
--- 1371,1377 ----
    { NULL,        0, 0, false, false, false, NULL }
  };
  
! /* Handle a "cdecl", "stdcall", or "fastcall" attribute;
     arguments as in struct attribute_spec.handler.  */
  static tree
  ix86_handle_cdecl_attribute (node, name, args, flags, no_add_attrs)
*************** ix86_handle_cdecl_attribute (node, name,
*** 1387,1392 ****
--- 1390,1416 ----
  	       IDENTIFIER_POINTER (name));
        *no_add_attrs = true;
      }
+   else
+     {
+       if (is_attribute_p ("fastcall", name))
+         {
+           if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
+             {
+               error ("fastcall and stdcall attributes are not compatible");
+             }
+            else if (lookup_attribute ("regparm", TYPE_ATTRIBUTES (*node)))
+             {
+               error ("fastcall and regparm attributes are not compatible");
+             }
+         }
+       else if (is_attribute_p ("stdcall", name))
+         {
+           if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
+             {
+               error ("fastcall and stdcall attributes are not compatible");
+             }
+         }
+     }
  
    if (TARGET_64BIT)
      {
*************** ix86_handle_regparm_attribute (node, nam
*** 1433,1438 ****
--- 1457,1467 ----
  		   IDENTIFIER_POINTER (name), REGPARM_MAX);
  	  *no_add_attrs = true;
  	}
+ 
+       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
+     {
+       error ("fastcall and regparm attributes are not compatible");
+     }
      }
  
    return NULL_TREE;
*************** ix86_comp_type_attributes (type1, type2)
*** 1453,1458 ****
--- 1482,1492 ----
    if (TREE_CODE (type1) != FUNCTION_TYPE)
      return 1;
  
+   /*  Check for mismatched fastcall types */ 
+   if (!lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type1))
+       != !lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type2)))
+     return 0; 
+ 
    /* Check for mismatched return types (cdecl vs stdcall).  */
    if (!lookup_attribute (rtdstr, TYPE_ATTRIBUTES (type1))
        != !lookup_attribute (rtdstr, TYPE_ATTRIBUTES (type2)))
*************** ix86_return_pops_args (fundecl, funtype,
*** 1503,1510 ****
      /* Cdecl functions override -mrtd, and never pop the stack.  */
    if (! lookup_attribute ("cdecl", TYPE_ATTRIBUTES (funtype))) {
  
!     /* Stdcall functions will pop the stack if not variable args.  */
!     if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (funtype)))
        rtd = 1;
  
      if (rtd
--- 1537,1545 ----
      /* Cdecl functions override -mrtd, and never pop the stack.  */
    if (! lookup_attribute ("cdecl", TYPE_ATTRIBUTES (funtype))) {
  
!     /* Stdcall and fastcall functions will pop the stack if not variable args. */
!     if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (funtype))
!         || lookup_attribute ("fastcall", TYPE_ATTRIBUTES (funtype)))
        rtd = 1;
  
      if (rtd
*************** init_cumulative_args (cum, fntype, libna
*** 1590,1595 ****
--- 1625,1641 ----
      }
    cum->maybe_vaarg = false;
  
+   /* Use ecx and edx registers if function has fastcall attribute */
+   if (fntype && !TARGET_64BIT)
+     {
+       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (fntype)))
+ 	{
+ 	  cum->nregs = 2;
+ 	  cum->fastcall = 1;
+ 	}
+     }
+ 
+ 
    /* Determine if this function has variable arguments.  This is
       indicated by the last argument being 'void_type_mode' if there
       are no variable arguments.  If there are variable arguments, then
*************** init_cumulative_args (cum, fntype, libna
*** 1604,1610 ****
  	  if (next_param == 0 && TREE_VALUE (param) != void_type_node)
  	    {
  	      if (!TARGET_64BIT)
! 		cum->nregs = 0;
  	      cum->maybe_vaarg = true;
  	    }
  	}
--- 1650,1659 ----
  	  if (next_param == 0 && TREE_VALUE (param) != void_type_node)
  	    {
  	      if (!TARGET_64BIT)
! 		{
! 		  cum->nregs = 0;
! 		  cum->fastcall = 0;
! 		}
  	      cum->maybe_vaarg = true;
  	    }
  	}
*************** function_arg (cum, mode, type, named)
*** 2254,2260 ****
        case HImode:
        case QImode:
  	if (words <= cum->nregs)
! 	  ret = gen_rtx_REG (mode, cum->regno);
  	break;
        case TImode:
  	if (cum->sse_nregs)
--- 2303,2324 ----
        case HImode:
        case QImode:
  	if (words <= cum->nregs)
!  	  {
!  	    int regno = cum->regno;
! 
!  	    /* Fastcall allocates the first two DWORD (SImode) or
!  	       smaller arguments to ECX and EDX.  */
!  	    if (cum->fastcall)
!  	      {
!  	        if (mode == BLKmode || mode == DImode)
!  	          break;
!  
!  	        /* ECX not EAX is the first allocated register.  */
!  	        if (regno == 0)
!  		      regno = 2;
!  	      }
!  	    ret = gen_rtx_REG (mode, regno);
!  	  }
  	break;
        case TImode:
  	if (cum->sse_nregs)
Index: config/i386/i386.h
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/i386/i386.h,v
retrieving revision 1.308
diff -c -3 -p -r1.308 i386.h
*** config/i386/i386.h	27 Nov 2002 20:04:16 -0000	1.308
--- config/i386/i386.h	7 Dec 2002 10:54:36 -0000
*************** typedef struct ix86_args {
*** 1665,1670 ****
--- 1665,1671 ----
    int words;			/* # words passed so far */
    int nregs;			/* # registers available for passing */
    int regno;			/* next available register number */
+   int fastcall;		/* fastcall calling convention is used */
    int sse_words;		/* # sse words passed so far */
    int sse_nregs;		/* # sse registers available for passing */
    int sse_regno;		/* next available sse register number */
*************** enum fp_cw_mode {FP_CW_STORED, FP_CW_UNI
*** 3445,3451 ****
  \f
  #define MACHINE_DEPENDENT_REORG(X) x86_machine_dependent_reorg(X)
  
! #define DLL_IMPORT_EXPORT_PREFIX '@'
  
  /*
  Local variables:
--- 3446,3454 ----
  \f
  #define MACHINE_DEPENDENT_REORG(X) x86_machine_dependent_reorg(X)
  
! #define DLL_IMPORT_EXPORT_PREFIX '#'
! 
! #define FASTCALL_PREFIX '@'
  
  /*
  Local variables:
Index: config/i386/mingw32.h
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/i386/mingw32.h,v
retrieving revision 1.28
diff -c -3 -p -r1.28 mingw32.h
*** config/i386/mingw32.h	5 Dec 2002 23:55:15 -0000	1.28
--- config/i386/mingw32.h	7 Dec 2002 10:54:36 -0000
*************** Boston, MA 02111-1307, USA.  */
*** 50,60 ****
--- 50,62 ----
  	builtin_define_std ("WINNT");					\
  	builtin_define ("_X86_=1");					\
  	builtin_define ("__stdcall=__attribute__((__stdcall__))");	\
+ 	builtin_define ("__fastcall=__attribute__((__fastcall__))");	\
  	builtin_define ("__cdecl=__attribute__((__cdecl__))");		\
  	builtin_define ("__declspec(x)=__attribute__((x))");		\
  	if (!flag_iso)							\
  	  {								\
  	    builtin_define ("_stdcall=__attribute__((__stdcall__))");	\
+ 	    builtin_define ("_fastcall=__attribute__((__fastcall__))");	\
  	    builtin_define ("_cdecl=__attribute__((__cdecl__))");	\
  	  }								\
  	EXTRA_OS_CPP_BUILTINS ();					\
Index: config/i386/winnt.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/i386/winnt.c,v
retrieving revision 1.37
diff -c -3 -p -r1.37 winnt.c
*** config/i386/winnt.c	27 Nov 2002 20:04:16 -0000	1.37
--- config/i386/winnt.c	7 Dec 2002 10:54:36 -0000
*************** Boston, MA 02111-1307, USA.  */
*** 46,51 ****
--- 46,52 ----
  
  static tree associated_type PARAMS ((tree));
  const char * gen_stdcall_suffix PARAMS ((tree));
+ const char * gen_fastcall_suffix PARAMS ((tree));
  int i386_pe_dllexport_p PARAMS ((tree));
  int i386_pe_dllimport_p PARAMS ((tree));
  void i386_pe_mark_dllexport PARAMS ((tree));
*************** i386_pe_mark_dllimport (decl)
*** 313,320 ****
        return;
      }
  
!   newname = alloca (strlen (oldname) + 11);
!   sprintf (newname, "%ci._imp__%s", DLL_IMPORT_EXPORT_PREFIX, oldname);
  
    /* We pass newname through get_identifier to ensure it has a unique
       address.  RTL processing can sometimes peek inside the symbol ref
--- 314,321 ----
        return;
      }
  
!   newname = alloca (strlen (oldname) + 4);
!   sprintf (newname, "%ci.%s", DLL_IMPORT_EXPORT_PREFIX, oldname);
  
    /* We pass newname through get_identifier to ensure it has a unique
       address.  RTL processing can sometimes peek inside the symbol ref
*************** i386_pe_mark_dllimport (decl)
*** 332,337 ****
--- 333,375 ----
  }
  
  /* Return string which is the former assembler name modified with a 
+    prefix consisting of FASTCALL_PREFIX and a suffix consisting of an
+    atsign (@) followed by the number of bytes of arguments.  */
+ 
+ const char *
+ gen_fastcall_suffix (decl)
+   tree decl;
+ {
+   int total = 0;
+ 
+   const char *asmname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
+   char *newsym;
+ 
+   if (TYPE_ARG_TYPES (TREE_TYPE (decl)))
+     if (TREE_VALUE (tree_last (TYPE_ARG_TYPES (TREE_TYPE (decl))))
+         == void_type_node)
+       {
+ 	tree formal_type = TYPE_ARG_TYPES (TREE_TYPE (decl));
+ 
+ 	while (TREE_VALUE (formal_type) != void_type_node)
+ 	  {
+ 	    int parm_size
+ 	      = TREE_INT_CST_LOW (TYPE_SIZE (TREE_VALUE (formal_type)));
+ 	    /* Must round up to include padding.  This is done the same
+ 	       way as in store_one_arg.  */
+ 	    parm_size = ((parm_size + PARM_BOUNDARY - 1)
+ 			 / PARM_BOUNDARY * PARM_BOUNDARY);
+ 	    total += parm_size;
+ 	    formal_type = TREE_CHAIN (formal_type);
+ 	  }
+       }
+ 
+   newsym = xmalloc (strlen (asmname) + 11);
+   sprintf (newsym, "%c%s@%d", FASTCALL_PREFIX, asmname, total/BITS_PER_UNIT);
+   return IDENTIFIER_POINTER (get_identifier (newsym));
+ }
+ 
+ /* Return string which is the former assembler name modified with a 
     suffix consisting of an atsign (@) followed by the number of bytes of 
     arguments */
  
*************** i386_pe_encode_section_info (decl, first
*** 387,396 ****
      }
  
    if (TREE_CODE (decl) == FUNCTION_DECL)
!     if (lookup_attribute ("stdcall",
! 			  TYPE_ATTRIBUTES (TREE_TYPE (decl))))
!       XEXP (DECL_RTL (decl), 0) = 
! 	gen_rtx (SYMBOL_REF, Pmode, gen_stdcall_suffix (decl));
  
    /* Mark the decl so we can tell from the rtl whether the object is
       dllexport'd or dllimport'd.  */
--- 425,440 ----
      }
  
    if (TREE_CODE (decl) == FUNCTION_DECL)
!     {
!       if (lookup_attribute ("stdcall",
! 			    TYPE_ATTRIBUTES (TREE_TYPE (decl))))
!         XEXP (DECL_RTL (decl), 0) = 
! 	  gen_rtx (SYMBOL_REF, Pmode, gen_stdcall_suffix (decl));
!       else if (lookup_attribute ("fastcall",
! 				 TYPE_ATTRIBUTES (TREE_TYPE (decl))))
!         XEXP (DECL_RTL (decl), 0) =
! 	  gen_rtx (SYMBOL_REF, Pmode, gen_fastcall_suffix (decl));
!     }
  
    /* Mark the decl so we can tell from the rtl whether the object is
       dllexport'd or dllimport'd.  */
*************** i386_pe_encode_section_info (decl, first
*** 424,430 ****
      }
  }
  
! /* Strip only the leading encoding, leaving the stdcall suffix.  */
  
  const char *
  i386_pe_strip_name_encoding (str)
--- 468,475 ----
      }
  }
  
! /* Strip only the leading encoding, leaving the stdcall suffix and fastcall
!    prefix if it exists.  */
  
  const char *
  i386_pe_strip_name_encoding (str)
*************** i386_pe_strip_name_encoding_full (str)
*** 451,456 ****
--- 496,539 ----
      return ggc_alloc_string (name, p - name);
  
    return name;
+ }
+ 
+ /* Output a reference to a label. Fastcall symbols are prefixed with @,
+    whereas symbols for functions using other calling conventions don't
+    have a prefix (unless they are marked dllimport or dllexport).  */
+ 
+ void i386_pe_output_labelref (stream, name)
+      FILE *stream;
+      const char *name;
+ {
+   char prefix[4];
+ 
+   sprintf (prefix, "%ci.", DLL_IMPORT_EXPORT_PREFIX);
+   if (strncmp (name, prefix, strlen (prefix)) == 0)
+     {
+       if (name[3] == FASTCALL_PREFIX)
+         {
+           fprintf (stream, "__imp_%s",
+                    i386_pe_strip_name_encoding (name));
+         }
+       else
+         {
+           fprintf (stream, "__imp__%s",
+                    i386_pe_strip_name_encoding (name));
+         }
+     }
+   else if ((name[0] == FASTCALL_PREFIX)
+            || ((name[0] == DLL_IMPORT_EXPORT_PREFIX)
+                && (name[3] == FASTCALL_PREFIX)))
+     {
+       fprintf (stream, "%s",
+                i386_pe_strip_name_encoding (name));
+     }
+   else
+     {
+       fprintf (stream, "%s%s", USER_LABEL_PREFIX,
+                i386_pe_strip_name_encoding (name));
+     }
  }
  
  void
Index: doc/extend.texi
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/doc/extend.texi,v
retrieving revision 1.108
diff -c -3 -p -r1.108 extend.texi
*** doc/extend.texi	27 Nov 2002 06:32:13 -0000	1.108
--- doc/extend.texi	7 Dec 2002 10:54:42 -0000
*************** pass arguments, unless it takes a variab
*** 2373,2378 ****
--- 2373,2386 ----
  The PowerPC compiler for Windows NT currently ignores the @code{stdcall}
  attribute.
  
+ @item fastcall
+ @cindex functions that pop the argument stack on the 386
+ On the Intel 386, the @code{fastcall} attribute causes the compiler to
+ pass the first two arguments in the registers ECX and EDX. Subsequent
+ arguments are passed on the stack. The called function will pop the 
+ arguments off the stack. If the number of arguments is variable all
+ arguments are pushed on the stack.
+ 
  @item cdecl
  @cindex functions that do pop the argument stack on the 386
  @opindex mrtd

[-- Attachment #4: 20021208-1.c --]
[-- Type: text/plain, Size: 45 bytes --]

void
__attribute__ ((fastcall))
f()
{
}

[-- Attachment #5: 20021208-1.x --]
[-- Type: application/octet-stream, Size: 161 bytes --]

# Only mingw32 and cygwin on i386 have fastcall support
if { !([istarget "i386-pc-mingw32*"] || [istarget "i386-pc-cygwin*"]) } {
  return 1;
}

return 0;

[-- Attachment #6: 20021208-2.c --]
[-- Type: text/plain, Size: 28 bytes --]

void
_fastcall
f()
{
}

[-- Attachment #7: 20021208-2.x --]
[-- Type: application/octet-stream, Size: 161 bytes --]

# Only mingw32 and cygwin on i386 have fastcall support
if { !([istarget "i386-pc-mingw32*"] || [istarget "i386-pc-cygwin*"]) } {
  return 1;
}

return 0;

[-- Attachment #8: 20021208-3.c --]
[-- Type: text/plain, Size: 29 bytes --]

void
__fastcall
f()
{
}

[-- Attachment #9: 20021208-3.x --]
[-- Type: application/octet-stream, Size: 161 bytes --]

# Only mingw32 and cygwin on i386 have fastcall support
if { !([istarget "i386-pc-mingw32*"] || [istarget "i386-pc-cygwin*"]) } {
  return 1;
}

return 0;

[-- Attachment #10: 20021208-4.c --]
[-- Type: text/plain, Size: 63 bytes --]

int
__attribute__ ((fastcall))
f(int x, int y, int z)
{
}

[-- Attachment #11: 20021208-4.x --]
[-- Type: application/octet-stream, Size: 161 bytes --]

# Only mingw32 and cygwin on i386 have fastcall support
if { !([istarget "i386-pc-mingw32*"] || [istarget "i386-pc-cygwin*"]) } {
  return 1;
}

return 0;

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

* Re: [PATCH] Fastcall support on cygwin and mingw targets
  2002-12-08  4:08                             ` Casper Hornstrup
@ 2002-12-19 14:01                               ` Richard Henderson
  2002-12-19 14:07                                 ` Casper Hornstrup
  0 siblings, 1 reply; 26+ messages in thread
From: Richard Henderson @ 2002-12-19 14:01 UTC (permalink / raw)
  To: Casper Hornstrup; +Cc: gcc-patches

On Sun, Dec 08, 2002 at 01:08:40PM +0100, Casper Hornstrup wrote:
> Attached is a new version of this patch.

Applied.

I combined the four test cases into gcc.dg/i386-fastcall-1.c,
which doesn't need .x files.


r~

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

* RE: [PATCH] Fastcall support on cygwin and mingw targets
  2002-12-19 14:01                               ` Richard Henderson
@ 2002-12-19 14:07                                 ` Casper Hornstrup
  0 siblings, 0 replies; 26+ messages in thread
From: Casper Hornstrup @ 2002-12-19 14:07 UTC (permalink / raw)
  To: 'Richard Henderson'; +Cc: gcc-patches



> -----Original Message-----
> From: Richard Henderson [mailto:rth@redhat.com] 
> Sent: 19. december 2002 23:01
> To: Casper Hornstrup
> Cc: gcc-patches@gcc.gnu.org
> Subject: Re: [PATCH] Fastcall support on cygwin and mingw targets
> 
> 
> On Sun, Dec 08, 2002 at 01:08:40PM +0100, Casper Hornstrup wrote:
> > Attached is a new version of this patch.
> 
> Applied.
> 
> I combined the four test cases into gcc.dg/i386-fastcall-1.c, 
> which doesn't need .x files.
> 
> 
> r~
> 

Thanks.

Casper Hornstrup

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

* [PATCH] Fastcall support on cygwin and mingw targets
@ 2002-11-20 11:03 Casper Hornstrup
  0 siblings, 0 replies; 26+ messages in thread
From: Casper Hornstrup @ 2002-11-20 11:03 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 2601 bytes --]

This is a refresh of the patch that implements support
in gcc for the fastcall calling convention on cygwin and
mingw targets (found here:
http://gcc.gnu.org/ml/gcc-patches/2002-11/msg00638.html).
This version of the patch includes changes as suggested
by people on this list.


gcc/testsuite/ChangeLog

2002-11-13  Casper S. Hornstrup  <chorns@users.sourceforge.net>

	* gcc.c-torture/compile/20021110-1.c: New test.
	* gcc.c-torture/compile/20021110-1.x: Likewise.
	* gcc.c-torture/compile/20021110-2.c: Likewise.
	* gcc.c-torture/compile/20021110-2.x: Likewise.
	* gcc.c-torture/compile/20021110-3.c: Likewise.
	* gcc.c-torture/compile/20021110-3.x: Likewise.
	* gcc.c-torture/compile/20021110-4.c: Likewise.
	* gcc.c-torture/compile/20021110-4.x: Likewise.


gcc/ChangeLog

2002-11-13  Casper S. Hornstrup  <chorns@users.sourceforge.net>

	* config/i386/i386.c (ix86_handle_cdecl_attribute): Check for
	attributes incompatible with fastcall attribute.
	(ix86_handle_regparm_attribute): Likewise.

2002-11-13  Danny Smith  <dannysmith@users.sourceforge.net>

	* config/i386/i386.c (ix86_comp_type_attributes): Check for
mismatched
	fastcall types.

2002-11-13  Eric Kohl  <ekohl@rz-online.de>

	* config/i386/cygwin.h (TARGET_OS_CPP_BUILTINS): Add fastcall
	attributes.
	(ASM_OUTPUT_LABELREF): Add __imp_ prefix now rather than in
winnt.c.
	* config/i386/winnt.c (i386_pe_mark_dllimport). Convert internal
	fastcall decoration to MS-compatible decoration. Add __imp_
prefix in
	ASM_OUTPUT_LABELREF rather than here.
	* config/i386/i386.c (ix86_attribute_table): Accept 'fastcall'
as a
	valid attribute.
	(ix86_return_pops_args): Fastcall functions pop the stack.
	(init_cumulative_args): Reserve registers ECX and EDX if
function has
	fastcall attribute.
	(function_arg): Use registers ECX and EDX if function has
fastcall
	attribute.
	* config/i386/i386.h (CUMULATIVE_ARGS): Add fastcall attribute
flag.
	* config/i386/mingw32.h (TARGET_OS_CPP_BUILTINS): Add fastcall
	attributes.
	* config/i386/winnt.c (gen_fastcall_suffix): New function.
Decorates a
	label name with a preliminary fastcall prefix (+) and the
stdcall
	suffix.
	(i386_pe_encode_section_info): Call gen_fastcall_suffix() if a
symbol
	has a fastcall attribute.
	(i386_pe_strip_name_encoding): Return length of internal
fastcall
	prefix (+).
	(i386_pe_fastcall_name_p): New function. Checks a symbol for
presence
	of internal fastcall prefix ('+' prefix).
	(i386_pe_asm_file_end): Converts internal fastcall prefix ('+'
prefix)
	into the Microsoft compatible '@' prefix.
	* doc/extend.texi: Add documentation of fastcall attribute.

[-- Attachment #2: fastcall.tar.gz --]
[-- Type: application/octet-stream, Size: 5812 bytes --]

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

end of thread, other threads:[~2002-12-19 22:07 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-30 21:14 PATCH: Re: optimization/6162: gcc 3.0.4: certain i386 asm reloader ice Nathanael Nerode
2002-11-10  8:17 ` [PATCH] Fastcall support on cygwin and mingw targets Casper Hornstrup
2002-11-10 17:50   ` Fergus Henderson
2002-11-10 19:10     ` Christopher Faylor
2002-11-11 12:47     ` Casper Hornstrup
2002-11-11 12:27       ` Fergus Henderson
2002-11-12 10:45         ` Casper Hornstrup
2002-11-12 22:08           ` Fergus Henderson
2002-11-13 12:17             ` Casper Hornstrup
2002-11-13 15:47               ` Joseph S. Myers
2002-11-13 20:27               ` Fergus Henderson
2002-11-14  0:31                 ` Joseph S. Myers
2002-11-14  8:28                 ` Casper Hornstrup
2002-11-25 15:39                   ` Richard Henderson
2002-11-27 19:52                     ` Casper Hornstrup
2002-11-27 21:15                       ` Casper Hornstrup
2002-11-27 22:19                       ` Richard Henderson
2002-11-28  2:00                         ` Richard Henderson
2002-12-02 13:25                     ` Casper Hornstrup
2002-12-02 13:48                       ` Richard Henderson
2002-12-03 13:52                         ` Casper Hornstrup
2002-12-03 16:32                           ` Richard Henderson
2002-12-08  4:08                             ` Casper Hornstrup
2002-12-19 14:01                               ` Richard Henderson
2002-12-19 14:07                                 ` Casper Hornstrup
2002-11-20 11:03 Casper Hornstrup

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).