From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/547 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: libm Date: Mon, 23 Jan 2012 17:41:52 +0100 Message-ID: <20120123164152.GZ31975@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1327336932 1861 80.91.229.12 (23 Jan 2012 16:42:12 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 23 Jan 2012 16:42:12 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-548-gllmg-musl=m.gmane.org@lists.openwall.com Mon Jan 23 17:42:07 2012 Return-path: Envelope-to: gllmg-musl@lo.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by lo.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1RpMy6-0007SE-ER for gllmg-musl@lo.gmane.org; Mon, 23 Jan 2012 17:42:06 +0100 Original-Received: (qmail 3887 invoked by uid 550); 23 Jan 2012 16:42:05 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 3878 invoked from network); 23 Jan 2012 16:42:05 -0000 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Xref: news.gmane.org gmane.linux.lib.musl.general:547 Archived-At: i've looked into libm implementations to figure out what's best for musl some resources: http://nsz.repo.hu/libm.txt there are various issues: * reproducible semantics: linux uses double extended precision by default on i386 which does not give the same results as standard 64bit ieee754 (sse2, x86_64, arm) bsd uses plain double precision by default on i386 (so at least when bsd functions are ported the precision claims should be reevaluated) most of the recent advances in efficient and correct function evaluation assume strict ieee754 64bit arithmetics (so they can do formal proofs etc, some algorithms assume fma instruction which is not available on musl's targets) portable semantics are not easy to guarantee (extended precision, rounding modes, compiler optimizations) (especially if efficiency is important as well) * tradeoffs: modern libms (libmcr, libultim, crlibm) try to guarantee correctness but arg reduction and faithful (or even correct) rounding is hard to do and hard to verify some libms prefer simple implementation (eg the go math package sincos is from cephes and starts to get inaccurate when |x| > 2^30, but the implementation is much simpler than the arg reduction in fdlibm) in theory one should prefer correctness instead of size and speed, but there are significant differences in code size and implementation effort the speed of a correct implementation can be good in average case, but not in worstcase * libms in practice: many functions are the same in glibc and the various bsd libcs (they are mostly based on fdlibm, but glibc 64bit double precision functions are from the gpl licensed libultim) the extended precision algorithms are reused across different libcs as well, but there are 80bit vs 128bit differences. the correctness of extended precision algorithms are much less studied (eg there are no correctly rounded versions or worstcases for 2pi arg reductions) most of the complex functions are simple once elementary functions are there (bsd libcs has bsd licensed implementations of these) conclusion: the simplest approach for musl at this point is to reuse the already available math functions (+run the available tests on them) this can be done by diffing the various bsd and glibc functions and choosing the best one (usually they are the same except code organization and bit manipulation details) most of the task is understanding floating point semantics well (not the mathematics of the algorithms) and doing code cleanups code and ideas from crlibm might be possible to use but that would take much more effort and knowledge (assuming we want small code size) designing new algorithms for elementary functions seems to require a huge effort and the best tradoffs are not even clear