From owner-freebsd-current Thu Oct 24 1:33:23 2002 Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 10D1737B401 for ; Thu, 24 Oct 2002 01:33:21 -0700 (PDT) Received: from motgate2.mot.com (motgate2.mot.com [136.182.1.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id B5C0043E6E for ; Thu, 24 Oct 2002 01:33:19 -0700 (PDT) (envelope-from rittle@latour.rsch.comm.mot.com) Received: [from pobox4.mot.com (pobox4.mot.com [10.64.251.243]) by motgate2.mot.com (motgate2 2.1) with ESMTP id BAA04508; Thu, 24 Oct 2002 01:33:24 -0700 (MST)] Received: [from latour.rsch.comm.mot.com (latour.rsch.comm.mot.com [145.1.80.116]) by pobox4.mot.com (MOT-pobox4 2.0) with ESMTP id BAA11764; Thu, 24 Oct 2002 01:33:12 -0700 (MST)] Received: from latour.rsch.comm.mot.com (localhost.rsch.comm.mot.com [127.0.0.1]) by latour.rsch.comm.mot.com (8.12.6/8.12.6) with ESMTP id g9O8XBpZ033885; Thu, 24 Oct 2002 03:33:11 -0500 (CDT) (envelope-from rittle@latour.rsch.comm.mot.com) Received: (from rittle@localhost) by latour.rsch.comm.mot.com (8.12.6/8.12.6/Submit) id g9O8XB1W033884; Thu, 24 Oct 2002 03:33:11 -0500 (CDT) Date: Thu, 24 Oct 2002 03:33:11 -0500 (CDT) From: Loren James Rittle Message-Id: <200210240833.g9O8XB1W033884@latour.rsch.comm.mot.com> To: current@freebsd.org Subject: Lack of real long double support (was Re: libstdc++ does not contain fabsl symbol) In-Reply-To: <20021023123653.A39814@espresso.q9media.com> References: <20021020025400.GA13776@xor.obsecurity.org> Organization: Networks and Infrastructure Lab (IL02/2240), Motorola Labs Cc: rittle@latour.rsch.comm.mot.com Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG >> Note that while you're adding the C99 math stuff, you >> might want to fix up float.h, which is just wrong about long >> doubles (see PR i386/38288). > Right, I should have said no one has started committing C99 math > functions. (Reading this exchange reminded me that I promised fellow gcc developers to check on this issue with FreeBSD developers.) The gcc mainline (what will become 3.3) recently got a new implementation of ``software floating point emulation'' (contained in gcc/real.[hc] which is used to format all compile-time FP constants, etc). Along with that change, the compiler wants to provide a copy of generated from its own knowledge of FP hardware instead of sucking information from /usr/include/float.h, as it had done in past gcc releases. I know that when we install gcc as the FreeBSD system compiler, we don't bother with such header files provided from gcc (but, for the moment please consider that people might build cross-compilers to FreeBSD and please consider that we test future releases of gcc as might be used as the FreeBSD system compiler from FSF sources). Anyways, that work exposed some issues. We have this in the system header: #define LDBL_MANT_DIG DBL_MANT_DIG #define LDBL_MIN_EXP DBL_MIN_EXP #define LDBL_MAX_EXP DBL_MAX_EXP [...] Yet, the FP hardware is actually configured by default to provide `long double' as: #define LDBL_MANT_DIG 53 #define LDBL_MIN_EXP (-16381) #define LDBL_MAX_EXP 16384 Indeed, FP code using long double generated by gcc 2.95.X, installed as the FreeBSD 4 system compiler, uses the full exponent range of -16381 to 16384. However, printf(), etc loses on that exponent range and reports Inf. I suspect this is why the system header misreports the FP hardware, thus the header describes the largest printable long double value, not the largest that could be held in a calculation. Anyways, two questions for FreeBSD maintainers. How should gcc, as provided from the FSF, describe the long double FP format for FreeBSD/i386 4.x? Shall we assume that no changes for FreeBSD 5.x will occur? Unless someone strongly prefers otherwise, the I lean towards wanting to describe the default FP hardware setup exactly and assume that libc changes to properly support long double stdio, etc will follow at some point. However, that also brings to mind: Are we happy with the current default FP hardware setup especially if support for long double is to be improved? At the moment we support long double in name only. There is no extra dynamic range over a double; as might be implied (and allowed by the hardware). Also, as an aside, having just learned everything there is to know about IEEE FP from a witty 80-slide presentation on the WWW by one of the original designers of the spec@Berkeley, I'd say that he would be sad that we default to use 53-bit precision mode. I'd say that it is dumb to claim we even support long double unless we change that to 64-bit precision mode... Regarding the comment in sys/i386/include/npx.h: * 64-bit precision often gives bad results with high level languages * because it makes the results of calculations depend on whether * intermediate values are stored in memory or in FPU registers. This is pure bunk when considered in broad context. Using 53-bit precision mode with high level languages while making actual calculations yields more outright undetectable precision-related errors due to algorithm design by non-numerical analysts. I know which error I'd rather *not* find in my naively-written and compiled FP code. People that write their FP code to correctly use epsilon (the one appropriate for the type of the float they are using) should never see this problem, no? I don't see why FreeBSD should cater to people that don't know how to write FP code properly (i.e. anyone that expected exact results across compilation switches, etc) at the expense of being able to write code that fully utilizes the best mode available from the CPU. People that absolutely want to avoid the problem of spilling from register to memory truncation changing with optimization level may feel free to allocate long doubles instead of doubles. Problem solved. Anyways, that is my quick speech in favor of change. I will help commit bits to the FSF gcc tree that supports whatever people want to do. It is easy to support one FP model for FreeBSD 4 and another for FreeBSD 5. Regards, Loren To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message