Mail Archives: djgpp/1997/02/01/10:37:20
>If *ALL* integer mults/divs are converted to shifts, then what would
>be the equivalent for:
>
>other_stuff = stuff * 57
Ask gcc. Write a little function:
int times57(int stuff)
{
return stuff * 57;
}
Compile it with 'gcc -m486 -O3 test.c -S', and you get:
_times57:
pushl %ebp
movl %esp,%ebp
movl 8(%ebp),%edx # edx = stuff
leal (%edx,%edx,2),%eax # eax = stuff * 3
leal (%edx,%eax,2),%eax # eax = stuff * 7
leal (%edx,%eax,8),%eax # eax = stuff * 57
movl %ebp,%esp
popl %ebp
ret
Rather faster than a multiply! This doesn't work for divides, though:
they will produce a genuine division instruction unless they are by
powers of two.
/*
* Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
* Ghoti: 'gh' as in 'enough', 'o' as in 'women', and 'ti' as in 'nation'.
*/
- Raw text -