A little bit more about the compiler's different levels of optimization

Source: Internet
Author: User
Experimental Purpose

In a programming language, you can compare code writing in different programming styles, or generate assembly code from a compiler by using different compilers and compilation optimization parameters, and statically analyze the efficiency of the generated assembly code. experimental platform, tools

Under the Windows platform, use the VC6.0 tool.

Experimental design

Optimized comparison of redundant code by the same compiler at different levels of optimization.

int main ()

{

int a=0;

int b=1;

int c=2;

int d=3;

int e=4;

C=a+b;

return C;

}



The following is a compilation and code integration without optimized generation

_main PROC near; Comdat

; 4: {

Pushebp

MOVEBP, ESP

SUBESP, 84; 00000054H

Pushebx

Pushesi

Pushedi

Leaedi, DWORD PTR [ebp-84]

MOVECX, 21; 00000015H

Moveax,-858993460; Cccccccch

Rep STOSD

; 5:int a=0;

Movdword PTR _A$[EBP], 0

; 6:int b=1;

Movdword PTR _B$[EBP], 1

; 7:int c=2;

Movdword PTR _C$[EBP], 2

; 8:int d=3;

Movdword PTR _D$[EBP], 3

; 9:int e=4;

Movdword PTR _E$[EBP], 4

; 10:c=a+b;

Moveax, DWORD PTR _A$[EBP]

Addeax, DWORD PTR _B$[EBP]

Movdword PTR _C$[EBP], eax

; 11:return C;

Moveax, DWORD PTR _C$[EBP]

; 12:

; 13:}

Pop EDI

Pop esi

Pop ebx

mov esp, EBP

Pop EBP

RET 0

_main ENDP

}


The following is the release optimization level of code and compilation

_main PROC near; Comdat

; 5:int a=0;

; 6:int b=1;

; 7:int c=2;

; 8:int d=3;

; 9:int e=4;

; 10:c=a+b;

; 11:return C;

Moveax, 1

; 12:

; 13:}

RET 0

_main ENDP




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.