From nobody Tue Nov 02 01:17:03 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 082E218264F9; Tue, 2 Nov 2021 01:17:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HjsSc1b7tz3D0d; Tue, 2 Nov 2021 01:17:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5B2991BB63; Tue, 2 Nov 2021 01:17:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1A21H33M078737; Tue, 2 Nov 2021 01:17:03 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1A21H3nM078736; Tue, 2 Nov 2021 01:17:03 GMT (envelope-from git) Date: Tue, 2 Nov 2021 01:17:03 GMT Message-Id: <202111020117.1A21H3nM078736@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 5033d0b56f5b - stable/13 - sinpi[fl] etc: Fix the ld128 implementations List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 5033d0b56f5be90fcca4ede92f28f9335eb20b4a Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=5033d0b56f5be90fcca4ede92f28f9335eb20b4a commit 5033d0b56f5be90fcca4ede92f28f9335eb20b4a Author: Steve Kargl AuthorDate: 2021-10-31 22:26:20 +0000 Commit: Konstantin Belousov CommitDate: 2021-11-02 01:16:29 +0000 sinpi[fl] etc: Fix the ld128 implementations PR: 218514 (cherry picked from commit 4f889260c33c163ab28e0e082b4d7e7562d9c647) --- lib/msun/ld128/s_cospil.c | 31 +++++++++++++++++-------------- lib/msun/ld128/s_sinpil.c | 29 ++++++++++++++++------------- lib/msun/ld128/s_tanpil.c | 23 +++++++++++++---------- 3 files changed, 46 insertions(+), 37 deletions(-) diff --git a/lib/msun/ld128/s_cospil.c b/lib/msun/ld128/s_cospil.c index b4bc50bb4d89..71acc4485f7b 100644 --- a/lib/msun/ld128/s_cospil.c +++ b/lib/msun/ld128/s_cospil.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2017 Steven G. Kargl + * Copyright (c) 2017-2021 Steven G. Kargl * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,9 +26,6 @@ /* * See ../src/s_cospi.c for implementation details. - * - * FIXME: This has not been compiled nor has it been tested for accuracy. - * FIXME: This should use bit twiddling. */ #include "math.h" @@ -54,7 +51,7 @@ cospil(long double x) ax = fabsl(x); - if (ax < 1) { + if (ax <= 1) { if (ax < 0.25) { if (ax < 0x1p-60) { if ((int)x == 0) @@ -75,15 +72,21 @@ cospil(long double x) } if (ax < 0x1p112) { - xf = floorl(ax); - ax -= xf; - if (x < 0.5) { - if (x < 0.25) + /* Split x = n + r with 0 <= r < 1. */ + xf = (ax + 0x1p112L) - 0x1p112L; /* Integer part */ + ax -= xf; /* Remainder */ + if (ax < 0) { + ax += 1; + xf -= 1; + } + + if (ax < 0.5) { + if (ax < 0.25) c = ax == 0 ? 1 : __kernel_cospil(ax); else c = __kernel_sinpil(0.5 - ax); } else { - if (x < 0.75) { + if (ax < 0.75) { if (ax == 0.5) return (0); c = -__kernel_sinpil(ax - 0.5); @@ -91,10 +94,10 @@ cospil(long double x) c = -__kernel_cospil(1 - ax); } - if (xf > 0x1p50) - xf -= 0x1p50; - if (xf > 0x1p30) - xf -= 0x1p30; + if (xf > 0x1p64) + xf -= 0x1p64; + if (xf > 0x1p32) + xf -= 0x1p32; ix = (uint32_t)xf; return (ix & 1 ? -c : c); } diff --git a/lib/msun/ld128/s_sinpil.c b/lib/msun/ld128/s_sinpil.c index 39eed9b007bc..cdfa2bcac3ef 100644 --- a/lib/msun/ld128/s_sinpil.c +++ b/lib/msun/ld128/s_sinpil.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2017 Steven G. Kargl + * Copyright (c) 2017-2021 Steven G. Kargl * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,9 +26,6 @@ /* * See ../src/s_sinpi.c for implementation details. - * - * FIXME: This has not been compiled nor has it been tested for accuracy. - * FIXME: This should use bit twiddling. */ #include "math.h" @@ -68,7 +65,7 @@ sinpil(long double x) } s = __kernel_sinpil(ax); - return (copysignl(s, x)); + return (x < 0 ? -s : s); } if (ax < 0.5) @@ -77,12 +74,18 @@ sinpil(long double x) s = __kernel_cospil(ax - 0.5); else s = __kernel_sinpil(1 - ax); - return (copysignl(s, x)); + return (x < 0 ? -s : s); } if (ax < 0x1p112) { - xf = floorl(ax); - ax -= xf; + /* Split x = n + r with 0 <= r < 1. */ + xf = (ax + 0x1p112L) - 0x1p112L; /* Integer part */ + ax -= xf; /* Remainder */ + if (ax < 0) { + ax += 1; + xf -= 1; + } + if (ax == 0) { s = 0; } else { @@ -98,14 +101,14 @@ sinpil(long double x) s = __kernel_sinpil(1 - ax); } - if (xf > 0x1p50) - xf -= 0x1p50; - if (xf > 0x1p30) - xf -= 0x1p30; + if (xf > 0x1p64) + xf -= 0x1p64; + if (xf > 0x1p32) + xf -= 0x1p32; ix = (uint32_t)xf; if (ix & 1) s = -s; } - return (copysignl(s, x)); + return (x < 0 ? -s : s); } if (isinf(x) || isnan(x)) diff --git a/lib/msun/ld128/s_tanpil.c b/lib/msun/ld128/s_tanpil.c index 7cbbdc8a5d05..90f4aea5c629 100644 --- a/lib/msun/ld128/s_tanpil.c +++ b/lib/msun/ld128/s_tanpil.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2017 Steven G. Kargl + * Copyright (c) 2017-2021 Steven G. Kargl * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,9 +26,6 @@ /* * See ../src/s_tanpi.c for implementation details. - * - * FIXME: This has not been compiled nor has it been tested for accuracy. - * FIXME: This should use bit twiddling. */ #include "math.h" @@ -75,7 +72,7 @@ tanpil(long double x) long double ax, hi, lo, xf, t; uint32_t ix; - ax = fabsl(ax); + ax = fabsl(x); if (ax < 1) { if (ax < 0.5) { @@ -94,19 +91,25 @@ tanpil(long double x) return ((ax - ax) / (ax - ax)); else t = -__kernel_tanpil(1 - ax); - return (copysignl(t, x)); + return (x < 0 ? -t : t); } if (ix < 0x1p112) { - xf = floorl(ax); - ax -= xf; + /* Split x = n + r with 0 <= r < 1. */ + xf = (ax + 0x1p112L) - 0x1p112L; /* Integer part */ + ax -= xf; /* Remainder */ + if (ax < 0) { + ax += 1; + xf -= 1; + } + if (ax < 0.5) t = ax == 0 ? 0 : __kernel_tanpil(ax); else if (ax == 0.5) return ((ax - ax) / (ax - ax)); else t = -__kernel_tanpil(1 - ax); - return (copysignl(t, x)); + return (x < 0 ? -t : t); } /* x = +-inf or nan. */ @@ -114,7 +117,7 @@ tanpil(long double x) return (vzero / vzero); /* - * |x| >= 0x1p53 is always an integer, so return +-0. + * |x| >= 0x1p112 is always an integer, so return +-0. */ return (copysignl(0, x)); }