From owner-freebsd-numerics@FreeBSD.ORG Fri Mar 13 03:58:33 2015 Return-Path: Delivered-To: freebsd-numerics@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 5E2F7A3A for ; Fri, 13 Mar 2015 03:58:33 +0000 (UTC) Received: from mail-ie0-x233.google.com (mail-ie0-x233.google.com [IPv6:2607:f8b0:4001:c03::233]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 23457F2 for ; Fri, 13 Mar 2015 03:58:30 +0000 (UTC) Received: by iegc3 with SMTP id c3so81887854ieg.3 for ; Thu, 12 Mar 2015 20:58:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=wPCQFP2mAsAka5YWCdyecJXJN2M2UnRqKSVa+k/reAw=; b=GG43+ofDjD8MQ2zdp/f0EeTrYTfDYGqKIDxE7wt4fXo9ubbsP3FaLpRyye2m5yMb03 rua1L4j1cuX+qnCn8mDTOLFI4HwAUPfCn083JoHnr9wt4RmBwryB/Iy5GiWImEmeeHVT vGogDS8ltaqU8E9XD3CZIRo2w/DSj7QOKxMikCr78LRHn57yD2oFKns6HZnQxslgxXbh V63GZrOouBTdpTJh3Kz3j72Em5iVrE/qWf4MgifVXVHjCj1Hc2grqy1v8wYooKD8xUYS 2m0DmSG8fFVvmUZrgHZ+1qsQxfYCE4abicLlEx/MSzZJmuZFwP9nXgvwak6w/DlGjDtv RcyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to :content-type; bh=wPCQFP2mAsAka5YWCdyecJXJN2M2UnRqKSVa+k/reAw=; b=hBew13VzRm/RByR+Fg7b5Yb1VZEDNDeLxmaAJ11pe6+6TG0nIxaSBsjPLJzcIzjiTv F5lKXSIzV53Kle0Dd8aEWdkpTaEF2Zaz+EY6rfvBOvmlJPfL4Xs6I9N0R9R88iqQ5QZB mQf298164qNRgGSN+TuxWirx9aDg4AhkyfdmjXPp3q3ZQmHiHWoM5GIxF58qsPyWZlh7 +5dgbBX3R+Fobs2CigCEmHu1BxXFuPz0I0e875p39TbceMIjpImeqjMrWXP2Yn/f2xRc lADYAr+CyxYv+payOp5h92w2o4g/Do63jUILSAlHbSMbTprqrH8SU8Seu3HqUHLO4t5H NCxA== X-Gm-Message-State: ALoCoQkn67M/HqMe5/epwLFwUEgs+rakBTNiG2yyxkIs4ODIzFnrue7PZufqXwmD45coUYo6C4WK X-Received: by 10.107.135.212 with SMTP id r81mr56011877ioi.38.1426219108157; Thu, 12 Mar 2015 20:58:28 -0700 (PDT) MIME-Version: 1.0 Received: by 10.36.25.129 with HTTP; Thu, 12 Mar 2015 20:58:06 -0700 (PDT) From: enh Date: Thu, 12 Mar 2015 20:58:06 -0700 Message-ID: Subject: libm functions sensitive to current rounding mode To: freebsd-numerics@freebsd.org Content-Type: text/plain; charset=UTF-8 X-BeenThere: freebsd-numerics@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "Discussions of high quality implementation of libm functions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Mar 2015 03:58:33 -0000 various SoC vendors have been sending us (Android) assembler implementations of various libm functions, and we noticed when looking at one change that it was slower on certain inputs than the FreeBSD C implementation we were already using. the response was that the cost was coping with other rounding modes, and they gave this example: #include #include #include int main(){ double x = -0xb.6365e22ee46fp4; fesetround(FE_UPWARD); printf("sin(%f) = %.16e\n", x, sin(x)); fesetround(FE_DOWNWARD); printf("sin(%f) = %.16e\n", x, sin(x)); x = 0x1.921fb54442d16p0; fesetround(FE_UPWARD); printf("sin(%f) = %.16e\n", x, sin(x)); fesetround(FE_DOWNWARD); printf("sin(%f) = %.16e\n", x, sin(x)); return 0; } see https://android-review.googlesource.com/112700 for the original change and related conversation. glibc 2.19: sin(-182.212373) = -2.4759225463534308e-18 sin(-182.212374) = -2.4759225463534309e-18 sin(1.570797) = 1.0000000000000000e+00 sin(1.570796) = 1.0000000000000000e+00 (glibc's fixed bugs here in the past. see https://sourceware.org/bugzilla/show_bug.cgi?id=3976 for example.) the FreeBSD libm: sin(-182.212374) = -2.4759225463534304e-18 sin(-182.212374) = 2.2575413760606011e-11 sin(1.570796) = 1.0000000000000000e+00 sin(1.570796) = 1.0000000002522276e+00 it looks like e_sqrtl.c, s_fmal.c, s_fma.c, and s_fmaf.c save/restore the rounding mode but nothing else does. let me know if you'd like me to send trivial patches for any of the affected functions. (do all the libm functions need this?) -- Elliott Hughes - http://who/enh - http://jessies.org/~enh/ Android native code/tools questions? Mail me/drop by/add me as a reviewer.