From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-6.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by gnuweeb.org (Postfix) with ESMTPS id CCFF27E3F1 for ; Tue, 19 Apr 2022 00:42:31 +0000 (UTC) Authentication-Results: gnuweeb.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=npTj/Qxt; dkim-atps=neutral Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 73CDAB81158; Tue, 19 Apr 2022 00:42:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20174C385D1; Tue, 19 Apr 2022 00:42:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1650328948; bh=TXGXxxDUWM3g7RndkKdMyxMfgFKYo/NmOYDBPkR2PO4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=npTj/QxtzwbLb44f/6Dil+BCDyCFtLyMhclIALEZZ3iHbeHaDhPMougDmfixqWGeU HDezrEwx+FWpGfAjDhr13Y1AWTdLTCMHxXOx6fILFEN3bB8BIpBXgvehoFmjgtBiZp XhnAUlkiIeA2YFtr0IIndBc8oYYCwMUR2usKBu6RT5zfuGdGYdFEl+lLr5GgDW1Kx2 QdVbkzjz51L2LBUXyj9UpzkiFpSNBTNLMACvEVDsb4YO4zKH3+RQrhrtQqpTXLbd+m o6OwuzTtimWCeVTnIUQr4D8sz31/W1pWihYKV4G6oBOA2uR0/jXRt/cNsaWVluNCf0 uG1/Z0HpTZ6Rw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 351C65C30FB; Mon, 18 Apr 2022 17:42:27 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@fb.com, w@lwt.eu, Willy Tarreau , "Paul E . McKenney" Subject: [PATCH nolibc 25/61] tools/nolibc/stdlib: avoid a 64-bit shift in u64toh_r() Date: Mon, 18 Apr 2022 17:41:49 -0700 Message-Id: <20220419004225.3952530-25-paulmck@kernel.org> X-Mailer: git-send-email 2.31.1.189.g2e36527f23 In-Reply-To: <20220419004219.GA3952301@paulmck-ThinkPad-P17-Gen-1> References: <20220419004219.GA3952301@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: From: Willy Tarreau The build of printf() on mips requires libgcc for functions __ashldi3 and __lshrdi3 due to 64-bit shifts when scanning the input number. These are not really needed in fact since we scan the number 4 bits at a time. Let's arrange the loop to perform two 32-bit shifts instead on 32-bit platforms. Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/stdlib.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tools/include/nolibc/stdlib.h b/tools/include/nolibc/stdlib.h index 82a4cf606d3c..db47362a750f 100644 --- a/tools/include/nolibc/stdlib.h +++ b/tools/include/nolibc/stdlib.h @@ -200,14 +200,18 @@ int u64toh_r(uint64_t in, char *buffer) int dig; do { - dig = in >> pos; - in -= (uint64_t)dig << pos; + if (sizeof(long) >= 8) { + dig = (in >> pos) & 0xF; + } else { + /* 32-bit platforms: avoid a 64-bit shift */ + uint32_t d = (pos >= 32) ? (in >> 32) : in; + dig = (d >> (pos & 31)) & 0xF; + } + if (dig > 9) + dig += 'a' - '0' - 10; pos -= 4; - if (dig || digits || pos < 0) { - if (dig > 9) - dig += 'a' - '0' - 10; + if (dig || digits || pos < 0) buffer[digits++] = '0' + dig; - } } while (pos >= 0); buffer[digits] = 0; -- 2.31.1.189.g2e36527f23