From owner-freebsd-standards Sun Feb 9 3:38:47 2003 Delivered-To: freebsd-standards@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2C26E37B401 for ; Sun, 9 Feb 2003 03:38:46 -0800 (PST) Received: from HAL9000.homeunix.com (12-233-57-224.client.attbi.com [12.233.57.224]) by mx1.FreeBSD.org (Postfix) with ESMTP id 82B4643FA3 for ; Sun, 9 Feb 2003 03:38:45 -0800 (PST) (envelope-from dschultz@uclink.Berkeley.EDU) Received: from HAL9000.homeunix.com (localhost [127.0.0.1]) by HAL9000.homeunix.com (8.12.6/8.12.5) with ESMTP id h19BcioH001267; Sun, 9 Feb 2003 03:38:45 -0800 (PST) (envelope-from dschultz@uclink.Berkeley.EDU) Received: (from das@localhost) by HAL9000.homeunix.com (8.12.6/8.12.5/Submit) id h19BciB4001266; Sun, 9 Feb 2003 03:38:44 -0800 (PST) (envelope-from dschultz@uclink.Berkeley.EDU) Date: Sun, 9 Feb 2003 03:38:44 -0800 From: David Schultz To: Bruce Evans Cc: Lukas Ertl , standards@FreeBSD.ORG Subject: Re: C99 floating point macros Message-ID: <20030209113844.GA535@HAL9000.homeunix.com> Mail-Followup-To: Bruce Evans , Lukas Ertl , standards@FreeBSD.ORG References: <20030209003350.GA20683@HAL9000.homeunix.com> <20030209200824.R24643-100000@gamplex.bde.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030209200824.R24643-100000@gamplex.bde.org> Sender: owner-freebsd-standards@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Thus spake Bruce Evans : > On Sat, 8 Feb 2003, David Schultz wrote: > > > Thus spake Lukas Ertl : > > > Ok, please review the following patch. I hope I didn't take it too easy. > > > > Hmm...why not just use some macros, like this? > > > > #define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y)) > > #define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y)) > > #define isless(x, y) (!isunordered((x), (y)) && (x) < (y)) > > #define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y)) > > #define islessgreater(x, y) (!isunordered((x), (y)) && \ > > ((x) > (y) || (y) > (x))) > > #define isunordered(x, y) (isnan(x) || isnan(y)) > > If there were no signaling NaNs, then the even simpler macros: > > #define isgreater(x, y) ((x) > (y)) > > etc., would work on i386's at least, since gcc generates comparison > instructions (fucom, not fcom) which don't raise the invalid exception > (IE) for quiet NaNs. > > However, not raising IE for signaling NaNs seems to be necessary (to > support C99's interpretation of IEC 60559:1989). At least on i386's, > this is handled by isunordered() above provided we unbreak isnan() so > that just calling it doesn't raise IE for float and long double signaling > NaNs. (isnan() needs to be a macro since converting its arg to a > common type doesn't work if the arg is a signaling NaN although it > works in all other cases. Even on i386's it is not clear that args > can be and are always passed to isnan() without invoking the FPU in a > way that would raise IE for signaling NaNs. Similarly for fpclassify().) In the patches I sent Mike a few hours ago, I used the above code and additionally reimplemented isnan(), isinf() and friends as macros that call fpclassify(). The slightly defective function versions would be retained in libc until FreeBSD 6.0 for binary compatibility. I'm not sure whether it's worthwhile to optimize the comparison routines, but I would be willing to write the i386 versions in assembly with MI fallbacks for other architectures if someone thinks that it is important. For the classification routines (is{nan,inf,finite,normal}), there seems to be less reason to optimize; fpclassify() costs at most one or two masks and comparisons more than we would otherwise pay. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-standards" in the body of the message