www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/01/10:37:20

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: fixed point math: NEED HELP QUICK!
Date: Sat, 1 Feb 1997 11:36:26 +0000
Organization: None
Distribution: world
Message-ID: <0MfOUIA6qy8yEw2n@talula.demon.co.uk>
References: <19970128 DOT 181621 DOT 14527 DOT 2 DOT chambersb AT juno DOT com>
<Pine DOT LNX DOT 3 DOT 95 DOT 970131164737 DOT 140G-100000 AT capslock DOT com>
NNTP-Posting-Host: talula.demon.co.uk
MIME-Version: 1.0
Lines: 33
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

>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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019