🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.intel
Article #874

Fixed point multiplication on 386

#874
From: russell wallace
Date: Fri, 16 Oct 1992 18:58
45 lines
1790 bytes
Does anyone know how to do fast 32-bit fixed point multiplication on a
386? The numbers involved are stored with the high 16 bits before the
decimal point and the low 16 bits after it, and signed. I wrote the
following function in C, and compiled it under Zortech C version 3, and
it ended up as about 50 machine instructions, which on my 33 MHz 386
works out as about 100,000 multiplications per second. Considering that
the Zortech single-precision floating-point libraries can get the same
machine (without floating-point hardware) to ~200 Kflops, there would
seem to be little point in using fixed point, and I can't figure out how
to shave more than a few clock cycles off the compiler's code. If
anyone knows of a faster solution, it would be much appreciated.

typedef long num;
 
num mul (num x,num y)
{
	long xh,xl,yh,yl,result;
	int sign;
 
	sign = 0;
	if (x < 0)
	{
		x = -x;
		sign = 1;
	}
	if (y < 0)
	{
		y = -y;
		sign = 1 - sign;
	}
	xh = x >> 16;
	xl = x & 0xffff;
	yh = y >> 16;
	yl = y & 0xffff;
	result = (xh*yh << 16) + (xh*yl) + (yh*xl) + (xl*yl >> 16);
	if (sign)
		return -result;
	return result;
}


--
"To summarize the summary of the summary: people are a problem"
Russell Wallace, Trinity College, Dublin
rwallace@unix1.tcd.ie
Technical Details
Message-ID: <rwallace.719261884@unix1.tcd.ie>
Path: arc1-ca.pugleaf.net!sparky!uunet!know!hri.com!ukma!usenet.ins.cwru.edu!gatech!paladin.american.edu!news.univie.ac.at!hp4at!mcsun!ieunet!tcdcs!unix1.tcd.ie!rwallace

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!know!hri.com!ukma!usenet.ins.cwru.edu!gatech!paladin.american.edu!news.univie.ac.at!hp4at!mcsun!ieunet!tcdcs!unix1.tcd.ie!rwallace
From: rwallace@unix1.tcd.ie (russell wallace)
Newsgroups: comp.sys.intel
Subject: Fixed point multiplication on 386
Message-ID: <rwallace.719261884@unix1.tcd.ie>
Date: 16 Oct 92 18:58:04 GMT
Sender: usenet@cs.tcd.ie (NN required at ashe.cs.tcd.ie)
Organization: Trinity College, Dublin
Lines: 45
Nntp-Posting-Host: unix1.tcd.ie