Qhov Tseem Ceeb Qhov Sib Txawv - Tshuab Dependent vs Machine Independent Code Optimization
Cov khoos phis tawj yog cov lus qhia muab rau kho vajtse, ua haujlwm. Cov kev pab cuam no feem ntau yog sau ua hom lus siab, thiab lub computer tsis to taub cov lus ntawd. Yog li ntawd, ib tug compiler yog siv los hloov cov lus qhia rau hauv tshuab code los yog phiaj code. Nws mus dhau ob peb theem los tsim lub hom phiaj code. Code optimization yog ib qho ntawm lawv. Muaj ob txoj kev optimization zoo li, tshuab nyob thiab tshuab ywj siab code optimization. Qhov sib txawv tseem ceeb ntawm lub tshuab dependent thiab tshuab ywj pheej code optimization yog tias lub tshuab nyob rau hauv optimization yog siv rau cov khoom code thaum lub tshuab ywj siab code optimization yog siv rau nruab nrab code.
Machine Dependent Code Optimization yog dab tsi?
Thaum hloov lub hauv paus code rau cov khoom siv lossis cov hom phiaj, cov neeg muab sau ua ke mus dhau ntau theem. Ua ntej, qhov chaws yog muab rau Lexical analyzer uas tsim cov tokens. Tom qab ntawd, cov zis tau muab rau syntax analyzer uas tshawb xyuas seb cov tokens generated puas yog qhov kev txiav txim siab. Cov zis ntawd yog muab rau lub semantic analyzer. Xav tias muaj ib daim code li p=q + r;
Ntawm no, p, q yog tus lej, tab sis r yog ntab. Siv cov kev ntsuas semantic, tus c integer sib txawv yog hloov mus rau ntab. Yog li ntawd, nws ua qhov kev ntsuam xyuas semantic. Cov zis ntawm lub semantic analyzer mus rau Intermediate code generator. Nws xa rov qab tus lej nruab nrab uas tom qab ntawd mus rau qhov zoo tshaj plaws code. Code optimization yog tus txheej txheem ntawm kev tshem tawm cov lus tsis tseem ceeb ntawm qhov kev pab cuam yam tsis hloov lub ntsiab lus ntawm qhov chaws tiag tiag. Nws tsis yog qhov yuav tsum tau ua kom zoo dua qub tab sis, nws tuaj yeem txhim kho lub sijhawm khiav ntawm lub hom phiaj code. Cov zis ntawm tus lej optimizer yog muab rau tus lej generator, thiab thaum kawg, lub hom phiaj code yog tsim.
Daim duab 01: Phase of the Compiler
Nyob rau hauv lub tshuab nyob ntawm kev ua kom zoo dua, kev ua kom zoo dua yog siv rau qhov chaws. Kev faib cov peev txheej txaus tuaj yeem txhim kho kev ua tiav ntawm qhov program hauv qhov kev ua kom zoo dua no.
Machine Independent Code Optimization yog dab tsi?
Thaum optimization ua tiav ntawm tus lej nruab nrab, nws yog hu ua tshuab ywj pheej code optimization. Muaj cov txheej txheem sib txawv rau kev ua tiav tshuab ywj pheej code optimization. Lawv tau piav qhia siv cov piv txwv hauv qab no.
Nyeem cov kab hauv qab no.
for (j=0; j<10; j++) {
b=x+2;
a[j]=5 j;
}
Raws li cov cai saum toj no, b=x + 2 yog xam dua thiab dua hauv txhua qhov iteration. Thaum xam b, nws tsis hloov. Yog li, cov kab no tuaj yeem muab tso rau sab nraum lub voj voog raws li hauv qab no.
b=x+2;
for (j=0; j< 10; j++)
{a[j]=5j;
}
Qhov no hu ua kev txav chaw.
Nyeem cov kab hauv qab no.
j=5;
if (j==10) {
a=b+20;
}
Raws li cov cai saum toj no, 'yog thaiv' yuav tsis ua haujlwm vim tias tus nqi j yuav tsis sib npaug li 10. Nws twb pib rau tus nqi 5. Yog li ntawd, qhov no yog thaiv tau tshem tawm. Cov txheej txheem no yog kev tshem tawm txoj cai tuag.
Lwm txoj kev yog txo lub zog. Kev ua lej lej zoo li kev sib faib yuav tsum muaj ntau lub cim xeeb, sijhawm, thiab CPU mus. Cov kab lus kim no tuaj yeem hloov tau los ntawm cov lus pheej yig xws li b=a2; los yog hloov tau los ntawm kev ntxiv, b=a + a;
Refer the below code.
for (j=1; j <=5; j++) {
value=j5;
}
Hloov pauv, tus lej tuaj yeem hloov pauv raws li hauv qab no.
int temp=5;
for (j=1; j<=5; j++) {
temp=temp + 5;
value=temp;
}
Nws tuaj yeem ntsuas cov kab lus uas yog qhov tsis tu ncua ntawm lub sijhawm ua haujlwm. Nws yog hu ua tas li folding. Muaj peev xwm hais tau xws li b[j+1]=c [j+1];
Xwb, nws tuaj yeem hloov tau raws li hauv qab no.
n=j +1;
b[n]=c[n];
Yuav muaj voj voog raws li hauv qab no.
for (j=0; j<5; j++) {
printf(“a\n”);
}
for (j=0; j <5; j++) {
printf(“b\n”);
}
Printing a thiab b, ob qho tib si muaj cov lej sib txawv. Ob leeg tuaj yeem muab tso ua ke rau ib lub voj voog raws li hauv qab no.
for (j=0; j <5; j++) {
printf(“a \n”);
printf(“b\n”);
}
Lwm cov txheej txheem tseem ceeb yog kev tshem tawm cov lus qhia sib txawv. Nws yog los hloov cov kab lus zoo ib yam nrog ib qho kev sib txawv los ua qhov kev suav. Xa mus rau tus lej hauv qab no.
a=bc + k;
d=b c + m;
Tus lej no tuaj yeem hloov pauv raws li hauv qab no.
temp=bc;
a=temp + k;
d=temp + m;
Nws tsis tas yuav suav bc dua thiab dua. Tus nqi sib npaug tuaj yeem khaws cia hauv qhov sib txawv thiab rov siv dua.
Dab tsi yog qhov zoo sib xws ntawm Machine Dependent thiab Machine Independent Code Optimization?
Ob leeg no muaj rau kev ua kom zoo dua
Dab tsi yog qhov sib txawv ntawm Tshuab Dependent thiab Tshuab Independent Code Optimization?
Machine Dependent vs Machine Independent Code Optimization |
|
Kev ua kom zoo ntawm lub tshuab ua kom zoo yog siv rau cov lej khoom. | Kev ua haujlwm ywj pheej ntawm tshuab yog siv rau cov lej nruab nrab. |
Kev koom tes nrog Hardware | |
Kev ua kom zoo dua ntawm lub tshuab suav nrog kev sau npe CPU thiab cov ntaub ntawv nco meej. | Kev ua haujlwm ywj pheej ntawm lub tshuab tsis suav nrog CPU sau npe lossis cov ntaub ntawv cim xeeb kiag li. |
Summary – Machine Dependent vs Machine Independent Code Optimization
Code optimization muaj ob txoj kev ua kom zoo tshaj plaws uas yog, tshuab nyob ntawm thiab tshuab ywj pheej code optimization. Qhov sib txawv ntawm tshuab dependent thiab tshuab ywj siab code optimization yog tias lub tshuab nyob rau hauv optimization yog siv rau cov khoom code whereas, lub tshuab ywj siab code optimization yog siv rau nruab nrab code.
Download the PDF Version of Machine Dependent vs Machine Independent Code Optimization
Koj tuaj yeem rub tawm PDF version ntawm kab lus no thiab siv nws rau offline lub hom phiaj raws li daim ntawv ceeb toom. Thov rub tawm PDF version ntawm no Qhov txawv Ntawm Tshuab Dependent thiab Tshuab Independent Code Optimization