Date: Sun, 12 Aug 2012 22:58:22 -0000 From: Steve Kargl <sgk@troutmask.apl.washington.edu> To: Peter Jeremy <peter@rulingia.com> Cc: Diane Bruce <db@db.net>, John Baldwin <jhb@freebsd.org>, David Chisnall <theraven@freebsd.org>, Stephen Montgomery-Smith <stephen@missouri.edu>, Bruce Evans <bde@freebsd.org>, Bruce Evans <brde@optusnet.com.au>, David Schultz <das@freebsd.org>, Warner Losh <imp@bsdimp.com> Subject: Re: Use of C99 extra long double math functions after r236148 Message-ID: <20120719234425.GA6280@troutmask.apl.washington.edu> Resent-Message-ID: <20120812225815.GM20453@server.rulingia.com> In-Reply-To: <20120719213944.GA21199@server.rulingia.com> References: <5004A5C7.1040405@missouri.edu> <5004DEA9.1050001@missouri.edu> <20120717040118.GA86840@troutmask.apl.washington.edu> <20120717042125.GF66913@server.rulingia.com> <20120717043848.GB87001@troutmask.apl.washington.edu> <20120717225328.GA86902@server.rulingia.com> <20120717232740.GA95026@troutmask.apl.washington.edu> <20120718001337.GA87817@server.rulingia.com> <20120718123627.D1575@besplex.bde.org> <20120719213944.GA21199@server.rulingia.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Jul 20, 2012 at 07:39:44AM +1000, Peter Jeremy wrote: > On 2012-Jul-18 14:01:42 +1000, Bruce Evans <brde@optusnet.com.au> wrote: > > >The standard classification macros are good for developing things, but > >they are very slow. All (?) committed complex functions use hard-coded > >bit test. > > I notice that the functions are full of hard-coded magic constants. > Would these be better as macros to: > 1) Provide a description as to their purpose; and > 2) Reduce differences between the float/long/double function bodies? > I collected some of the float and double into a cheat sheet. Idioms used in libm with float type: int32_t xsb; u_int32_t hx; GET_FLOAT_WORD(hx, x); /* Get the sign bit of x */ xsb = (hx >> 31) & 1; /* high word of |x| */ hx &= 0x7fffffff; /* NaN */ if (hx > 0x7f800000) return (x + x); /* exp(+-inf) = {inf, 0} */ if (hx == 0x7f800000) return (xsb == 0) ? x : 0.0; /* subnormal */ if (hx < 0x00800000) Idioms used in lib with double type: u_int32_t hx, lx, xsb EXTRACT_WORDS(hx, lx, x); /* sign bit of x */ xsb = (hx >> 31) & 1; /* high word of |x| */ hx &= 0x7fffffff; /* subnormal */ if (hx < 0x00100000) /* Test for NaN and +-Inf. */ if (hx >= 0x7ff00000) { /* Is it a NaN? */ if (((hx & 0xfffff) | lx) != 0) return (x + x); /* It's an +-Inf. */ return ((xsb == 0) ? x : 0.0); /* exp(+-inf)={inf,0} */ } -- Steve
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120719234425.GA6280>