前のページ | 次のページ
リスト


〔リスト1〕-finline-functionsオプションを使う例(test217.c)
//インラインファンクションの例
#include <stdio.h>
static int	a;
static int	test1();
static int	test1()
{
	return	a++;
}
int main()
{
	int		res;
	a	=	1;
	res	=	test1();
	printf("%d\n",res);
	res	=	test1();
	printf("%d\n",res);
	return	0;
}


〔リスト2〕-finline-functionsオプションを付けて生成されたアセンブラ・ソース(test217a.s)
	.file	"test217.c"
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d\n"
	.text
	.p2align 2,,3
.globl main
	.type	main, 	@function
main:
	pushl	%ebp
	movl		%esp,	%ebp
	subl		$8,		%esp
	andl		$-16,	%esp
	subl		$8,		%esp
	pushl	$1
	pushl	$.LC0
	movl		$2, 		a
	call		printf
	popl		%eax
	popl		%edx
	movl		a,		%ecx
	pushl	%ecx
	leal		1(%ecx),	%edx
	pushl	$.LC0
	movl		%edx,	a
	call		printf
	xorl		%eax,	%eax
	leave
	ret
	.size	main,	.-main
	.local	a
	.comm	a,4,4
	.section	.note.GNU-stack,"",@progbits
	.ident	"GCC: (GNU) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)"

〔リスト3〕-fno-inline-functionsオプションを付けて生成されたアセンブラ・ソース(test217.s)
	.file	"test217.c"
	.text
	.p2align 	2,,3
	.type	test1, 	@function
test1:
	movl		a, 		%eax
	pushl	%ebp
	movl		%esp,	%ebp
	leal		1(%eax),	%ecx
	movl		%ecx,	a
	leave
	ret
	.size	test1, 	.-test1
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d\n"
	.text
	.p2align 	2,,3
.globl main
	.type	main, 	@function
main:
	pushl	%ebp
	movl		%esp,	%ebp
	subl		$8,		%esp
	andl		$-16,	%esp
	movl		$1,		a
	call		test1
	subl		$8,		%esp
	pushl	%eax
	pushl	$.LC0
	call		printf
	call		test1
	popl		%edx
	popl		%ecx
	pushl	%eax
	pushl	$.LC0
	call		printf
	xorl		%eax,	%eax
	leave
	ret
	.size	main,	.-main
	.local	a
	.comm	a,4,4
	.section	.note.GNU-stack,"",@progbits
	.ident	"GCC: (GNU) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)"

〔リスト4〕キーワードinlineを指定した例(test218.c)
//インライン・ファンクションの例
#include <stdio.h>
static int	a;
static inline int	test1();
static inline int	test1()
{
	return	a++;
}
int main()
{
	int		res;
	a	=	1;
	res	=	test1();
	printf("%d\n",res);
	res	=	test1();
	printf("%d\n",res);
	return	0;
}


〔リスト5〕-O3オプションを付けて生成されたアセンブラ・ソース(test218.s)
	.file	"test218.c"
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d\n"
	.text
	.p2align 	2,,3
.globl main
	.type	main, @function
main:
	pushl	%ebp
	movl		%esp,	%ebp
	subl		$8,		%esp
	andl		$-16,	%esp
	subl		$8,		%esp
	pushl	$1
	pushl	$.LC0
	movl		$2,		a
	call		printf
	popl		%eax
	popl		%edx
	movl		a, 		%ecx	
	pushl	%ecx
	leal		1(%ecx), 	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	xorl		%eax, 	%eax
	leave
	ret
	.size	main, 	.-main
	.local	a
	.comm	a,4,4
	.section	.note.GNU-stack,"",@progbits
	.ident	"GCC: (GNU) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)"

〔リスト6〕-finline-limit=オプションを使う例(test219.c)
//インライン・ファンクションの例
#include <stdio.h>
static	int	a;
static	int	test1();
static	int	test1()
{
	return	a++;
}
int main()
{
	int		res;
	a	=	1;
	res	=	test1();
	printf("%d\n",res);
	res	=	test1();
	printf("%d\n",res);
	res	=	test1();
	printf("%d\n",res);
	res	=	test1();
	printf("%d\n",res);
	res	=	test1();
	printf("%d\n",res);
	res	=	test1();
	printf("%d\n",res);
	res	=	test1();
	printf("%d\n",res);
	res	=	test1();
	printf("%d\n",res);
	res	=	test1();
	printf("%d\n",res);
	res	=	test1();
	printf("%d\n",res);
	res	=	test1();
	printf("%d\n",res);
	res	=	test1();
	printf("%d\n",res);
	return	0;
}

