From owner-freebsd-hackers@freebsd.org Mon May 28 22:18:21 2018 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id AEBE5EF9563 for ; Mon, 28 May 2018 22:18:21 +0000 (UTC) (envelope-from sgk@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (troutmask.apl.washington.edu [128.95.76.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "troutmask", Issuer "troutmask" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 460A78E8E4; Mon, 28 May 2018 22:18:21 +0000 (UTC) (envelope-from sgk@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (localhost [127.0.0.1]) by troutmask.apl.washington.edu (8.15.2/8.15.2) with ESMTPS id w4SMIJ5r078144 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 28 May 2018 15:18:19 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.15.2/8.15.2/Submit) id w4SMIJwu078143; Mon, 28 May 2018 15:18:19 -0700 (PDT) (envelope-from sgk) Date: Mon, 28 May 2018 15:18:19 -0700 From: Steve Kargl To: Adhemerval Zanella Cc: Konstantin Belousov , freebsd-hackers@freebsd.org, emaste@freebsd.org Subject: Re: Code with apache-2 on /usr/src Message-ID: <20180528221819.GA77894@troutmask.apl.washington.edu> Reply-To: sgk@troutmask.apl.washington.edu References: <20180528190444.GE3789@kib.kiev.ua> <20180528193506.GA76705@troutmask.apl.washington.edu> <1c09023e-9bf5-d23a-dedc-1c4f4706bbde@linaro.org> <20180528202117.GA77184@troutmask.apl.washington.edu> <72101038-9e89-3f23-ab67-1c97b2a89803@linaro.org> <20180528210907.GA77475@troutmask.apl.washington.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.2 (2017-12-15) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 May 2018 22:18:21 -0000 On Mon, May 28, 2018 at 06:12:13PM -0300, Adhemerval Zanella wrote: > > >> And is having a different algorithm for single and double prevision > >> a blocker for a future patch proposal? > > > > No. Given the comment in sinf.c that max ULP is 0.56072, I do note that > > the current implementation of sinf in lib/msun is more accurate (for > > interesting values of x). I also looked at single/s_sincosf.c. It is > > rather dubious to have 80+ digit numerical constants for a float, which > > at most has 9 relevant digits. > > > > Also keep in mind my initial idea is to propose patches only to expf, powf, > logf, expf2, and log2f. OK, so I peeked at expf. Comment claims max ulp of 0.502. Exhaustive testing for normal numbers in relevent range for the current implementation of expf(x) shows Interval tested: [-18,88.72] ULP: 0.90951, x = -5.19804668e+00f, /* 0xc0a65666 */ flt = 5.52735012e-03f, /* 0x3bb51ec6 */ dbl = 5.5273505437686398e-03, /* 0x3f76a3d8, 0xdd1aae8e */ But, then one looks at implementation details. msun's current implementation is written in terms of single precision; while the routine you're suggesting is written in terms of double_t. So, achieving 0.502 ULP is due to having 53-bits in intermediate results. It appears that the algorithm of the suggested code cannot easily be generalized to double and long double without implementing a multiple-precision routines. Note, years ago, I submitted implementations for expf, exp, ld80/expl, ld128/expl, logf, log, ld80/logl, and ld128/logl based on papers by PTP Tang [1,2]. My versions for single and double precision were not adopted even though these had better accuracy. Either Bruce Evans improved or with Bruce's help I improved the ld80 and ld128 routines, which were added to msun. I know Bruce fixed minor issues with the single and double precision routines, but he has not submitted patches. 1. PTP Tang, "Table-driven implementation of the exponential function in IEEE floating-point arithmetic," ACM Trans. Math. Soft., 15, 144-157 (1989). 2. PTP Tang, "Table-driven implementation of the logarithm function in IEEE floating-point arithmetic," ACM Trans. Math. Soft., 16, 378-400 (1990). -- Steve