前のページ | 次のページ
リスト(続き)


〔リスト11〕「覗き穴」最適化の例(test230.c)
//ピープホール最適化を行う例
#include 
main()
{
	int	x	=	0;
	int	y	=	0;
	x	=	x	+	1;
	y	=	x^2;
	printf("%d\n",x);
	printf("%d\n",y);
	y	=	y	+	0;
	y	=	y	+	0;
	y	=	y	+	0;
	y	=	y	+	0;
	y	=	y	+	0;
	goto L1;
	return;
L1:
	return;
	printf("%d\n",x);
}


〔リスト12〕最適化-Oで生成されたアセンブラ・ソース(test230a.s)
	.file	"test230.c"
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d\n"
	.text
.globl main
	.type	main, @function
main:
	pushl	%ebp
	movl		%esp, %ebp
	subl		$8,   %esp
	andl		$-16, %esp
	subl		$8,   %esp
	pushl	$1
	pushl	$.LC0
	call		printf
	addl		$8,  %esp
	pushl	$3
	pushl	$.LC0
	call		printf
	addl		$16, %esp
.L2:
	leave
	ret
	.size	main, .-main
	.section	.note.GNU-stack,"",@progbits
	.ident	"GCC: (GNU) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)"

〔リスト13〕「のぞき穴」最適化を禁止して生成されたアセンブラ・ソース(test230b.s)
	.file	"test230.c"
	.section	.rodata
.LC0:
	.string	"%d\n"
	.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		$0,       -4(%ebp)
	movl		$0,       -8(%ebp)
	leal		-4(%ebp), %eax
	incl		(%eax)
	movl		-4(%ebp), %eax
	xorl		$2,   %eax
	movl		%eax, -8(%ebp)
	subl		$8,   %esp
	pushl	-4(%ebp)
	pushl	$.LC0
	call		printf
	addl		$16,  %esp
	subl		$8,   %esp
	pushl	-8(%ebp)
	pushl	$.LC0
	call		printf
	addl		$16,  %esp
.L2:
	leave
	ret
	.size	main, .-main
	.section	.note.GNU-stack,"",@progbits
	.ident	"GCC: (GNU) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)"

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


〔リスト15〕浮動小数点式のトラップを生成しない最適化の例(test231.c)
//浮動小数点式のトラップを生成しない最適化をする例
#include 
#include 
const float f1 = 3.1212312312312312f;
const float f2 = 6.5432165432165432f;

float func(float a)
{
	float	x;
	x	=	f1 / f2;
    return a * f1 / f2;
}
main()
{
	float	z	=	func(3.1212312312312312f);
}

〔リスト16〕トラップを生成したアセンブラ・ソース(test231.s)
	.file	"test231.c"
.globl f1
	.section	.rodata
	.align 4
	.type	f1, @object
	.size	f1, 4
f1:
	.long	1078444609
.globl f2
	.align 4
	.type	f2, @object
	.size	f2, 4
f2:
	.long	1087463944
	.text
.globl func
	.type	func, @function
func:
	pushl	%ebp
	movl		%esp, %ebp
	subl		$4,   %esp
	flds		f1
	fdivs	f2
	fstps	-4(%ebp)
	flds		8(%ebp)
	fmuls	f1
	fdivs	f2
	leave
	ret
	.size	func, .-func
.globl main
	.type	main, @function
main:
	pushl	%ebp
	movl		%esp,        %ebp
	subl		$8,          %esp
	andl		$-16,        %esp
	movl		$0,          %eax
	subl		%eax,        %esp
	subl		$12,         %esp
	movl		$0x4047c241, %eax
	pushl	%eax
	call		func
	addl		$16,         %esp
	fstps	-4(%ebp)
	leave
	ret
	.size	main, .-main
	.section	.note.GNU-stack,"",@progbits
	.ident	"GCC: (GNU) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)"

〔リスト17〕トラップを生成しないアセンブラ・ソース(test231a.s)
	.file	"test231.c"
