Aha! is a program of the superoptimizer type that can be used to find short branch-free code sequences for certain simple functions such as
- the absolute value function,
- a comparison predicate such as and
- swapping the two low-order bits of a register.
It works by exhaustive search over programs of a given length. As a practical matter the length is limited to four instructions for most machines.
It can be fun to play around with this program.
A perhaps more subtle thing to notice is that the function to be optimized is written in C, and the superoptimizer relies on the C compiler to compile it correctly. The optimizer itself doesn't understand C, nor does it have to.
Posted to fun by Ehud Lamm on 5/11/03; 2:15:43 AM
|