Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: very simple question on inlining

Author: Tom Likens

Date: 07:55:22 11/30/03

Go up one level in this thread


On November 30, 2003 at 07:25:09, Georg v. Zimmermann wrote:

>Do modern compilers understand the following 2 code parts are exactly
>equivialent ? Do they understand to also eliminate the ifs in the second example
>when inlining ?
>
>Thanks.
>
>Oh and if I have typose in there , its just an example, I think you get the idea
>anyway.
>
>
>PS.
>Congrats to Shredder !
>
>
>Example 1.)
>
>int test ()
>{
>
>	for (int a = 0; a < 77; a++)
>	{
>		if (oneArray[a]) return 0;
>	}
>
>	for (a = 0; a < 77; a++)
>	{
>		if (anotherArray[a]) return 0;
>	}
>	return 1;
>}
>
>-------------------------------------------------------
>Example 2.)
>
>
>inline int subTest1 ()
>{
>	for (int a = 0; a < 77; a++)
>	{
>		if (oneArray[a]) return 0;
>	}
>	return 1;
>}
>
>inline int subTest2 ()
>{
>	for (int a = 0; a < 77; a++)
>	{
>		if (anotherArray[a]) return 0;
>	}
>	return 1;
>}
>
>
>int test ()
>{
>
>	if (!subTest1())
>		return 0;
>	if (!subTest2())
>		return 0;
>
>	return 1;
>}

Georg,

One way to determine this, for your compiler, is to have it output assembly.
For gcc (and the Linux version of Intel's compiler as well) use the -S
switch.  If you are uncomfortable with the default AT&T assembly syntax
used by gcc, and are using gcc 3.x, you can add the -masm=intel to produce
assembly using the Intel syntax.

It's actually a pretty good idea to look at the assembly your compiler is
producing every now and then, in order to determine if it is hosing you
behind the scenes.  Sometimes it can be rather eye-opening.

regards,
--tom



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.