.globl f1
	.section	.rodata
	.align 4
	.type	f1, @object
	.size	f1, 4
f1:
	.long	1078444609
.globl f2
	.align 4
	.type	f2, @object
	.size	f2, 4
f2:
	.long	1087463944
	.text
.globl func
	.type	func, @function
func:
	pushl	%ebp
	movl		%esp, %ebp
	subl		$4,   %esp
	flds		f1
	fdivs	f2
	fstps	-4(%ebp)
	flds		8(%ebp)
	fmuls	f1
	fdivs	f2
	leave
	ret
	.size	func, .-func
	.section	.note.GNU-stack,"",@progbits
	.ident	"GCC: (GNU) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)"

〔リスト18〕BSSセクションに置かれた定数を初期化する例(test232.c)
//BSSセクションに置かれた定数を初期化する例
#include 
int	a;
int	b;
int	c;
main()
{
	printf("%d\n",a);
	printf("%d\n",b);
	printf("%d\n",c);
}

〔リスト19〕初期化するアセンブラ・ソース(test232.s)
	.file	"test232.c"
	.section	.rodata
.LC0:
	.string	"%d\n"
	.text
.globl main
	.type	main, @function
main:
	pushl	%ebp
	movl		%esp, %ebp
	subl		$8,   %esp
	andl		$-16, %esp
	movl		$0,   %eax
	subl		%eax, %esp
	subl		$8,   %esp
	pushl	a
	pushl	$.LC0
	call		printf
	addl		$16,  %esp
	subl		$8,   %esp
	pushl	b
	pushl	$.LC0
	call		printf
	addl		$16,  %esp
	subl		$8,   %esp
	pushl	c
	pushl	$.LC0
	call		printf
	addl		$16, %esp
	leave
	ret
	.size	main, .-main
.globl a
	.bss
	.align 4
	.type	a, @object
	.size	a, 4
a:
	.zero	4
.globl b
	.align 4
	.type	b, @object
	.size	b, 4
b:
	.zero	4
.globl c
	.align 4
	.type	c, @object
	.size	c, 4
c:
	.zero	4
	.section	.note.GNU-stack,"",@progbits
	.ident	"GCC: (GNU) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)"

〔リスト20〕初期化しないアセンブラ・ソース(test232a.s)
	.file	"test232.c"
	.section	.rodata
.LC0:
	.string	"%d\n"
	.text
.globl main
	.type	main, @function
main:
	pushl	%ebp
	movl		%esp, %ebp
	subl		$8,   %esp
	andl		$-16, %esp
	movl		$0,   %eax
	subl		%eax, %esp
	subl		$8,   %esp
	pushl	a
	pushl	$.LC0
	call		printf
	addl		$16,  %esp
	subl		$8,   %esp
	pushl	b
	pushl	$.LC0
	call		printf
	addl		$16,  %esp
	subl		$8,   %esp
	pushl	c
	pushl	$.LC0
	call	printf
	addl	$16, %esp
	leave
	ret
	.size	main, .-main
.globl a
	.bss
	.align 4
	.type	a, @object
	.size	a, 4
a:
	.zero	4
.globl b
	.align 4
	.type	b, @object
	.size	b, 4
b:
	.zero	4
.globl c
	.align 4
	.type	c, @object
	.size	c, 4
c:
	.zero	4
	.section	.note.GNU-stack,"",@progbits
	.ident	"GCC: (GNU) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)"

〔リスト21〕生成されたオブジェクト・ダンプ・リスト3(test232.txt)
test232:     ファイル形式 elf32-i386

セクション .init の逆アセンブル:

08048278 <_init>:
 8048278:	55                   	push   %ebp
 8048279:	89 e5                	mov    %esp,%ebp
 804827b:	83 ec 08             	sub    $0x8,%esp
 804827e:	e8 61 00 00 00       	call   80482e4 
 8048283:	e8 bc 00 00 00       	call   8048344 
 8048288:	e8 c3 01 00 00       	call   8048450 <__do_global_ctors_aux>
 804828d:	c9                   	leave  
 804828e:	c3                   	ret    
