segunda-feira, 18 de fevereiro de 2008

Integer Division

Some divisions are optimized into a multiplication and a shift.
The result of the mul operation is in two combined registers [edx:eax].
The value of edx is result/0xFFFFFFFF.
This optimization takes advantage of that fact:
(value*multiply/0xFFFFFFFF)>>shift =>; value*original

A multiplication followed by a division is sometimes optimized the same way.

MultiplyShiftOriginal
0x069C16BD0665/25756
0x10624DD341/250
0x10624DD351/500
0x10624DD361/1000
0x2AAAAAAB01/6
0x30C30C3131/42
0x38E38E3911/9
0x4EC4EC4F31/26
0x51EB851F51/100
0x5555555601/3
0x6666666711/5
0x6666666721/10
0x6666666731/20
0x6666666741/40
0x6666666751/80
0x6666666761/160
0x6666666771/320
0x6666666781/640
0x6BCA1AF351/76
0x8888888981/480
0x9249249331/14
0xA0A0A0A171/204
0xAAAAAAAB11/3
0xAAAAAAAB21/6
0xAAAAAAAB31/12
0xAAAAAAAB41/24
0xAE147AE1517/800
0xB21642C951/46
0xB60B60B751/45
0xBA2E8BA331/11
0xEA0EA0EB032/35

Note: these optimization are only used if the resulting value doesn't lose precision in comparison to the original operation.

Sem comentários:

Enviar um comentário