1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
//Fonction Initiale :
void Fonction1()
{
for (int i=0; i<MAX; i++)
{
tab[i] = a * i * i + b * i + c + d;
}
}
/*
@5:
mov ecx,dword ptr [_a]
mov ebx,dword ptr [_b]
imul ecx,eax ; a * i
imul ecx,eax ; a * i * i
imul ebx,eax ; b * i
add ecx,ebx ; a * i * i + b * i
add ecx,dword ptr [_c] ; a * i * i + b * i + c
add ecx,dword ptr [_d] ; a * i * i + b * i + c + d
mov dword ptr [edx],ecx ; tab[i] = a * i * i + b * i + c + d;
@7:
inc eax ; i++
add edx,4 ; edx = &tab[i] + 4
cmp eax,10000 ; Si i < MAX
jl short @5 ; alors Nouvelle Ittération
La seule optimisation est une utilisation de varaible pour stocker l'adresse de
tab[i]. En revanche ici, aucune multiplication, puisque l'optimisation entraine
a ajouter 4 et non recalculer l'adresse a chaque fois.
Je ne vois pas pouquoi mon compilateur remet a et b a chaque fois dans ecx et
ebx. C'est parfaitement inutile. Serait-il sot ?
*/
//Forme Recursive. Gain : ~50 % :
void Fonction2()
{
tab[0] = c + d;
int x = b - a - c - d;
int y = 0;
int a2 = 2 * a;
for (int i = 1 ; i < MAX ; i++)
{
y += a2;
tab[i] = tab[i-1] + y + x;
}
}
/*
@12:
add edx,esi
mov edi,dword ptr [eax]
add edi,edx
add edi,ebx
mov dword ptr [eax+4],edi
@14:
inc ecx
add eax,4
cmp ecx,10000
jl short @12
*/
//Suppression des calculs inutiles. Gain ~25 % :
void Fonction3()
{
tab[0] = c + d;
int x = b - a - c - d;
int y = a * 2;
for (int i = 1 ; i < MAX ; i++)
{
x += y;
tab[i] = tab[i-1] + x;
}
}
/*
@19:
add edx,ebx
mov esi,dword ptr [eax]
add esi,edx
mov dword ptr [eax+4],esi
@21:
inc ecx
add eax,4
cmp ecx,10000
jl short @19
*/
//Utilisation de pointeur dans la boucle. Gain ridicule :
void Fonction4()
{
tab[0] = c + d;
int x = b - a - c - d;
int y = a * 2;
/*
Normalement tab + MAX est fixe a la compilation mais mon
compilateur refuse d'effectuer le calcul. J'ai donc utilisé
la variable q
*/
for (int* p = tab, *q = tab + MAX ; p < q ; p++)
{
x += y;
*p = p[-1] + x;
}
}
/*
Note : Ca sert juste a supprimer le inc ecx
@26:
add edx,ecx
mov esi,dword ptr [eax-4]
add esi,edx
mov dword ptr [eax],esi
@28:
add eax,4
cmp ebx,eax
ja short @26
*/
//Variable intermediaire. Gain : ~30 %
void Fonction5()
{
tab[0] = c + d;
int x = b - a - c - d;
int y = a * 2;
int z = tab[0];
for (int* p = tab, *q = tab + MAX ; p < q ; p++)
{
x += y;
z += x;
*p = z;
}
}
/*
@33:
add edx,ebx
add ecx,edx
mov dword ptr [eax],ecx
@35:
add eax,4
cmp esi,eax
ja short @33
*/ |
Partager