セクション .plt の逆アセンブル:

08048290 <.plt>:
 8048290:	ff 35 84 95 04 08    	pushl  0x8049584
 8048296:	ff 25 88 95 04 08    	jmp    *0x8049588
 804829c:	00 00                	add    %al,(%eax)
 804829e:	00 00                	add    %al,(%eax)
 80482a0:	ff 25 8c 95 04 08    	jmp    *0x804958c
 80482a6:	68 00 00 00 00       	push   $0x0
 80482ab:	e9 e0 ff ff ff       	jmp    8048290 <_init+0x18>
 80482b0:	ff 25 90 95 04 08    	jmp    *0x8049590
 80482b6:	68 08 00 00 00       	push   $0x8
 80482bb:	e9 d0 ff ff ff       	jmp    8048290 <_init+0x18>
セクション .text の逆アセンブル:

080482c0 <_start>:
 80482c0:	31 ed                	xor    %ebp,%ebp
 80482c2:	5e                   	pop    %esi
 80482c3:	89 e1                	mov    %esp,%ecx
 80482c5:	83 e4 f0             	and    $0xfffffff0,%esp
 80482c8:	50                   	push   %eax
 80482c9:	54                   	push   %esp
 80482ca:	52                   	push   %edx
 80482cb:	68 0c 84 04 08       	push   $0x804840c
 80482d0:	68 c4 83 04 08       	push   $0x80483c4
 80482d5:	51                   	push   %ecx
 80482d6:	56                   	push   %esi
 80482d7:	68 70 83 04 08       	push   $0x8048370
 80482dc:	e8 bf ff ff ff       	call   80482a0 <_init+0x28>
 80482e1:	f4                   	hlt    
 80482e2:	90                   	nop    
 80482e3:	90                   	nop    

080482e4 :
 80482e4:	55                   	push   %ebp
 80482e5:	89 e5                	mov    %esp,            %ebp
 80482e7:	53                   	push   %ebx
 80482e8:	e8 00 00 00 00       	call   80482ed 
 80482ed:	5b                   	pop    %ebx
 80482ee:	81 c3 93 12 00 00    	add    $0x1293,         %ebx
 80482f4:	50                   	push   %eax
 80482f5:	8b 83 fc ff ff ff    	mov    0xfffffffc(%ebx),%eax
 80482fb:	85 c0                	test   %eax,%eax
 80482fd:	74 02                	je     8048301 
 80482ff:	ff d0                	call   *%eax
 8048301:	8b 5d fc             	mov    0xfffffffc(%ebp),%ebx
 8048304:	c9                   	leave  
 8048305:	c3                   	ret    
 8048306:	90                   	nop    
 8048307:	90                   	nop    

08048308 <__do_global_dtors_aux>:
 8048308:	55                   	push   %ebp
 8048309:	89 e5                	mov    %esp,     %ebp
 804830b:	83 ec 08             	sub    $0x8,     %esp
 804830e:	80 3d a0 95 04 08 00 	cmpb   $0x0,0x80495a0
 8048315:	75 29                	jne    8048340 <__do_global_dtors_aux+0x38>
 8048317:	a1 9c 95 04 08       	mov    0x804959c,%eax
 804831c:	8b 10                	mov    (%eax),   %edx
 804831e:	85 d2                	test   %edx,     %edx
 8048320:	74 17                	je     8048339 <__do_global_dtors_aux+0x31>
 8048322:	89 f6                	mov    %esi,     %esi
 8048324:	83 c0 04             	add    $0x4,     %eax
 8048327:	a3 9c 95 04 08       	mov    %eax,0x804959c
 804832c:	ff d2                	call   *%edx
 804832e:	a1 9c 95 04 08       	mov    0x804959c,%eax
 8048333:	8b 10                	mov    (%eax),   %edx
 8048335:	85 d2                	test   %edx,     %edx
 8048337:	75 eb                	jne    8048324 <__do_global_dtors_aux+0x1c>
 8048339:	c6 05 a0 95 04 08 01 	movb   $0x1,0x80495a0
 8048340:	c9                   	leave  
 8048341:	c3                   	ret    
 8048342:	89 f6                	mov    %esi,      %esi