〔リスト7〕n=200で生成されたアセンブラ・ソース(test219a.s)
	.file	"test219.c"
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d\n"
	.text
	.p2align 2,,3
.globl main
	.type	main, @function
main:
	pushl	%ebp
	movl		%esp, 	%ebp
	subl		$8, 		%esp
	andl		$-16, 	%esp
	subl		$8, 		%esp
	pushl	$1
	pushl	$.LC0
	movl		$2, 		a
	call		printf
	popl		%eax
	popl		%edx
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx), 	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	popl		%ecx
	popl		%eax
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx), 	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	popl		%eax
	popl		%edx
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx), 	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	popl		%ecx
	popl		%eax
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx), 	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	popl		%eax
	popl		%edx
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx), 	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	popl		%ecx
	popl		%eax
	movl		a,		%ecx
	pushl	%ecx
	leal		1(%ecx),	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	popl		%eax
	popl		%edx
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx),	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	popl		%ecx
	popl		%eax
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx),	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	popl		%eax
	popl		%edx
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx), 	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	popl		%ecx
	popl		%eax
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx),	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	popl		%eax
	popl		%edx
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx),	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	xorl		%eax,	%eax
	leave
	ret
	.size	main, 	.-main
	.local	a
	.comm	a,4,4
	.section	.note.GNU-stack,"",@progbits
	.ident	"GCC: (GNU) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)"

〔リスト8〕n=5で生成されたアセンブラ・ソース(test219.s)
	.file	"test219.c"
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d\n"
	.text
	.p2align 2,,3
.globl main
	.type	main, 	@function
main:
	pushl	%ebp
	movl		%esp, 	%ebp
	subl		$8, 		%esp
	andl		$-16, 	%esp
	movl		$1, a
	call		test1
	subl		$8, 		%esp
	pushl	%eax
	pushl	$.LC0
	call		printf
	call		test1
	popl		%edx
	popl		%ecx
	pushl	%eax
	pushl	$.LC0
	call		printf
	call		test1
	popl		%edx
	popl		%ecx
	pushl	%eax
	pushl	$.LC0
	call		printf
	call		test1
	popl		%edx
	popl		%ecx
	pushl	%eax
	pushl	$.LC0
	call		printf
	call		test1
	popl		%edx
	popl		%ecx
	pushl	%eax
	pushl	$.LC0
	call		printf
	call		test1
	popl		%edx
	popl		%ecx
	pushl	%eax
	pushl	$.LC0
	call		printf
	call		test1
	popl		%edx
	popl		%ecx
	pushl	%eax
	pushl	$.LC0
	call		printf
	call		test1
	popl		%edx
	popl		%ecx
	pushl	%eax
	pushl	$.LC0
	call		printf
	call		test1
	popl		%edx
	popl		%ecx
	pushl	%eax
	pushl	$.LC0
	call		printf
	call		test1
	popl		%edx
	popl		%ecx
	pushl	%eax
	pushl	$.LC0
	call		printf
	call		test1
	popl		%edx
	popl		%ecx
	pushl	%eax
	pushl	$.LC0
	call		printf
	call		test1
	popl		%edx
	popl		%ecx
	pushl	%eax
	pushl	$.LC0
	call		printf
	xorl		%eax, 	%eax
	leave
	ret
	.size	main, 	.-main
	.local	a
	.comm	a,4,4
	.p2align 2,,3
	.type	test1, 	@function
test1:
	movl		a, 		%eax
	pushl	%ebp
	movl		%esp, 	%ebp
	leal		1(%eax), 	%ecx
	movl		%ecx, 	a
	leave
	ret
	.size	test1, 	.-test1
	.section	.note.GNU-stack,"",@progbits
	.ident	"GCC: (GNU) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)"

