Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/2216096/?format=api
{ "id": 2216096, "url": "http://patchwork.ozlabs.org/api/patches/2216096/?format=api", "web_url": "http://patchwork.ozlabs.org/project/glibc/patch/20260325192357.1284741-6-adhemerval.zanella@linaro.org/", "project": { "id": 41, "url": "http://patchwork.ozlabs.org/api/projects/41/?format=api", "name": "GNU C Library", "link_name": "glibc", "list_id": "libc-alpha.sourceware.org", "list_email": "libc-alpha@sourceware.org", "web_url": "", "scm_url": "", "webscm_url": "", "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20260325192357.1284741-6-adhemerval.zanella@linaro.org>", "list_archive_url": null, "date": "2026-03-25T19:22:23", "name": "[5/8] math: Use cosf from CORE-MATH", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "053f657fd879d9817841833c009e6f5329819593", "submitter": { "id": 66065, "url": "http://patchwork.ozlabs.org/api/people/66065/?format=api", "name": "Adhemerval Zanella Netto", "email": "adhemerval.zanella@linaro.org" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/glibc/patch/20260325192357.1284741-6-adhemerval.zanella@linaro.org/mbox/", "series": [ { "id": 497503, "url": "http://patchwork.ozlabs.org/api/series/497503/?format=api", "web_url": "http://patchwork.ozlabs.org/project/glibc/list/?series=497503", "date": "2026-03-25T19:22:18", "name": "Add sinf/cosf/sincosf CORE-MATH implementations", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/497503/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2216096/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2216096/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org>", "X-Original-To": [ "incoming@patchwork.ozlabs.org", "libc-alpha@sourceware.org" ], "Delivered-To": [ "patchwork-incoming@legolas.ozlabs.org", "libc-alpha@sourceware.org" ], "Authentication-Results": [ "legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256\n header.s=google header.b=tzFpZWVy;\n\tdkim-atps=neutral", "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org;\n receiver=patchwork.ozlabs.org)", "sourceware.org;\n\tdkim=pass (2048-bit key,\n unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256\n header.s=google header.b=tzFpZWVy", "sourceware.org;\n dmarc=pass (p=none dis=none) header.from=linaro.org", "sourceware.org; spf=pass smtp.mailfrom=linaro.org", "server2.sourceware.org;\n arc=none smtp.remote-ip=2607:f8b0:4864:20::92e" ], "Received": [ "from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fgxn04XbCz1y1K\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 26 Mar 2026 06:29:40 +1100 (AEDT)", "from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 7E58D4BB58CE\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 25 Mar 2026 19:29:38 +0000 (GMT)", "from mail-ua1-x92e.google.com (mail-ua1-x92e.google.com\n [IPv6:2607:f8b0:4864:20::92e])\n by sourceware.org (Postfix) with ESMTPS id 1596C4BAD15F\n for <libc-alpha@sourceware.org>; Wed, 25 Mar 2026 19:24:18 +0000 (GMT)", "by mail-ua1-x92e.google.com with SMTP id\n a1e0cc1a2514c-94e9810221cso57093241.2\n for <libc-alpha@sourceware.org>; Wed, 25 Mar 2026 12:24:18 -0700 (PDT)", "from mandiga.. ([2804:1b3:a7c1:90ea:f31d:ca7d:f8dd:c20b])\n by smtp.gmail.com with ESMTPSA id\n 71dfb90a1353d-56d31d394fcsm1040021e0c.12.2026.03.25.12.24.15\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Wed, 25 Mar 2026 12:24:16 -0700 (PDT)" ], "DKIM-Filter": [ "OpenDKIM Filter v2.11.0 sourceware.org 7E58D4BB58CE", "OpenDKIM Filter v2.11.0 sourceware.org 1596C4BAD15F" ], "DMARC-Filter": "OpenDMARC Filter v1.4.2 sourceware.org 1596C4BAD15F", "ARC-Filter": "OpenARC Filter v1.0.0 sourceware.org 1596C4BAD15F", "ARC-Seal": "i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1774466658; cv=none;\n b=Dcvtc2+4PEljxSKPTZNf7KNCaL2hvxdP7NFu5ni3fW7liCJ+E81cPphEJnFWod3wHhBDL9w76OaSI4TkpNZuYBR5kjktIFdKGEjAjcriW7uUdoRMzHU5ECRMRzbMffO7BJFvuhdvn3Qk+euX2pZMajcIjbA9vIf2t2AXucVdVDY=", "ARC-Message-Signature": "i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1774466658; c=relaxed/simple;\n bh=x+jJZ99RC0q/K+ykiZLlXmbkZ+RnkniVRi0J4wUXhXk=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=FVdNSYnyGXnK69ZsAPguk6T80v1+rYDscT2esjw/G/yp86ex12P9AU1bc68vG9VcGZG/05mcNYS9GsVwqzsPkaPOQqvyc6w3dfGsZcnSwTi2qH7z+IAh8ocHotoxS2Y3jLU4yzZ7j/UHDXBj9RqRS4q7WC9IK6pq7Lb/T9warWQ=", "ARC-Authentication-Results": "i=1; server2.sourceware.org", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=linaro.org; s=google; t=1774466657; x=1775071457; darn=sourceware.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=xOtnqWsBNQYqC7d5+0lRvBiKPaw8yvw2N6/uhhpHL90=;\n b=tzFpZWVySytYpyDrJN3ERfYz32g8bHVqgwvGMS6oiUXQxg+pEf/eXIkgTK1ukj892h\n 8o7lZaeWqTL0DxZAhK64mH6bmlfm6EdNFk1KGBf8DJR673PYWwuMTInzr2kCxVZo2iI6\n yDNK+/2qt/MoSM6CpzLMcTFRJsi8UgpWDKxm9qbSkZvn0LEKE3I+E+J4XvLnEiC2dgj5\n JFdMbnjkhLKl3jsB6KQtOWIcyDVID6U2NJdh5Hyra5qxfY5wiFjRVYblCf4voi5IhAty\n CoSjNTGuNVZYWbsdpleOHpIT7KBQG92gl5ETd7K4ShJ/JmoYE1Gl0j32RVn6KnnUWVKA\n 1TgA==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1774466657; x=1775071457;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=xOtnqWsBNQYqC7d5+0lRvBiKPaw8yvw2N6/uhhpHL90=;\n b=Bp1pi/ZMP1ukREHP6r8Gp0kjwe1VAdlmcsxh+TezLYaYCLbsQQEE1opi0zaInrcVUl\n IQyZ+OzpUPfeGf7VnHru6G1XBTcE0ZA9Zf4uLMRiMJ4kjszaL25B9XaSjspne+ElbNDV\n Bv3KZpY54s4w4/iZvU8p/Rk/v2pdra9SPFeRVcDOITaa9ucPwDq8oKg4txftWSF1QM/O\n 4EkBVobp+CvNboug6vGHLbMsi2nfXsJLk/+MuF0R8ft8THuurX4KUxrn/ivVRbhOHz8l\n jNNKdWYmL7ehR8C9gU+baaEzsjGRllITajbZTXpEIdSRVkYlG6bL60oMYd7lSHeFJXdr\n Yt+w==", "X-Gm-Message-State": "AOJu0Yw/rA6gGTJ1VNZXh+ErF0Nsg0srJ4WyvuNEltrm+qn+6d5BRKwY\n fbhXydTkmjyWUx0xu3Aa0NmaJbFOttcJ+rJMIZ0SC7KNcGW0ZLHUNH5pf5Bp1ekBWpXE5LWxZr+\n 5ixFM", "X-Gm-Gg": "ATEYQzxr0LHGu0A9rOHtxx7f2VjcqqcJ6ewyBgHKaho7erqengaLbET+bi6aFr5N2UE\n UWrWS1LJP6jjy2y/hDoqHfcwLckiyQvgE2plsAherjU+JhEikFCfLLkMjv0tsnxoykL/MgH82zI\n fnfETnI7gfPCfxP/Pzp4opc8Q4MH4ZaehrlsJUGVeuSBtWU/jQIfqb06Y6zDF/wAnl0f+pH+JpY\n dJ8aAsJAnSiAZncUE9njiYpO7A8rVMPQC1yroomg8uSm+K26XaO0NfZEHY3Jc6dNjFOsA8MNrsy\n QDIVDC8sV6j9lLsDF9alJ+QjfNYXlx32Vn5Vhhjw59JYjIyg4LYZtt7en6poz2jDkQVKaIibPn/\n dirN6bWvs2uUrc+zrPjgfuXI2k96yU+gNktDX4R+xlZPeNbrz/1yy2J7NBGyoNJPt6b4nhur9Ng\n PQjjPKOUd4jnlUgvrohUkpQpeOwGOkrs6p67I=", "X-Received": "by 2002:a05:6102:3f0b:b0:5f8:e3a9:4135 with SMTP id\n ada2fe7eead31-6037903e5eemr2460955137.11.1774466656948;\n Wed, 25 Mar 2026 12:24:16 -0700 (PDT)", "From": "Adhemerval Zanella <adhemerval.zanella@linaro.org>", "To": "libc-alpha@sourceware.org", "Cc": "Paul Zimmermann <Paul.Zimmermann@inria.fr>,\n\tDJ Delorie <dj@redhat.com>", "Subject": "[PATCH 5/8] math: Use cosf from CORE-MATH", "Date": "Wed, 25 Mar 2026 16:22:23 -0300", "Message-ID": "<20260325192357.1284741-6-adhemerval.zanella@linaro.org>", "X-Mailer": "git-send-email 2.43.0", "In-Reply-To": "<20260325192357.1284741-1-adhemerval.zanella@linaro.org>", "References": "<20260325192357.1284741-1-adhemerval.zanella@linaro.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "X-BeenThere": "libc-alpha@sourceware.org", "X-Mailman-Version": "2.1.30", "Precedence": "list", "List-Id": "Libc-alpha mailing list <libc-alpha.sourceware.org>", "List-Unsubscribe": "<https://sourceware.org/mailman/options/libc-alpha>,\n <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe>", "List-Archive": "<https://sourceware.org/pipermail/libc-alpha/>", "List-Post": "<mailto:libc-alpha@sourceware.org>", "List-Help": "<mailto:libc-alpha-request@sourceware.org?subject=help>", "List-Subscribe": "<https://sourceware.org/mailman/listinfo/libc-alpha>,\n <mailto:libc-alpha-request@sourceware.org?subject=subscribe>", "Errors-To": "libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org" }, "content": "The CORE-MATH implementation is correctly rounded (in any rounding mode)\nand performs similarly:\n\n* latency\n- input: random (-2*pi, 2*pi)\nlatency master patched improvement\nx86_64 39.9757 48.0301 -20.15%\nx86_64v2 38.7156 35.6435 7.94%\nx86_64v3 35.3454 34.5288 2.31%\naarch64 14.2015 13.7825 2.95%\npower10 9.1381 7.8624 13.96%\n\n- input: large (-64, 64)\nlatency master patched improvement\nx86_64 41.8186 48.9696 -17.10%\nx86_64v2 40.4777 38.0614 5.97%\nx86_64v3 37.0052 37.4971 -1.33%\naarch64 14.7948 15.7752 -6.63%\npower10 9.7240 8.9764 7.69%\n\n- input: huge (-1024, 1024)\nlatency master patched improvement\nx86_64 45.3777 49.6575 -9.43%\nx86_64v2 43.6480 39.6503 9.16%\nx86_64v3 40.9541 37.5966 8.20%\naarch64 17.9758 14.9358 16.91%\npower10 10.6854 8.1665 23.57%\n\n* reciprocal-throughput\n- input: random (-2*pi, 2*pi)\n master patched improvement\nx86_64 11.8433 17.9805 -51.82%\nx86_64v2 12.6771 10.9479 13.64%\nx86_64v3 11.1440 10.9951 1.34%\naarch64 7.5800 6.8004 10.29%\npower10 4.4510 3.5792 19.59%\n\n- input: rlarge (-64, 64)\n master patched improvement\nx86_64 11.9478 18.5297 -55.09%\nx86_64v2 12.7393 12.8142 -0.59%\nx86_64v3 11.1613 12.7013 -13.80%\naarch64 8.3857 8.1288 3.06%\npower10 5.2212 4.3630 16.44%\n\n- input: huge (-1024, 1024)\n master patched improvement\nx86_64 15.2741 18.3418 -20.08%\nx86_64v2 15.1064 13.0792 13.42%\nx86_64v3 14.6651 12.6774 13.55%\naarch64 9.6304 7.2278 24.95%\npower10 5.0207 3.6809 26.69%\n\nThe benchmarks were run on x64_64 (Ryzen 9 5900X, gcc 15.2.1)\nwith --disable-multi-arch disable; aarch64 (Neoverse-N1, gcc 15.2.1),\nand powerpc (POWER10, gcc 15.2.1).\n\nThe code is adapted to glibc style and to use the math_config\ndefinition.h (to handle errno, overflow, and underflow).\n\nThe x86_64-v1 shows some performance regression because the CORE-MATH\nimplementation relies on roundeven. The x86_64v2 and forward provide\na specific instruction, and x86_64 already provides an FMA ifunc variant.\n\nChecked on x86_64-linux-gnu, i686-linux-gnu, aarch64-linux-gnu,\nand powerpc64le-linux-gnu.\n---\n SHARED-FILES | 2 +\n sysdeps/ieee754/flt-32/libm-test-ulps | 12 +\n sysdeps/ieee754/flt-32/s_cosf.c | 220 +++++++++++++-----\n sysdeps/ieee754/flt-32/s_sincosf_data.h | 10 +-\n .../ieee754/flt-32/s_sincosf_data_generic.c | 35 ++-\n 5 files changed, 205 insertions(+), 74 deletions(-)", "diff": "diff --git a/SHARED-FILES b/SHARED-FILES\nindex d4b5b30ae4..751b31fae4 100644\n--- a/SHARED-FILES\n+++ b/SHARED-FILES\n@@ -288,6 +288,8 @@ core-math:\n sysdeps/ieee754/flt-32/s_atanpif.c\n # src/binary32/cbrt/cbrtf.c, revision f7c7408d\n sysdeps/ieee754/flt-32/s_cbrtf.c\n+ # src/binary32/cos/cosf.c revision 8ea8ea35\n+ sysdeps/ieee754/flt-32/s_cosf.c\n # src/binary32/cospi/cospif.c, revision bbfabd99\n sysdeps/ieee754/flt-32/s_cospif.c\n # src/binary32/erfc/erfcf.c revision d0a2be20\ndiff --git a/sysdeps/ieee754/flt-32/libm-test-ulps b/sysdeps/ieee754/flt-32/libm-test-ulps\nindex 2516f54a55..0179223018 100644\n--- a/sysdeps/ieee754/flt-32/libm-test-ulps\n+++ b/sysdeps/ieee754/flt-32/libm-test-ulps\n@@ -95,6 +95,18 @@ float: 0\n Function: \"cbrt_upward\":\n float: 0\n \n+Function: \"cos\":\n+float: 0\n+\n+Function: \"cos_downward\":\n+float: 0\n+\n+Function: \"cos_towardzero\":\n+float: 0\n+\n+Function: \"cos_upward\":\n+float: 0\n+\n Function: \"cosh\":\n float: 0\n \ndiff --git a/sysdeps/ieee754/flt-32/s_cosf.c b/sysdeps/ieee754/flt-32/s_cosf.c\nindex be98f8bb3b..2bef3b3036 100644\n--- a/sysdeps/ieee754/flt-32/s_cosf.c\n+++ b/sysdeps/ieee754/flt-32/s_cosf.c\n@@ -1,90 +1,182 @@\n-/* Compute cosine of argument.\n- Copyright (C) 2018-2026 Free Software Foundation, Inc.\n- This file is part of the GNU C Library.\n+/* Correctly-rounded cosine of binary32 value.\n \n- The GNU C Library is free software; you can redistribute it and/or\n- modify it under the terms of the GNU Lesser General Public\n- License as published by the Free Software Foundation; either\n- version 2.1 of the License, or (at your option) any later version.\n+Copyright (c) 2022-2026 Alexei Sibidanov.\n \n- The GNU C Library is distributed in the hope that it will be useful,\n- but WITHOUT ANY WARRANTY; without even the implied warranty of\n- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n- Lesser General Public License for more details.\n+The original version of this file was copied from the CORE-MATH\n+project (file src/binary32/cosh/coshf.c, revision 8ea8ea35.\n \n- You should have received a copy of the GNU Lesser General Public\n- License along with the GNU C Library; if not, see\n- <https://www.gnu.org/licenses/>. */\n+Permission is hereby granted, free of charge, to any person obtaining A copy\n+of this software and associated documentation files (the \"Software\"), to deal\n+in the Software without restriction, including without limitation the rights\n+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n+copies of the Software, and to permit persons to whom the Software is\n+furnished to do so, subject to the following conditions:\n \n+The above copyright notice and this permission notice shall be included in all\n+copies or substantial portions of the Software.\n+\n+THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n+SOFTWARE.\n+*/\n+\n+#include <array_length.h>\n #include <stdint.h>\n #include <math.h>\n #include <math-barriers.h>\n #include <libm-alias-float.h>\n #include \"math_config.h\"\n-#include \"s_sincosf.h\"\n+#include <math_uint128.h>\n+#include <s_sincosf_data.h>\n+\n+static double __attribute__ ((noinline))\n+rbig (uint32_t u, int *q)\n+{\n+ int e = (u >> 23) & 0xff, i;\n+ uint64_t m = (u & (~0u >> 9)) | 1 << 23;\n+ u128 p0 = u128_mul (u128_from_u64 (m), u128_from_u64 (IPI[0]));\n+ u128 p1 = u128_mul (u128_from_u64 (m), u128_from_u64 (IPI[1]));\n+ p1 = u128_add (p1, u128_rshift (p0, 64));\n+ u128 p2 = u128_mul (u128_from_u64 (m), u128_from_u64 (IPI[2]));\n+ p2 = u128_add (p2, u128_rshift (p1, 64));\n+ u128 p3 = u128_mul (u128_from_u64 (m), u128_from_u64 (IPI[3]));\n+ p3 = u128_add (p3, u128_rshift (p2, 64));\n+ uint64_t p3h = u128_high (p3), p3l = u128_low (p3), p2l = u128_low (p2),\n+\t p1l = u128_low (p1);\n+ int64_t A;\n+ int k = e - 124, s = k - 23;\n+ /* in cr_sinf(), rbig() is called in the case 127+28 <= e < 0xff\n+ thus 155 <= e <= 254, which yields 28 <= k <= 127 and 5 <= s <= 104 */\n+ if (s < 64)\n+ {\n+ i = p3h << s | p3l >> (64 - s);\n+ A = p3l << s | p2l >> (64 - s);\n+ }\n+ else if (s == 64)\n+ {\n+ i = p3l;\n+ A = p2l;\n+ }\n+ else\n+ { /* s > 64 */\n+ i = p3l << (s - 64) | p2l >> (128 - s);\n+ A = p2l << (s - 64) | p1l >> (128 - s);\n+ }\n+ int sgn = u;\n+ sgn >>= 31;\n+ int64_t sm = A >> 63;\n+ i -= sm;\n+ double z = (A ^ sgn) * 0x1p-64;\n+ i = (i ^ sgn) - sgn;\n+ *q = i;\n+ return z;\n+}\n+\n+static inline double\n+rltl (float z, int *q)\n+{\n+ double x = z;\n+ double idl = -0x1.b1bbead603d8bp-29 * x, idh = 0x1.45f306ep+2 * x,\n+\t id = roundeven_finite (idh);\n+ *q = asuint64 (0x1.8p52 + id);\n+ return (idh - id) + idl;\n+}\n+\n+static inline double\n+rltl0 (double x, int *q)\n+{\n+ double idh = 0x1.45f306dc9c883p+2 * x, id = roundeven_finite (idh);\n+ *q = asuint64 (0x1.8p52 + id);\n+ return idh - id;\n+}\n+\n+static float __attribute__ ((noinline))\n+as_cosf_database (float x, double r)\n+{\n+ uint32_t t = asuint (x);\n+ uint32_t ax = t & (~0u >> 1);\n+ for (unsigned i = 0; i < array_length (ST_COSF); i++)\n+ if (__glibc_unlikely (ST_COSF[i].uarg == ax))\n+ return ST_COSF[i].rh + ST_COSF[i].rl;\n+ return r;\n+}\n+\n+static float __attribute__ ((noinline))\n+as_cosf_big (float x)\n+{\n+ uint32_t t = asuint (x);\n+ uint32_t ax = t << 1;\n+ if (__glibc_unlikely (ax >= 0xffu << 24))\n+ { // nan or +-inf\n+ if (ax << 8)\n+\treturn x + x; // nan\n+ return __math_invalidf (x);\n+ }\n+ int ia;\n+ double z = rbig (t, &ia);\n+ double z2 = z * z, z4 = z2 * z2;\n+ double aa = (A[0] + z2 * A[1]) + z4 * (A[2] + z2 * A[3]);\n+ double bb = (B[0] + z2 * B[1]) + z4 * (B[2] + z2 * B[3]);\n+ double s0 = TB_COSF[(ia + 8u) & 31], c0 = TB_COSF[ia & 31];\n+ double r = c0 + z * (aa * s0 - bb * (z * c0));\n+ uint32_t tr = asuint64 (r);\n+ uint64_t tail = (tr + 6) & (~UINT64_C(0) >> 36);\n+ if (__glibc_unlikely (tail <= 12))\n+ return as_cosf_database (x, r);\n+ return r;\n+}\n \n #ifndef SECTION\n-# define SECTION\n+# define SECTION\n #endif\n \n #ifndef COSF\n-# define COSF_FUNC __cosf\n+# define COSF_FUNC __cosf\n #else\n-# define COSF_FUNC COSF\n+# define COSF_FUNC COSF\n #endif\n \n-/* Fast cosf implementation. Worst-case ULP is 0.5607, maximum relative\n- error is 0.5303 * 2^-23. A single-step range reduction is used for\n- small values. Large inputs have their range reduced using fast integer\n- arithmetic.\n-*/\n-float\n-SECTION\n-COSF_FUNC (float y)\n+float SECTION\n+COSF_FUNC (float x)\n {\n- double x = y;\n- double s;\n- int n;\n- const sincos_t *p = &__sincosf_table[0];\n-\n- if (abstop12 (y) < abstop12 (pio4))\n+ uint32_t t = asuint (x);\n+ uint32_t ax = t << 1;\n+ int ia;\n+ double z0 = x, z;\n+ if (__glibc_unlikely (ax > 0x99000000u || ax < 0x73000000))\n {\n- double x2 = x * x;\n-\n- if (__glibc_unlikely (abstop12 (y) < abstop12 (0x1p-12f)))\n-\treturn 1.0f;\n-\n- return sinf_poly (x, x2, p, 1);\n+ if (__glibc_likely (ax < 0x73000000))\n+\t{\n+\t if (__glibc_unlikely (ax < 0x66000000u))\n+\t {\n+\t if (__glibc_unlikely (ax == 0u))\n+\t\treturn 1.0f;\n+\t return 1.0f - 0x1p-25f;\n+\t }\n+\t return -0x1p-1f * x * x + 1.0f;\n+\t}\n+ return as_cosf_big (x);\n }\n- else if (__glibc_likely (abstop12 (y) < abstop12 (120.0f)))\n+ if (__glibc_likely (ax < 0x82a41896u))\n {\n- x = reduce_fast (x, p, &n);\n-\n- /* Setup the signs for sin and cos. */\n- s = p->sign[n & 3];\n-\n- if (n & 2)\n-\tp = &__sincosf_table[1];\n-\n- return sinf_poly (x * s, x * x, p, n ^ 1);\n- }\n- else if (abstop12 (y) < abstop12 (INFINITY))\n- {\n- uint32_t xi = asuint (y);\n- int sign = xi >> 31;\n-\n- x = reduce_large (xi, &n);\n-\n- /* Setup signs for sin and cos - include original sign. */\n- s = p->sign[(n + sign) & 3];\n-\n- if ((n + sign) & 2)\n-\tp = &__sincosf_table[1];\n-\n- return sinf_poly (x * s, x * x, p, n ^ 1);\n+ if (__glibc_unlikely (ax == 0x812d97c8u))\n+\treturn as_cosf_database (x, 0.0);\n+ z = rltl0 (z0, &ia);\n }\n else\n- return __math_invalidf (y);\n+ {\n+ z = rltl (z0, &ia);\n+ }\n+ double z2 = z * z, z4 = z2 * z2;\n+ double aa = (A[0] + z2 * A[1]) + z4 * (A[2] + z2 * A[3]);\n+ double bb = (B[0] + z2 * B[1]) + z4 * (B[2] + z2 * B[3]);\n+ double c0 = TB_COSF[ia & 31], s0 = TB_COSF[(ia + 8) & 31];\n+ double r = c0 + aa * (z * s0) - bb * (z2 * c0);\n+ return r;\n }\n \n #ifndef COSF\ndiff --git a/sysdeps/ieee754/flt-32/s_sincosf_data.h b/sysdeps/ieee754/flt-32/s_sincosf_data.h\nindex 02465ee931..8bea0042f3 100644\n--- a/sysdeps/ieee754/flt-32/s_sincosf_data.h\n+++ b/sysdeps/ieee754/flt-32/s_sincosf_data.h\n@@ -29,7 +29,10 @@ extern const double __sinf_a[] attribute_hidden;\n extern const double __sinf_tb[] attribute_hidden;\n #define TB __sinf_tb\n \n-extern const struct\n+extern const double __cosf_tb[] attribute_hidden;\n+#define TB_COSF __cosf_tb\n+\n+typedef struct\n {\n union\n {\n@@ -37,7 +40,10 @@ extern const struct\n uint32_t uarg;\n };\n float rh, rl;\n-} __sinf_st[4] attribute_hidden;\n+} sincosf_database_t;\n+extern const sincosf_database_t __sinf_st[4] attribute_hidden;\n #define ST __sinf_st\n+extern const sincosf_database_t __cosf_st[5] attribute_hidden;\n+#define ST_COSF __cosf_st\n \n #endif\ndiff --git a/sysdeps/ieee754/flt-32/s_sincosf_data_generic.c b/sysdeps/ieee754/flt-32/s_sincosf_data_generic.c\nindex f53251d3d8..2e58f0b423 100644\n--- a/sysdeps/ieee754/flt-32/s_sincosf_data_generic.c\n+++ b/sysdeps/ieee754/flt-32/s_sincosf_data_generic.c\n@@ -24,6 +24,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n */\n \n+#include <s_sincosf_data.h>\n+\n const uint64_t __sinf_ipi[] =\n {\n 0xfe5163abdebbc562, 0xdb6295993c439041, 0xfc2757d1f534ddc0,\n@@ -55,17 +57,34 @@ const double __sinf_tb[] =\n -0x1.87de2a6aea963p-2, -0x1.8f8b83c69a60bp-3\n };\n \n-const struct\n+const double __cosf_tb[] =\n+{\n+ 0x1p+0, 0x1.f6297cff75cbp-1, 0x1.d906bcf328d46p-1,\n+ 0x1.a9b66290ea1a3p-1, 0x1.6a09e667f3bcdp-1, 0x1.1c73b39ae68c8p-1,\n+ 0x1.87de2a6aea963p-2, 0x1.8f8b83c69a60bp-3, 0x0p+0,\n+ -0x1.8f8b83c69a60bp-3, -0x1.87de2a6aea963p-2, -0x1.1c73b39ae68c8p-1,\n+ -0x1.6a09e667f3bcdp-1, -0x1.a9b66290ea1a3p-1, -0x1.d906bcf328d46p-1,\n+ -0x1.f6297cff75cbp-1, -0x1p+0, -0x1.f6297cff75cbp-1,\n+ -0x1.d906bcf328d46p-1, -0x1.a9b66290ea1a3p-1, -0x1.6a09e667f3bcdp-1,\n+ -0x1.1c73b39ae68c8p-1, -0x1.87de2a6aea963p-2, -0x1.8f8b83c69a60bp-3,\n+ 0x0p+0, 0x1.8f8b83c69a60bp-3, 0x1.87de2a6aea963p-2,\n+ 0x1.1c73b39ae68c8p-1, 0x1.6a09e667f3bcdp-1, 0x1.a9b66290ea1a3p-1,\n+ 0x1.d906bcf328d46p-1, 0x1.f6297cff75cbp-1\n+};\n+\n+const sincosf_database_t __sinf_st[] =\n {\n- union\n- {\n- float arg;\n- uint32_t uarg;\n- };\n- float rh, rl;\n-} __sinf_st[] = {\n { { 0x1.33333p+13 }, -0x1.63f4bap-2, -0x1p-27 },\n { { 0x1.75b8a2p-1 }, 0x1.55688ap-1, -0x1p-26 },\n { { 0x1.4f0654p+0 }, 0x1.ee836cp-1, -0x1p-26 },\n { { 0x1.2d97c8p+3 }, -0x1.99bc5ap-26, -0x1p-51 },\n };\n+\n+const sincosf_database_t __cosf_st[] =\n+{\n+ { { 0x1.2d97c8p+2 }, 0x1.99bc5cp-27, -0x1p-52 },\n+ { { 0x1.4555p+51 }, 0x1.115d7ep-1, -0x1p-26 },\n+ { { 0x1.48a858p+54 }, 0x1.f48148p-2, 0x1p-27 },\n+ { { 0x1.3170fp+63 }, 0x1.fe2976p-1, 0x1p-26 },\n+ { { 0x1.2b9622p+67 }, 0x1.f0285ep-1, -0x1p-26 },\n+};\n", "prefixes": [ "5/8" ] }