08048344 :
 8048344:	55                   	push   %ebp
 8048345:	89 e5                	mov    %esp,      %ebp
 8048347:	83 ec 08             	sub    $0x8,      %esp
 804834a:	a1 b0 94 04 08       	mov    0x80494b0, %eax
 804834f:	85 c0                	test   %eax,      %eax
 8048351:	74 19                	je     804836c 
 8048353:	b8 00 00 00 00       	mov    $0x0,      %eax
 8048358:	85 c0                	test   %eax,      %eax
 804835a:	74 10                	je     804836c 
 804835c:	83 ec 0c             	sub    $0xc,      %esp
 804835f:	68 b0 94 04 08       	push   $0x80494b0
 8048364:	ff d0                	call   *%eax
 8048366:	83 c4 10             	add    $0x10,     %esp
 8048369:	8d 76 00             	lea    0x0(%esi), %esi
 804836c:	c9                   	leave  
 804836d:	c3                   	ret    
 804836e:	90                   	nop    
 804836f:	90                   	nop    

08048370 
: 8048370: 55 push %ebp 8048371: 89 e5 mov %esp, %ebp 8048373: 83 ec 08 sub $0x8, %esp 8048376: 83 e4 f0 and $0xfffffff0, %esp 8048379: b8 00 00 00 00 mov $0x0, %eax 804837e: 29 c4 sub %eax, %esp 8048380: 83 ec 08 sub $0x8, %esp 8048383: ff 35 a4 95 04 08 pushl 0x80495a4 8048389: 68 98 84 04 08 push $0x8048498 804838e: e8 1d ff ff ff call 80482b0 <_init+0x38> 8048393: 83 c4 10 add $0x10, %esp 8048396: 83 ec 08 sub $0x8, %esp 8048399: ff 35 a8 95 04 08 pushl 0x80495a8 804839f: 68 98 84 04 08 push $0x8048498 80483a4: e8 07 ff ff ff call 80482b0 <_init+0x38> 80483a9: 83 c4 10 add $0x10, %esp 80483ac: 83 ec 08 sub $0x8, %esp 80483af: ff 35 ac 95 04 08 pushl 0x80495ac 80483b5: 68 98 84 04 08 push $0x8048498 80483ba: e8 f1 fe ff ff call 80482b0 <_init+0x38> 80483bf: 83 c4 10 add $0x10, %esp 80483c2: c9 leave 80483c3: c3 ret 080483c4 <__libc_csu_init>: 80483c4: 55 push %ebp 80483c5: 89 e5 mov %esp, %ebp 80483c7: 57 push %edi 80483c8: 56 push %esi 80483c9: 53 push %ebx 80483ca: 83 ec 0c sub $0xc, %esp 80483cd: e8 00 00 00 00 call 80483d2 <__libc_csu_init+0xe> 80483d2: 5b pop %ebx 80483d3: 81 c3 ae 11 00 00 add $0x11ae, %ebx 80483d9: e8 9a fe ff ff call 8048278 <_init> 80483de: 8d 93 20 ff ff ff lea 0xffffff20(%ebx),%edx 80483e4: 8d 8b 20 ff ff ff lea 0xffffff20(%ebx),%ecx 80483ea: 29 ca sub %ecx, %edx 80483ec: 31 f6 xor %esi, %esi 80483ee: c1 fa 02 sar $0x2, %edx 80483f1: 39 d6 cmp %edx, %esi 80483f3: 73 0f jae 8048404 <__libc_csu_init+0x40> 80483f5: 89 d7 mov %edx, %edi 80483f7: 90 nop 80483f8: ff 94 b3 20 ff ff ff call *0xffffff20(%ebx,%esi,4) 80483ff: 46 inc %esi 8048400: 39 fe cmp %edi, %esi 8048402: 72 f4 jb 80483f8 <__libc_csu_init+0x34> 8048404: 83 c4 0c add $0xc, %esp 8048407: 5b pop %ebx 8048408: 5e pop %esi 8048409: 5f pop %edi 804840a: c9 leave 804840b: c3 ret 0804840c <__libc_csu_fini>: 804840c: 55 push %ebp 804840d: 89 e5 mov %esp, %ebp 804840f: 56 push %esi 8048410: 53 push %ebx 8048411: e8 00 00 00 00 call 8048416 <__libc_csu_fini+0xa> 8048416: 5b pop %ebx 8048417: 81 c3 6a 11 00 00 add $0x116a, %ebx 804841d: 8d 8b 20 ff ff ff lea 0xffffff20(%ebx),%ecx 8048423: 8d 83 20 ff ff ff lea 0xffffff20(%ebx),%eax 8048429: 29 c1 sub %eax, %ecx 804842b: c1 f9 02 sar $0x2, %ecx 804842e: 85 c9 test %ecx, %ecx 8048430: 8d 71 ff lea 0xffffffff(%ecx),%esi 8048433: 75 0b jne 8048440 <__libc_csu_fini+0x34> 8048435: e8 3a 00 00 00 call 8048474 <_fini> 804843a: 5b pop %ebx 804843b: 5e pop %esi 804843c: c9 leave 804843d: c3 ret 804843e: 89 f6 mov %esi, %esi 8048440: ff 94 b3 20 ff ff ff call *0xffffff20(%ebx,%esi,4) 8048447: 89 f2 mov %esi, %edx 8048449: 4e dec %esi 804844a: 85 d2 test %edx, %edx 804844c: 75 f2 jne 8048440 <__libc_csu_fini+0x34> 804844e: eb e5 jmp 8048435 <__libc_csu_fini+0x29> 08048450 <__do_global_ctors_aux>: 8048450: 55 push %ebp 8048451: 89 e5 mov %esp, %ebp 8048453: 53 push %ebx 8048454: 52 push %edx 8048455: a1 a0 94 04 08 mov 0x80494a0, %eax 804845a: 83 f8 ff cmp $0xffffffff, %eax 804845d: bb a0 94 04 08 mov $0x80494a0, %ebx 8048462: 74 0c je 8048470 <__do_global_ctors_aux+0x20> 8048464: 83 eb 04 sub $0x4, %ebx 8048467: ff d0 call *%eax 8048469: 8b 03 mov (%ebx), %eax 804846b: 83 f8 ff cmp $0xffffffff, %eax 804846e: 75 f4 jne 8048464 <__do_global_ctors_aux+0x14> 8048470: 58 pop %eax 8048471: 5b pop %ebx 8048472: c9 leave 8048473: c3 ret セクション .fini の逆アセンブル: 08048474 <_fini>: 8048474: 55 push %ebp 8048475: 89 e5 mov %esp, %ebp 8048477: 53 push %ebx 8048478: e8 00 00 00 00 call 804847d <_fini+0x9> 804847d: 5b pop %ebx 804847e: 81 c3 03 11 00 00 add $0x1103, %ebx 8048484: 52 push %edx 8048485: e8 7e fe ff ff call 8048308 <__do_global_dtors_aux> 804848a: 8b 5d fc mov 0xfffffffc(%ebp),%ebx 804848d: c9 leave 804848e: c3 ret
前のページ | 次のページ
NEW記事内インデックス    連載インデックスはこちら   Interfaceのトップ
最適化オプション
リスト
◆リスト(続き)

Copyright 2004 岸 哲夫

Copyright 1997-2004 CQ Publishing Co.,Ltd.