From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EECDA236A73 for ; Mon, 16 Feb 2026 22:29:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771280988; cv=none; b=nV+EBwWxNAd9joLgNfn2z9waC5iIIgj6XTefhoZHtNbDhBELUus2d19AGNJCwmq07UlnlUdgT3Ti3ihh2oBluz/Ul/qOZtFSxfoMfo5aJj4Othnpy9bv9LjFPUnG+brs1//GwTxbrb+FalJi2jopB1bm+vaPYGKcUwg8lnTEuKo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771280988; c=relaxed/simple; bh=HsUSokXoUwYFDbZsHxbKDMGds19g+sjyo2vEbo+u4Yg=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HYT+2dzrcz17Jjg1fjBh6/yT+3o5nh30OxEVNUIR714D/m0gttKE7CnbiHwn3DxAaxF7KREPcVmnasHuBS62EanTucKG2VsQiR8imC2sUHoGUmhTec3Ns/YT419TqAeHxbqZPudS/sX0ZLKBKuJwqVJfwrsz/z5BK2c6DSFrEyc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XitxY/rh; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XitxY/rh" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4837f27cf2dso18650425e9.2 for ; Mon, 16 Feb 2026 14:29:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771280985; x=1771885785; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=A514Uz4l6/92sKCy8HiD9lJ8TT9i6IhxqU/+MTvd9dU=; b=XitxY/rhQibJRKHTJovMZheL+d92707Opf5Wnq1oi3Th2SNeJyPJOrdQQceYHohnyx UH9QKJNUmjCfozhS/CNZpF0rdZs30yEE7DJz5Ubu7qv8E4j2dR0HJV93OHnHVj7Hs6EO 2PgX31xC2OrVYJZw8nuj4BUEqHMtH/g29m5AJEjIn/oy5CdcG8HPDSKHt3sQl8Rn6UvS 0A9jzcYGTWLfYMKhyZMZU0q49RWGfRpxDq6ZoI5Ldyn7McpzJ0tyl7eDWRXGN63/TJ48 x9oE1uC+nKcdexqKjL0pVP4925ZSbb07PaWmT3qmShhnEDP+cNZrKRQNEpSxGqgGTBIL DVnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771280985; x=1771885785; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=A514Uz4l6/92sKCy8HiD9lJ8TT9i6IhxqU/+MTvd9dU=; b=wm+Ai6aXqtv+w+hUDVrB3ECLD7sDRXUrRYcVR7UydMq6XkI/ChTE8OKL3tXcwZDQSs sgINmNVQ9xhl/wZzM5wmN7MxeS528Wxjs2qaUw0ps5M/D64Hrhpto01Q/w/qJ1wd5ck0 PahCgvmoCpxJ5jlaLqE8i4PTaDeZXiF4xRMU4tDzAzmzznyHieEsk94VVGCm64mymVHZ zGNWilyCwNgq0/6mTWBpWXgGhX5PuqIeWNoHR8MmT9lk6zOMhkxA8Jk013P6vVd8F+6l 9PzZe7u5/TM5upjHKjM8H9/6gXDnuMfra/tzgeaUh1fN8pBmwqMZ35li/6am0RlamfWw fuhg== X-Forwarded-Encrypted: i=1; AJvYcCUInRBqiA1diEkdVMj+P0hb05fsXiQuHymVplSw1K78iySr7zhjVeqW1M/p131PvQ1zoDhYwJpVxzZCOaY=@vger.kernel.org X-Gm-Message-State: AOJu0Yxeoi1MiY2nrFEYYW3NXu3MhwcZyzDk4HLibjWsslBxnrZIoIEf gdXfIP3hf33/URxyPnl1qVRFSvttVJ26JFZwOyteUiS3JX1uHSnqDQIj X-Gm-Gg: AZuq6aIsfR5uBmJHUKhCdCPBIkRrDHKz3ea7r+w1OzhF0kTfh1V+klz2cZrB4/+LZS1 iZnw/JgD9rLF8+i8tDfhiCJqN57gA4pn2JS8XZBd8FUFHxxYNm2I77leTbKBHD1ffcXBWob+y0j 2yJPDJJLw2FA+HRLp5RdwnjEGz1Kfc7RJ5lq6U86SyTqs7+oFZl9x2Y4z80+gpiX2YXmyCLdPiD vmxqbn7aHunARgFpCGAr0P1tOG0fgH7SYZvUXW+MWI9nFSMnR1nE7SQ15kSddeg8M/Uvhvayr21 xXznKIG+6EqKYY8dujWCsizFAPzEE01sGxHL6goVBbD4Jp67N0mzHsE2FDIrP0uWwT9y1uxEbF+ sPn7AyB6qgqE68tKrP1CAOVvHkWAAFTK8behBBSIC5DcA+n+scu2xX82ELfdisI55UCx2zfXpbl +Pfe6T7O4/yTghe7Z1ykK7qsoeEse311359cDXQrZHdIQjJOaoCXVHjMeJgovdg2Mu X-Received: by 2002:a05:600c:c3dc:20b0:483:7631:befa with SMTP id 5b1f17b1804b1-4837631c7c9mr157237585e9.5.1771280985284; Mon, 16 Feb 2026 14:29:45 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-483801ff9b3sm182157925e9.13.2026.02.16.14.29.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Feb 2026 14:29:44 -0800 (PST) Date: Mon, 16 Feb 2026 22:29:43 +0000 From: David Laight To: Thomas =?UTF-8?B?V2Vpw59zY2h1aA==?= Cc: g@t-8ch.de, Willy Tarreau , linux-kernel@vger.kernel.org, Cheng Li Subject: Re: [PATCH v2 next 04/11] tools/nolibc/printf: Output pad characters in 16 byte chunks Message-ID: <20260216222943.240221d5@pumpkin> In-Reply-To: References: <20260206191121.3602-1-david.laight.linux@gmail.com> <20260206191121.3602-5-david.laight.linux@gmail.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Mon, 16 Feb 2026 20:30:27 +0100 Thomas Wei=C3=9Fschuh wrote: > On 2026-02-06 19:11:14+0000, david.laight.linux@gmail.com wrote: > > From: David Laight > >=20 > > Simple to do and saves calls to the callback function. > >=20 > > Signed-off-by: David Laight > > --- > >=20 > > Changes for v2: > > Formally patch 3, unchanged. > >=20 > > tools/include/nolibc/stdio.h | 8 +++++--- > > 1 file changed, 5 insertions(+), 3 deletions(-) > >=20 > > diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h > > index 552f09d51d82..c044a6b3babe 100644 > > --- a/tools/include/nolibc/stdio.h > > +++ b/tools/include/nolibc/stdio.h > > @@ -355,10 +355,12 @@ int __nolibc_printf(__nolibc_printf_cb cb, void *= state, const char *fmt, va_list > > outstr =3D fmt; > > len =3D ofs - 1; > > flush_str: > > - while (width-- > len) { > > - if (cb(state, " ", 1) !=3D 0) > > + while (width > len) { > > + unsigned int pad_len =3D ((width - len - 1) & 15) + 1; =20 >=20 > So this is a modulo, which does not return 0. > While I am sure you and Willy recognize this instantly, I had to squint a= bit. > While I understand that a regular modulo operator might be problematic > on some architectures, does it also apply to constant module values? The modulo would return 0..15, I wanted 1..16 hence the -1 and +1. Perhaps another comment. > The compiler could do this on its own. If not, we should have a macro. >=20 > I am wondering why it is a modulo and not some sort of max()... It doesn't require a conditional of any sort. Basically it does the short transfer first followed by the full length ones. Whereas a min/max would do the large ones first and the remainder at the en= d. The effect is basically the same. >=20 > Could you move the tests for the new functionality into the patches that > introduce that functionality? Can do, I was thinking you'd prefer separate patches for the code changes and test changes and didn't want to generate a stupid number of patches. It is bad enough already :-) > That would make it easier to review and > play with the code. Also it would allow to selectively apply the patches. > For example I get compiler warnings/errors in the later patches, so I > the full array of new tests will fail if I skip these later patches. I've been applying the patch so the tests and then doing a 'git reset' on it and not worrying about the tests that fail. David >=20 > > + width -=3D pad_len; > > + written +=3D pad_len; > > + if (cb(state, " ", pad_len) !=3D 0) > > return -1; > > - written +=3D 1; > > } > > if (cb(state, outstr, len) !=3D 0) > > return -1; > > --=20 > > 2.39.5 > > =20