〔リスト9〕-fkeep-inline-functionsオプションを使う例(test220.c)
//インライン・ファンクションの例
#include <stdio.h>
static 	int	a;
static	int	test1();
static	int	test1()
{
	return	a++;
}
int main()
{
	int		res;
	a	=	1;
	res	=	test1();
	printf("%d\n",res);
	res	=	test1();
	printf("%d\n",res);
	res	=	test1();
	printf("%d\n",res);
	res	=	test1();
	printf("%d\n",res);
	res	=	test1();
	printf("%d\n",res);
	res	=	test1();
	printf("%d\n",res);
	res	=	test1();
	printf("%d\n",res);
	res	=	test1();
	printf("%d\n",res);
	res	=	test1();
	printf("%d\n",res);
	res	=	test1();
	printf("%d\n",res);
	res	=	test1();
	printf("%d\n",res);
	res	=	test1();
	printf("%d\n",res);
	return	0;
}

〔リスト10〕-fkeep-inline-functionsで生成されたアセンブラ・ソース(test220a.s)
	.file	"test220.c"
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d\n"
	.text
	.p2align 2,,3
.globl main
	.type	main, @function
main:
	pushl	%ebp
	movl		%esp, 	%ebp
	subl		$8, 		%esp
	andl		$-16, 	%esp
	subl		$8, 		%esp
	pushl	$1
	pushl	$.LC0
	movl		$2, 		a
	call		printf
	popl		%eax
	popl		%edx
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx), 	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	popl		%ecx
	popl		%eax
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx), 	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	popl		%eax
	popl		%edx
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx), 	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	popl		%ecx
	popl		%eax
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx), 	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	popl		%eax
	popl		%edx
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx), 	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	popl		%ecx
	popl		%eax
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx), 	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	popl		%eax
	popl		%edx
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx), 	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	popl		%ecx
	popl		%eax
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx), 	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	popl		%eax
	popl		%edx
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx), 	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	popl		%ecx
	popl		%eax
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx), 	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	popl		%eax
	popl		%edx
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx), 	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	xorl		%eax, 	%eax
	leave
	ret
	.size	main, 	.-main
	.local	a
	.comm	a,4,4
	.p2align 	2,,3
	.type	test1, 	@function
test1:
	movl		a, 		%eax
	pushl	%ebp
	movl		%esp, 	%ebp
	leal		1(%eax), 	%ecx
	movl		%ecx, 	a
	leave
	ret
	.size	test1, 	.-test1
	.section	.note.GNU-stack,"",@progbits
	.ident	"GCC: (GNU) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)"

〔リスト11〕-fno-keep-inline-functionsで生成されたアセンブラ・ソース(test220.s)
	.file	"test220.c"
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d\n"
	.text
	.p2align 2,,3
.globl main
	.type	main, 	@function
main:
	pushl	%ebp
	movl		%esp, 	%ebp
	subl		$8, 		%esp
	andl		$-16, 	%esp
	subl		$8, 		%esp
	pushl	$1
	pushl	$.LC0
	movl		$2, 		a
	call		printf
	popl		%eax
	popl		%edx
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx), 	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	popl		%ecx
	popl		%eax
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx), 	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	popl		%eax
	popl		%edx
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx), 	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	popl		%ecx
	popl		%eax
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx), 	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	popl		%eax
	popl		%edx
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx), 	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	popl		%ecx
	popl		%eax
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx), 	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	popl		%eax
	popl		%edx
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx), 	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	popl		%ecx
	popl		%eax
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx), 	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	popl		%eax
	popl		%edx
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx), 	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	popl		%ecx
	popl		%eax
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx), 	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	popl		%eax
	popl		%edx
	movl		a, 		%ecx
	pushl	%ecx
	leal		1(%ecx), 	%edx
	pushl	$.LC0
	movl		%edx, 	a
	call		printf
	xorl		%eax, 	%eax
	leave
	ret
	.size	main, 	.-main
	.local	a
	.comm	a,4,4
	.section	.note.GNU-stack,"",@progbits
	.ident	"GCC: (GNU) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)"

〔リスト12〕-fkeep-static-constsオプションを使う例(test221.c)
//fkeep-static-constsの例
#include <stdio.h>
static const	test_static;
int main()
{
	int		res;
	int		a	=	1;
	return	0;
}

