From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::222]) by sourceware.org (Postfix) with ESMTPS id 9706C3857016 for ; Mon, 5 Sep 2022 18:14:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9706C3857016 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=otheo.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=otheo.eu Received: (Authenticated sender: #01#@otheo.eu) by mail.gandi.net (Postfix) with ESMTPSA id 57A1A40004 for ; Mon, 5 Sep 2022 18:14:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=otheo.eu; s=gm1; t=1662401688; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=d5gonwkabWiqLFjwBs/oD40W2CZ16sHwgjj9LBNNrdg=; b=MbJAELfh0v3fvmqEB7P9oVHAFns5jLZ/Yi5NJKtU85yrv8DrWbxJ8+CHNWSuMl2iaqEMqW e/UxhRR/wnYtkcDb/wg1AZ79CxJjB4PVtXPxsZYCC1tZKWeN+nZhr7xOVlmUrAZt7V9dWC /5Q9b1oaJqJGwabgbm2ORO2fiHNnH1hKA1lfxLyWwlIoIB7zR3u167Zqf/egK3b3kO0qNR tbNots0BctiDlrODkDwjTm3+w3+roPXPTB9uSBYlSP3KpzRTh3BCJHap3E/3qtdMUPM4ke dvYdfiNWlV7Tjn/ADtal3IyhhejNzfqq/TK9upnVjO0aIrcwL1EwB5VFiPWfvg== Date: Mon, 5 Sep 2022 20:13:38 +0200 From: Javier Pello To: libc-alpha@sourceware.org Subject: [PATCH 4/4] elf: Simplify hwcaps power set string construction Message-Id: <20220905201338.af2afde778758951b9f4e787@otheo.eu> In-Reply-To: <20220905200652.d69204581d15c64647da5cd2@otheo.eu> References: <20220905200652.d69204581d15c64647da5cd2@otheo.eu> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,JMQ_SPF_NEUTRAL,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: The power set strings in _dl_important_hwcaps were being computed in two passes, one to generate the strings and another one to store the pointers in the result array. Do it in a single pass instead, as this is simpler. Signed-off-by: Javier Pello --- elf/dl-hwcaps.c | 58 ++++++++++++++++++------------------------------- 1 file changed, 21 insertions(+), 37 deletions(-) diff --git a/elf/dl-hwcaps.c b/elf/dl-hwcaps.c index b248f74b..93a9c56d 100644 --- a/elf/dl-hwcaps.c +++ b/elf/dl-hwcaps.c @@ -176,7 +176,6 @@ _dl_important_hwcaps (const char *glibc_hwcaps_prepend, size_t cnt = GLRO (dl_platform) != NULL; size_t n, m; struct r_strlenpair *result; - struct r_strlenpair *rp; char *cp; /* glibc-hwcaps subdirectories. These are exempted from the power @@ -304,63 +303,48 @@ _dl_important_hwcaps (const char *glibc_hwcaps_prepend, #3: 0, 3 1001 This allows the representation of all possible combinations of capability names in the string. First generate the strings. */ - result[1].str = result[0].str = cp; + struct r_strlenpair *rp = result; + n = 1 << (cnt - 1); + struct r_strlenpair *rq = rp + n; #define add(idx) \ cp = __mempcpy (__mempcpy (cp, temp[idx].str, temp[idx].len), "/", 1); - n = 1 << (cnt - 1); do { n -= 2; + /* Strings in the first half include the first component. */ + rp[1].str = rp[0].str = cp; + /* We always add the last string. */ add (cnt - 1); + /* Strings in the second half start after the first component. */ + rq[1].str = rq[0].str = cp; + /* Add the strings which have the bit set in N. */ for (m = cnt - 2; m > 0; --m) if ((n & (1 << m)) != 0) add (m); + /* Odd-numbered strings end before before the last component. */ + rp[1].len = cp - rp[1].str; + rq[1].len = cp - rq[1].str; + /* Always add the first string. */ add (0); - } - while (n != 0); -#undef add - /* Now we are ready to install the string pointers and length. */ - for (n = 0; n < (1UL << cnt); ++n) - result[n].len = 0; - n = cnt; - do - { - size_t mask = 1 << --n; + /* Even-numbered strings include the last component. */ + rp[0].len = cp - rp[0].str; + rq[0].len = cp - rq[0].str; - rp = result; - for (m = 1 << cnt; m > 0; ++rp) - if ((--m & mask) != 0) - rp->len += temp[n].len + 1; + rp += 2; + rq += 2; } while (n != 0); +#undef add - /* The first half of the strings all include the first string. */ - n = (1 << cnt) - 2; - rp = &result[2]; - while (n != (1UL << (cnt - 1))) - { - if ((--n & 1) != 0) - rp[0].str = rp[-2].str + rp[-2].len; - else - rp[0].str = rp[-1].str; - ++rp; - } - - /* The second half starts right after the first part of the string of - the corresponding entry in the first half. */ - do - { - rp[0].str = rp[-(1 << (cnt - 1))].str + temp[cnt - 1].len + 1; - ++rp; - } - while (--n != 0); + /* Assert that we got memory allocation right. */ + assert (cp == (char *) (overall_result + *sz) + total); /* The maximum string length. */ if (result[0].len > hwcaps_counts.maximum_length) -- 2.36.0