From owner-freebsd-hackers Sun Mar 11 18:49:34 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from netau1.alcanet.com.au (ntp.alcanet.com.au [203.62.196.27]) by hub.freebsd.org (Postfix) with ESMTP id 4058537B718 for ; Sun, 11 Mar 2001 18:49:26 -0800 (PST) (envelope-from jeremyp@gsmx07.alcatel.com.au) Received: from mfg1.cim.alcatel.com.au (mfg1.cim.alcatel.com.au [139.188.23.1]) by netau1.alcanet.com.au (8.9.3 (PHNE_22672)/8.9.3) with ESMTP id NAA19124; Mon, 12 Mar 2001 13:48:22 +1100 (EDT) Received: from gsmx07.alcatel.com.au by cim.alcatel.com.au (PMDF V5.2-32 #37640) with ESMTP id <01K140VILS40OZ4MR3@cim.alcatel.com.au>; Mon, 12 Mar 2001 13:48:17 +1100 Received: (from jeremyp@localhost) by gsmx07.alcatel.com.au (8.11.1/8.11.1) id f2C2mCK14887; Mon, 12 Mar 2001 13:48:12 +1100 (EST envelope-from jeremyp) Content-return: prohibited Date: Mon, 12 Mar 2001 13:48:12 +1100 From: Peter Jeremy Subject: Re: Kernel area libmish stuff To: Jordan DeLong Cc: Farooq Mela , freebsd-hackers@freebsd.org Message-id: <20010312134812.A14108@gsmx07.alcatel.com.au> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-disposition: inline User-Agent: Mutt/1.2.5i Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Sat, 10 Mar 2001 21:37:28 -0800, Farooq Mela wrote: >Jordan DeLong wrote: >> I was thinking of just getting a sintable array and making a few simple >> functions, so the whole of libm doesn't need to be statically linked into the >> module (from my understanding, once loaded, this module wont ever get paged >+out, >> and thus it'd be _bad_ for it to be big). > >Well, you can't do any FP stuff inside the kernel, as stated by others. >But what you can do is use the fact that: > >sin(x) = x - (x^3)/3! + (x^5)/5! - (x^7)/7! ... Actually, whilst Taylor expansions are mathematically nice, they are generally a very poor implementation choice - primarily because they are infinite series and can be very slow to converge for large x. Trig functions are normally implemented as truncated Taylor series (you pick a finite expansion and tweak the co-efficients to minimise error), or ratios of polynomials. In both cases, the polynomials need to be `tuned' to suit the FP precision. If you do decide to go the fixed-point approach, remember that multiplication and division need fixups afterwards to re-align the binary point. (Multiplying two numbers with a 24 bit fraction gives a result with a 48 bit fraction). If you did pick a 24-bit fraction, you could probably pinch the co-efficients out of the `float' trig functions in msun. For a totally different approach, try Cordic algorithms. Cordic algorithms let you implement circular and hyperbolic functions (including exponential, log and sqrt) using add, subtract, shift and table lookup. (An n-bit result needs an n-entry x n-bit table, 2n shifts and 3n adds/subtracts). I know there was an article in October 1990 Dr Dobbs Journal and a web search should probably find plenty more. Peter To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message