public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
From: Kuan-Wei Chiu <visitorckw@gmail.com>
To: Theodore Tso <tytso@mit.edu>
Cc: David Laight <david.laight.linux@gmail.com>,
	Guan-Chun Wu <409411716@gms.tku.edu.tw>,
	Andreas Dilger <adilger.kernel@dilger.ca>,
	linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ext4: improve str2hashbuf by processing 4-byte chunks
Date: Fri, 21 Nov 2025 00:58:23 +0800	[thread overview]
Message-ID: <aR9Ir6fdzD5_0Pkn@google.com> (raw)
In-Reply-To: <20251120155816.GB13687@macsyma-3.local>

Hi Ted,

On Thu, Nov 20, 2025 at 10:58:16AM -0500, Theodore Tso wrote:
> On Sun, Nov 16, 2025 at 07:35:13PM +0000, David Laight wrote:
> > 
> > The (int) casts are unnecessary (throughout), 'char' is always promoted to
> > 'signed int' before any arithmetic.
> 
> nit: in this case the casts aren't necessary, but your comment is not
> correct in general, so I just wanted to make sure it's corrected in
> case someone later looks at the mail archive.
> 
> "char" is not always signed.  It can be signed or unsigned; the C
> specification allows either.  In this particular case, scp is a
> "signed char", not "char".
> 
> Secondly, it's not that a promotion happens before "any" arithmetic.
> If we add two 8-bit values together, promotion doesn't happen.  In
> this case, we are adding a signed char to an int, so the promotion
> will happen.
> 
I believe David was referring to the C11 spec 6.3.1.1:

If an int can represent all values of the original type (as restricted
by the width, for a bit-field), the value is converted to an int;
otherwise, it is converted to an unsigned int. These are called the
integer promotions. All other types are unchanged by the integer
promotions.

The spec explicitly mentions char + char in 5.1.2.3 example:

EXAMPLE 2 In executing the fragment
char c1, c2;
/* ... */
c1 = c1 + c2;
the ‘‘integer promotions’’ require that the abstract machine promote
the value of each variable to int size and then add the two ints and
truncate the sum. Provided the addition of two chars can be done
without overflow, or with overflow wrapping silently to produce the
correct result, the actual execution need only produce the same result,
possibly omitting the promotions.

So IIUC conceptually the promotion happens, even if the compiler
optimizes it out in the actual execution.

Link: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf

Regards,
Kuan-Wei

  reply	other threads:[~2025-11-20 16:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-16 13:01 [PATCH] ext4: improve str2hashbuf by processing 4-byte chunks Guan-Chun Wu
2025-11-16 19:35 ` David Laight
2025-11-17 14:20   ` Guan-Chun Wu
2025-11-20 15:58   ` Theodore Tso
2025-11-20 16:58     ` Kuan-Wei Chiu [this message]
2025-11-20 18:27       ` David Laight
2025-11-21 10:07     ` Geert Uytterhoeven
2025-11-21 10:55     ` Andreas Schwab
2025-11-21 11:59       ` David Laight

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aR9Ir6fdzD5_0Pkn@google.com \
    --to=visitorckw@gmail.com \
    --cc=409411716@gms.tku.edu.tw \
    --cc=adilger.kernel@dilger.ca \
    --cc=david.laight.linux@gmail.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox