From patchwork Mon Aug 24 22:16:07 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Turner X-Patchwork-Id: 142124 X-Patchwork-Delegate: azanella@linux.vnet.ibm.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 280284BA799E for ; Mon, 24 Aug 2026 22:17:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 280284BA799E Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=GYG6h6tK X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yw1-x1133.google.com (mail-yw1-x1133.google.com [IPv6:2607:f8b0:4864:20::1133]) by sourceware.org (Postfix) with ESMTPS id 20AD04BA79A9 for ; Mon, 24 Aug 2026 22:16:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 20AD04BA79A9 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 20AD04BA79A9 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1133 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1787609783; cv=none; b=MdJFCYUPSEGYLyhV1RcFa78BB/9kmWPPGxbydgHVKrl66xxjOG+Oa6T3CQjFmkW7NJrtqMJWslaZxEOjP86MrVf4Amd9+wIhmarfuqkZ0bGUiVVHlvFriRal2BDLCqIMbuoIkQP03sl9w2Ufnk2faZIUGA1sk1llJvkHqwfPmVc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1787609783; c=relaxed/simple; bh=9DGhQiICQUvLOct3dOpOCdHHMJ3G7p8RO0QT/6zZrg0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=GKUwr4+EqPVkbiYeQPpOOMiOfZb078lGnBbngH1nMDRqTNOpUAvNQYD72+djzaoGmtoiM92fD4T3egF0Wzl2vQPW74iGLplj6PaxleZZdvL2O7EJ757/b7HMnrPtyuZk1l/rTcK8WwBTUg2m/XKa5hgvhKN8loL04PIx4AqY8Wg= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=GYG6h6tK DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 20AD04BA79A9 Received: by mail-yw1-x1133.google.com with SMTP id 00721157ae682-84c4d4f68c7so46135017b3.2 for ; Mon, 24 Aug 2026 15:16:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787609782; x=1788214582; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=T+brU6Ply0vdtK2fadxoB7AMBTytpUVn0fWDfS0DKLg=; b=GYG6h6tK5OfOoHY6Akt8FxfMce6Z1mRsIr7kgtfVrVN3ucEawuhE0b8RZHwt9N2tAe 7IH3drnLP6hZ30WOENSDUPZL3RKo9I9oxe5zTL3hbJ5UVLwy/M1gahtdsS+29HN33G1p JBBN4UvvzEFk6lcfd5ZnfdSNFJu3sACBD1sPAcpw38RACXzIca3bjgIsWik74dvkl0LB 1kthDE36v3j9/0+5pPiLB0MjUOoLtHyiXPUtlcOwPrwJztV9uNOsDKrAB1dZHSUgUMA+ 43VTF/rCfVKRKdX6RsaH162kb9BNPgkjV9NWK+m+JoVBxnXs3bgW2comrtD1kbCqqa3p JtnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787609782; x=1788214582; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=T+brU6Ply0vdtK2fadxoB7AMBTytpUVn0fWDfS0DKLg=; b=U9BRoL/T0PVIGnfqQBWwGSPF5pzfZBDYaZ7Sde0gvNjLykAjBW4SYk0Cng3PEIzrEK 0txiQhg6QfwHt3kxjdTuViGwaFJq8g/KISaYK8UFuxrr/+zVFA+ibClBJBOS5gnV59M+ HjtzWLYXaljhXhhSdqSiuiE0JZwOMTSSVdgRC1Q+NFUaV0m0wTEi7AUgsQSNgYudre6V WoXNgxRdeRjPhZ4oaxQAOA2ZNY8reAxDvGS+ERQ4t6RzvuXOWRh2v+cUdfCDpHdZKqtp rZHiCTUEzbnq/eEbfTAdrVxCcz1LGXBzo7gGqOIbsnC+oCJ9h5GP53atuGqaOp8bg1Zk hTzA== X-Gm-Message-State: AFuF++lZpcBbX6nkTHRDaSHSfVRKptVRcXIuuac33qb0dNMuOHtpV5hm nwRad/KMlUWwLWDgOlZ3EKxqmyFZSyuG5bHiKAI517Mv6MtII+Jwd9p4vaK5Ow== X-Gm-Gg: AR+sD11ewc/kcAhaC1XChzeFJXokke1bMU4MARA/H0Mi6492Z8d4K0M17Gat+t4waOH rfEk1Cc5WuYepMyTcNeozJAoIcl+PoMIQo5hTmx2jBU9oMk2sh3+KUQQes3FxYdDioti3uVdlbp 0y0VMjPJlEsbQIT8PKnzPupVD2AQzmKpb0CUALN2YEaSiY/Nb0Oyf9Tited0VkX77KL4zEDFdWl 8IU5SaFtMIoAIWgbGzS0upj7OVCE9zO+0q//Tn5nI099B4ckbrTYpjbCFSV4VkFq93dWsDF8tkz grH60WbS+rloZ4fdPq1BcEcFyj6zCazYckeX7Tz9FGwg/6SHOP4zpaOBYiChw/3v8JhvsSMXtH1 E2MdFXmGhk4xEYWKjW0rtDI1rJGqie0AxEgAxS3g7yxNQs8W6FwSRFS40VMOTm56zjivN5lx09a pRXx9eMCtr5h3ob1msu2kbwwSXMudt0/pIgBoQLWhNix5HEnjHi0w0at+KhVlqpkXVUy8= X-Received: by 2002:a05:690c:9987:b0:80b:9f4e:a70 with SMTP id 00721157ae682-849f5a0e03cmr130896227b3.26.1787609782340; Mon, 24 Aug 2026 15:16:22 -0700 (PDT) Received: from localhost ([67.197.117.177]) by smtp.gmail.com with ESMTPSA id 00721157ae682-84cab854483sm40072917b3.33.2026.08.24.15.16.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2026 15:16:21 -0700 (PDT) From: Matt Turner To: libc-alpha@sourceware.org Cc: Matt Turner Subject: [PATCH 2/7] stdio-common: Iterate over the huge width for one printf function only Date: Mon, 24 Aug 2026 18:16:07 -0400 Message-ID: <20260824221612.4132669-3-mattst88@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260824221612.4132669-1-mattst88@gmail.com> References: <20260824221612.4132669-1-mattst88@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_PBL, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org HUGE_WIDTH is chosen so that none of the strings produced are truncated, which for the floating-point types means every record it takes part in carries hundreds or thousands of digits. Those records dominate the cost of this whole family of tests: for the long double conversions they are 99% of the bytes produced, and the long double targets alone account for 92% of the time the tests take. The digits being checked are produced by the same conversion code whichever of the printf family of functions is used; what differs between the twelve of them is the sink the result is written to, which the smaller widths cover already. Iterate over HUGE_WIDTH for a single function then, chosen as printf, and let the remaining eleven stop at MID_WIDTH. This applies to the double and long double conversions only; for the other types full-precision output is short and costs nothing, so they keep iterating over it as before. Together with the switch to verifying in Python this takes the tests from 935s to 375s of processor time on x86_64-linux-gnu, with all 576 results continuing to pass. What remains is mostly intrinsic: the f and F conversions print the whole integer part regardless of the precision requested, so LDBL_MAX runs to some 4932 digits even at MID_WIDTH. Reviewed-by: Adhemerval Zanella --- stdio-common/tst-printf-format-p.h | 4 ++++ .../tst-printf-format-skeleton-double.c | 2 ++ .../tst-printf-format-skeleton-ldouble.c | 2 ++ stdio-common/tst-printf-format-skeleton.c | 19 ++++++++++++++++++- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git ./stdio-common/tst-printf-format-p.h ./stdio-common/tst-printf-format-p.h index 48dcc3b48c..c35ca2c44d 100644 --- ./stdio-common/tst-printf-format-p.h +++ ./stdio-common/tst-printf-format-p.h @@ -18,6 +18,10 @@ #include +/* Conversions are verified at the full width and precision through this + function; see the comment on WPHUGE in tst-printf-format-skeleton.c. */ +#define TST_PRINTF_HUGE 1 + #define printf_under_test(...) \ ({ \ int result; \ diff --git ./stdio-common/tst-printf-format-skeleton-double.c ./stdio-common/tst-printf-format-skeleton-double.c index e740c193b5..4dbf3fc1ed 100644 --- ./stdio-common/tst-printf-format-skeleton-double.c +++ ./stdio-common/tst-printf-format-skeleton-double.c @@ -21,6 +21,8 @@ #define MID_WIDTH 20 #define HUGE_WIDTH 320 +/* Full-precision output runs to hundreds of digits here. */ +#define TST_PRINTF_WIDE_TYPE 1 #define REF_FMT ".35e" #define REF_VAL(v) (v) #define PREC DBL_MANT_DIG diff --git ./stdio-common/tst-printf-format-skeleton-ldouble.c ./stdio-common/tst-printf-format-skeleton-ldouble.c index 29bc8b7d36..d959f9dc2d 100644 --- ./stdio-common/tst-printf-format-skeleton-ldouble.c +++ ./stdio-common/tst-printf-format-skeleton-ldouble.c @@ -22,6 +22,8 @@ #define MID_WIDTH 20 #define HUGE_WIDTH 4950 +/* Full-precision output runs to thousands of digits here. */ +#define TST_PRINTF_WIDE_TYPE 1 #define REF_FMT ".35Le" #define REF_VAL(v) (v) #define PREC LDBL_MANT_DIG diff --git ./stdio-common/tst-printf-format-skeleton.c ./stdio-common/tst-printf-format-skeleton.c index 000d8fa50d..3594124513 100644 --- ./stdio-common/tst-printf-format-skeleton.c +++ ./stdio-common/tst-printf-format-skeleton.c @@ -102,6 +102,23 @@ static struct #define STR(v) #v #define WPINIT(v) {0, STR (v)}, {v, NULL}, {-v, NULL} +/* HUGE_WIDTH is chosen so that nothing is truncated, which for the wider + floating-point types means thousands of digits in every record it takes + part in. Those records dominate the run time of this whole family of + tests. The digits they check are produced by the same conversion code + regardless of which of the printf family of functions is used; only the + sink the result is written to differs, and that is covered at the + smaller widths already. So iterate over HUGE_WIDTH for one function + only, chosen as 'printf' by having tst-printf-format-p.h define + TST_PRINTF_HUGE, and let the remaining functions stop at MID_WIDTH. + Types whose full-precision output is short keep it unconditionally, as + it costs nothing there. */ +#if defined TST_PRINTF_WIDE_TYPE && !defined TST_PRINTF_HUGE +# define WPHUGE +#else +# define WPHUGE , WPINIT (HUGE_WIDTH) +#endif + /* Width and precision settings to iterate over; zero is initialized directly as it has no corresponding negated value and other values use the helper above. */ @@ -113,7 +130,7 @@ static struct wp const char *s; } const wp[] = { {0, "0"}, {0, NULL}, WPINIT (1), WPINIT (2), - WPINIT (MID_WIDTH), WPINIT (HUGE_WIDTH) }; + WPINIT (MID_WIDTH) WPHUGE }; /* Produce a record according to '%' and zero or more output format flags already provided in FMT at indices 0..IDX-1, width W if non-NULL, '.'