🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #54307

Re: An Inline Function is NOT as Fast as a Macro

#54307
From: Arch D. Robison
Date: Thu, 06 Dec 1990 16:00
83 lines
2441 bytes
Section 6.15 of the gcc manual says that ``An Inline Function is as Fast as
a Macro''.  This is not necessarily the case.  Consider the program below.

------------------------------------------------------------------------
	#define LESS(a,b) (a<b)
	#define GEQ(a,b) !LESS(a,b)
	
	inline int less( int a, int b ) {
	     return a < b;
	}
	
	inline int geq( int a, int b ) {
	     return !less( a,b );
	}
	
	int inline_foo( int a, int b ) {
	    if(geq(a,b)) true(); else false();
	}
	
	int macro_foo( int a, int b ) {
	    if(GEQ(a,b)) true(); else false();
	} 
------------------------------------------------------------------------
Functions inline_foo and macro_foo differ in that one uses inline functions
and the other uses macros.  Gcc version 1.37.1 on a Sun/4 compiles this 
program into code that is excerpted below.  Clearly, the use of macros
in this case is more efficient than using inline functions.  I really like
the idea of inline functions, so perhaps there is a way to repair this
inefficiency?
--------------------------------------------------------------------------
        ...
	.align 4
.global _inline_foo
	.proc 1
_inline_foo:
	!#PROLOGUE# 0
	save %sp,-112,%sp
	!#PROLOGUE# 1
	mov 0,%o0
	cmp %i0,%i1
	bge L16
	nop
	mov 1,%o0
L16:
	tst %o0
	be,a L18
	orcc %g0,1,%o0
	orcc %g0,0,%o0
L18:
	be L13
	nop
	call _true,0
	nop
	b,a L17
L13:
	call _false,0
	nop
L17:
	ret
	restore
	.align 4
.global _macro_foo
	.proc 1
_macro_foo:
	!#PROLOGUE# 0
	save %sp,-112,%sp
	!#PROLOGUE# 1
	cmp %i0,%i1
	bl L20
	nop
	call _true,0
	nop
	b,a L21
L20:
	call _false,0
	nop
L21:
	ret
	restore
---------------------------------------------------------------------------

Arch D. Robison				(713)-663-2240
Shell Development Company 		robison@shell.com
Technical Details
Message-ID: <1990Dec6.160010.27073@shell.shell.com>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!nuchat!shell!brazil!robison

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,696aa50831602ca7,start
X-Google-Attributes: gid11318c,public
X-Google-ArrivalTime: 1990-12-06 08:00:10 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!nuchat!shell!brazil!robison
From: robison@brazil (Arch D. Robison)
Newsgroups: gnu.gcc.help
Subject: Re: An Inline Function is NOT as Fast as a Macro
Message-ID: <1990Dec6.160010.27073@shell.shell.com>
Date: 6 Dec 90 16:00:10 GMT
Sender: usenet@shell.shell.com (USENET News System)
Distribution: gnu.gcc.help
Organization: Shell Development Co.
Lines: 83
Posted: Thu Dec  6 17:00:10 1990