19.04.2013 Views

Apostila antiga - The Cyan Programming Language

Apostila antiga - The Cyan Programming Language

Apostila antiga - The Cyan Programming Language

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 5. OTIMIZAÇÃO DE CÓDIGO 47<br />

2. Uma multiplicação ou divisão é muito mais lenta do que uma soma, subtração ou deslocamento<br />

de bits.<br />

3. Operadores de manipulação de bits como & e | binários de C++ são muito mais rápidos do que<br />

as operações aritméticas.<br />

4. O uso de constantes é mais rápido do que o de variáveis:<br />

mov a, 2<br />

é mais rápido do que<br />

mov a, b<br />

Colocaremos o código original seguido do código otimizado dentro de um retângulo ou o código<br />

original seguido de uma barra horizontal seguido do código otimizado. As otimizações triviais não<br />

serão comentadas.<br />

1. mov t, a<br />

mov a, t<br />

mov t, a<br />

Este código pode ter sido o resultado da tradução de mais de uma linha do código fonte original,<br />

como<br />

t = a;<br />

a = t + 1;<br />

2. push a<br />

pop a<br />

(nada)<br />

3. cmp 5, 3<br />

goto L2<br />

L1: mov a, 1<br />

L2:<br />

goto L2<br />

L1: mov a, 1<br />

L2:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!