J'essaie d'optimiser ce code de manière correcte. Ce que je veux dire par correct est ... J'imagine qu'il existe une approche générale pour effectuer ces optimisations de telle sorte que si quelqu'un d'autre regardait le code, il serait capable de supprimer les optimisations.Optimisation d'une boucle dans l'assemblage SPARC
échantillon C de code pour la lisibilité ...
int a = 1; // mapped to %l0
int b = 5; // mapped to %l1
int c = 0; // mapped to %l2
int d; // mapped to %l3
while(a < b) {
c += a * b;
++a;
}
d = c * b;
SPARC version montage ...
mov %g0, %l2
cmp %l0, %l1
bge END_LOOP
nop
LOOP:
mov %l0, %o0
call .mul
mov %l1, %o1 ! Fill delay slot with second argument
add %l2, %o0, %l2
inc %l0
cmp %l0, %l1
bl LOOP
nop
END_LOOP:
mov %l2, %o0
call .mul ! Fill delay sot with second argument
mov %l1, %o1
mov %o0, %l3
Je peux optimiser la première partie (pas sûr si correctement), mais je suis Je ne sais pas comment optimiser la deuxième partie.
mov %g0, %l2
cmp %l0, %l1
bge,a END_LOOP ! Annul branch to execute if branch is taken
mov %l2, %o0 ! Instruction at target
LOOP:
mov %l0, %o0
call .mul
mov %l1, %o1 ! Fill delay slot with second argument
add %l2, %o0, %l2
inc %l0
cmp %l0, %l1
bl LOOP
nop
mov %l2, %o0 ! Move the instruction to above the target
END_LOOP:
call .mul ! Fill delay sot with second argument
mov %l1, %o1
mov %o0, %l3
Toute aide sur la façon d'effectuer ces optimisations serait très appréciée.
Si vous ciblez SPARC v8 ou une version ultérieure, vous pouvez utiliser l'instruction 'SMUL' au lieu de passer un appel à la routine de la bibliothèque système' .mul'. – Michael
J'aurais probablement dû ajouter cela aussi. C'est une ancienne machine SPARC 32 bits. – logbaseinfinity