〔リスト13〕-fkeep-inline-functionsで生成されたマップ・リスト(test221.nm)
08049448 D _DYNAMIC
08049514 D _GLOBAL_OFFSET_TABLE_
0804842c R _IO_stdin_used
         w _Jv_RegisterClasses
08049438 d __CTOR_END__
08049434 d __CTOR_LIST__
08049440 d __DTOR_END__
0804943c d __DTOR_LIST__
08048430 r __FRAME_END__
08049444 d __JCR_END__
08049444 d __JCR_LIST__
08049530 A __bss_start
08049524 D __data_start
080483e8 t __do_global_ctors_aux
080482d4 t __do_global_dtors_aux
08049528 D __dso_handle
08049434 A __fini_array_end
08049434 A __fini_array_start
         w __gmon_start__
08049434 A __init_array_end
08049434 A __init_array_start
080483a4 T __libc_csu_fini
0804835c T __libc_csu_init
         U __libc_start_main@@GLIBC_2.0
08049434 A __preinit_array_end
08049434 A __preinit_array_start
08049530 A _edata
08049538 A _end
0804840c T _fini
08048428 R _fp_hw
08048254 T _init
0804828c T _start
080482b0 t call_gmon_start
08049530 b completed.1
08049524 W data_start
08048310 t frame_dummy
0804833c T main
0804952c d p.0
08049534 b test_static

〔リスト14〕-fno-keep-inline-functionsで生成されたマップ・リスト(test221a.nm)
08049448 D _DYNAMIC
08049514 D _GLOBAL_OFFSET_TABLE_
0804842c R _IO_stdin_used
         w _Jv_RegisterClasses
08049438 d __CTOR_END__
08049434 d __CTOR_LIST__
08049440 d __DTOR_END__
0804943c d __DTOR_LIST__
08048430 r __FRAME_END__
08049444 d __JCR_END__
08049444 d __JCR_LIST__
08049530 A __bss_start
08049524 D __data_start
080483e8 t __do_global_ctors_aux
080482d4 t __do_global_dtors_aux
08049528 D __dso_handle
08049434 A __fini_array_end
08049434 A __fini_array_start
         w __gmon_start__
08049434 A __init_array_end
08049434 A __init_array_0start
080483a4 T __libc_csu_fini
0804835c T __libc_csu_init
         U __libc_start_main@@GLIBC_2.0
08049434 A __preinit_array_end
08049434 A __preinit_array_start
08049530 A _edata
08049534 A _end
0804840c T _fini
08048428 R _fp_hw
08048254 T _init
0804828c T _start
080482b0 t call_gmon_start
08049530 b completed.1
08049524 W data_start
08048310 t frame_dummy
0804833c T main
0804952c d p.0

〔リスト15〕-fkeep-inline-functionsで生成されたアセンブラ・ソース(test221.s)
	.file	"test221.c"
	.text
.globl main
	.type	main, 	@function
main:
	pushl	%ebp
	movl		%esp, 	%ebp
	subl		$8, 		%esp
	andl		$-16,	%esp
	movl		$0, 		%eax
	subl		%eax, 	%esp
	movl		$1, 		-8(%ebp)
	movl		$0, 		%eax
	leave
	ret
	.size	main, 	.-main
	.local	test_static
	.comm	test_static,4,4
	.section	.note.GNU-stack,"",@progbits
	.ident	"GCC: (GNU) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)"

〔リスト16〕-fno-keep-inline-functionsで生成されたアセンブラ・ソース(test221a.s)
	.file	"test221.c"
	.text
.globl main
	.type	main, 	@function
main:
	pushl	%ebp
	movl		%esp, 	%ebp
	subl		$8, 		%esp
	andl		$-16, 	%esp
	movl		$0, 		%eax
	subl		%eax,	%esp
	movl		$1, 		-8(%ebp)
	movl		$0, 		%eax
	leave
	ret
	.size	main, 	.-main
	.section	.note.GNU-stack,"",@progbits
	.ident	"GCC: (GNU) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)"
前のページ | 次のページ
NEW記事内インデックス    連載インデックスはこちら   Interfaceのトップ
最適化オプション
◆リスト

Copyright 2004 岸 哲夫

Copyright 1997-2004 CQ Publishing Co.,Ltd.