www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/04/00:50:17

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: fixed point math
Date: Thu, 03 Jul 1997 19:53:33 +0000
Organization: Two pounds of chaos and a pinch of salt
Lines: 44
Message-ID: <33BC033D.2460@cs.com>
References: <33BBCEEB DOT 2714D41B AT execulink DOT com>
Reply-To: fighteer AT cs DOT com
NNTP-Posting-Host: ppp102.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Jeff Weeks wrote:
> 
> I once had some fixed point assembly language routines (divide and
> multiply), but can't find them any more.  I was wondering if anybody
> could tell me where I could find some?  I don't think I could write them
> myself and get the same speed, unfortunately.
> 
> Also, do you think these assembly language routines would be faster than
> simply shifting and performing an actual multiply or divide?

Allegro has fixed point routines in its library; you might want to look
there.

I wrote some basic fixed point routines to use in one of my programs; I
used plain C instead of assembly, and declared everything inline and
register.  I don't do a lot of fixed point calculations, but with full
optimizations on this code shouldn't be much slower than pure assembly
(and it's a lot easier to understand).

The one caveat (like Shawn stated) is that you have to use casts to
'long long' in the intermediate stages of multiplication and division. 
This might slow the code down unacceptably; I don't know.

In any case, here is my source for 16.16 multiplication and division:

inline FIX16 mulfix( FIX16 a, FIX16 b )
{
    return (long long) a * b / 65536;
}

inline FIX16 divfix( FIX16 a, FIX16 b )
{
    return (long long) a * 65536 / b;
}

Simple, eh?  ;)

-- 
---------------------------------------------------------------------
|      John M. Aldrich       | "Deductive logic is tautological;    |
|       aka Fighteer I       | there is no way to get a new truth   |
|   mailto:fighteer AT cs DOT com   | out of it."                          |
| http://www.cs.com/fighteer |                 - Lazarus Long       |
---------------------------------------------------------------------

- Raw text -


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