From owner-freebsd-standards@FreeBSD.ORG Sun Dec 21 23:47:11 2003 Return-Path: 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 D002316A4CE for ; Sun, 21 Dec 2003 23:47:11 -0800 (PST) Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by mx1.FreeBSD.org (Postfix) with ESMTP id EB2E443D55 for ; Sun, 21 Dec 2003 23:47:05 -0800 (PST) (envelope-from bde@zeta.org.au) Received: from gamplex.bde.org (katana.zip.com.au [61.8.7.246]) by mailman.zeta.org.au (8.9.3p2/8.8.7) with ESMTP id SAA15863; Mon, 22 Dec 2003 18:46:59 +1100 Date: Mon, 22 Dec 2003 18:46:58 +1100 (EST) From: Bruce Evans X-X-Sender: bde@gamplex.bde.org To: "Steven G. Kargl" In-Reply-To: <200312212147.hBLLlGrr028043@troutmask.apl.washington.edu> Message-ID: <20031222182536.C7679@gamplex.bde.org> References: <200312212147.hBLLlGrr028043@troutmask.apl.washington.edu> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: freebsd-standards@freebsd.org Subject: Re: fenv.h implementation questions X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Dec 2003 07:47:12 -0000 On Sun, 21 Dec 2003, Steven G. Kargl wrote: > Is the following a sufficient implementation of fenv.h? > _fenv_t and _fexcept_t would be defined in machine/fenv.h, > which I haven't implemented, yet. I'm assuming that > these may be architecture specific (e.g., endianness). fenv_t and fexcept_t are very MD, and hopefully aren't needed in more than 1 file, so they should be declared directly in . > SuSv3 states that the exception and rounding mode macros > are to be defined *if and only if* the implementation > supports them. It also states that the function prototypes > that I've include need to be specified. However, why would > we need to specify, say, fegetround(), if the implementation > doesn't support control of the rounding mode? C99 says the same. I guess it is not expected that all rounding modes are unsupported (after all, there should be a default rounding mode and even if it is weird than it could be described by a nonstandard FE_ macro). fegetround() is needed if more than 2 rounding modes are supported and useful for avoiding special cases if only 1 rounding mode is supported. It is only not useful if no rounding mode is supported (since then it should not be called since it has no valid arg). > Finally, how the heck do we implement the #pragma at the end? Finish the relevant part of the C99 support in gcc, or wait for it. I think this is a large task. It would involve turning off certain optimizations within the FENV_ACCESS ON region. > #ifndef _FENV_H_ > #define _FENV_H_ > > #include > #include > > typedef fenv_t _fenv_t; > typedef fexcept_t _fexcept_t; > > #ifdef _EXCEPTIONS > #define FE_DIVBYZERO 0x00000001 /* Divide by zero */ > #define FE_INEXACT 0x00000002 /* Inexact flag raised */ > #define FE_INVALID 0x00000004 /* Invalid operation */ > #define FE_OVERFLOW 0x00000008 /* Overflow */ > #define FE_UNDERFLOW 0x00000010 /* Underflow */ > #define FE_ALL_EXCEPT 0x0000001F /* Bitwise-or of above flags */ > #endif /* _EXCEPTIONS */ > > #ifdef _ROUNDING_MODES > #define FE_DOWNWARD 0x00000020 /* Round downward */ > #define FE_TONEAREST 0x00000040 /* Round to nearest */ > #define FE_TOWARDZERO 0x00000080 /* Round towards zero */ > #define FE_UPWARD 0x00000100 /* Round upwards */ > #endif /* _ROUNDING_MODES */ These should probably all be MD. It saves a negative amount of code to use a common definition since larger code would be required to convert between the MI bits and the MI bits. > > #define FE_DFL_ENV (fenv_t const *) This needs to point to something. > > #if !defined(_FENV_INLINED_) > __BEGIN_DECLS > extern int feclearexcept(int); > extern int fegetenv(fenv_t *); > extern int fegetexceptflag(fexcept_t *, int); > extern int fegetround(void); > extern int feholdexcept(fenv_t *); > extern int feraiseexcept(int); > extern int fesetenv(const fenv_t *); > extern int fesetexceptflag(const fexcept_t *, int); > extern int fesetround(int); > extern int fetestexcept(int); > extern int feupdateenv(fenv_t *); > __END_DECLS > #endif /* !_FENV_INLINED_ */ I don't see much point in inlining these (like the i386 fp* versions). Marcel pointed out that inline versions are good for backwards compatibility (the library can be changed without affecting old interfaces), but we don't need that for standard interfaces. > > #if 0 > /* XXX Need to implement the FENV_ACCESS pragma */ > #endif > > #endif /* _FENV_H_ */ Bruce