From owner-svn-src-head@FreeBSD.ORG Wed Nov 6 23:44:53 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id C88FB6DB; Wed, 6 Nov 2013 23:44:53 +0000 (UTC) (envelope-from kargl@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id B45B428E4; Wed, 6 Nov 2013 23:44:53 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rA6NirkR001252; Wed, 6 Nov 2013 23:44:53 GMT (envelope-from kargl@svn.freebsd.org) Received: (from kargl@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id rA6Niqkf001246; Wed, 6 Nov 2013 23:44:52 GMT (envelope-from kargl@svn.freebsd.org) Message-Id: <201311062344.rA6Niqkf001246@svn.freebsd.org> From: Steve Kargl Date: Wed, 6 Nov 2013 23:44:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r257770 - head/lib/msun/src X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Nov 2013 23:44:54 -0000 Author: kargl Date: Wed Nov 6 23:44:52 2013 New Revision: 257770 URL: http://svnweb.freebsd.org/changeset/base/257770 Log: * Use "math.h" instead of . * Use bit twiddling. This requires inclusion of math_private.h and inclusion of float.h in s_roundl.c. Raise invalid exception. * Use literal integer constants where possible. Let the compiler do the appropriate conversion. * In s_roundf.c, use an F suffix on float constants instead of promoting float to double and then converting the result back to float. In s_roundl.c, use an L suffix. * In s_roundl.c, use the ENTERI and RETURNI macros. This requires the inclusion of fpmath.h and on __i386__ class hardware ieeefp.h. Reviewed by: bde Modified: head/lib/msun/src/s_round.c head/lib/msun/src/s_roundf.c head/lib/msun/src/s_roundl.c Modified: head/lib/msun/src/s_round.c ============================================================================== --- head/lib/msun/src/s_round.c Wed Nov 6 23:29:25 2013 (r257769) +++ head/lib/msun/src/s_round.c Wed Nov 6 23:44:52 2013 (r257770) @@ -27,25 +27,28 @@ #include __FBSDID("$FreeBSD$"); -#include +#include "math.h" +#include "math_private.h" double round(double x) { double t; + uint32_t hx; - if (!isfinite(x)) - return (x); + GET_HIGH_WORD(hx, x); + if ((hx & 0x7fffffff) == 0x7ff00000) + return (x + x); - if (x >= 0.0) { + if (!(hx & 0x80000000)) { t = floor(x); if (t - x <= -0.5) - t += 1.0; + t += 1; return (t); } else { t = floor(-x); if (t + x <= -0.5) - t += 1.0; + t += 1; return (-t); } } Modified: head/lib/msun/src/s_roundf.c ============================================================================== --- head/lib/msun/src/s_roundf.c Wed Nov 6 23:29:25 2013 (r257769) +++ head/lib/msun/src/s_roundf.c Wed Nov 6 23:44:52 2013 (r257770) @@ -27,25 +27,28 @@ #include __FBSDID("$FreeBSD$"); -#include +#include "math.h" +#include "math_private.h" float roundf(float x) { float t; + uint32_t hx; - if (!isfinite(x)) - return (x); + GET_FLOAT_WORD(hx, x); + if ((hx & 0x7fffffff) == 0x7f800000) + return (x + x); - if (x >= 0.0) { + if (!(hx & 0x80000000)) { t = floorf(x); - if (t - x <= -0.5) - t += 1.0; + if (t - x <= -0.5F) + t += 1; return (t); } else { t = floorf(-x); - if (t + x <= -0.5) - t += 1.0; + if (t + x <= -0.5F) + t += 1; return (-t); } } Modified: head/lib/msun/src/s_roundl.c ============================================================================== --- head/lib/msun/src/s_roundl.c Wed Nov 6 23:29:25 2013 (r257769) +++ head/lib/msun/src/s_roundl.c Wed Nov 6 23:44:52 2013 (r257770) @@ -27,25 +27,36 @@ #include __FBSDID("$FreeBSD$"); -#include +#include +#ifdef __i386__ +#include +#endif + +#include "fpmath.h" +#include "math.h" +#include "math_private.h" long double roundl(long double x) { long double t; + uint16_t hx; + + GET_LDBL_EXPSIGN(hx, x); + if ((hx & 0x7fff) == 0x7fff) + return (x + x); - if (!isfinite(x)) - return (x); + ENTERI(); - if (x >= 0.0) { + if (!(hx & 0x8000)) { t = floorl(x); - if (t - x <= -0.5) - t += 1.0; - return (t); + if (t - x <= -0.5L) + t += 1; + RETURNI(t); } else { t = floorl(-x); - if (t + x <= -0.5) - t += 1.0; - return (-t); + if (t + x <= -0.5L) + t += 1; + RETURNI(-t); } }