From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 054D033F396 for ; Thu, 20 Nov 2025 16:58:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763657909; cv=none; b=nyucDxrR/4tjpJj0JykWlyeXl6/HWDsHC8uVT711BemPHkkKeZ/MLmv2OVMs6jwDV+P7EuzZ9lp97ao9wA5gmzkGdnfJj2GNf27DoiPd6rIzGqH7Kue6oamtPVYQkE7X/ibAn8GJxq/bL+ReHRaB6HanFkD+8UaEq6F6ZOKUkGw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763657909; c=relaxed/simple; bh=WFzUcNhfWCsgFc0gJ5dxP4YdAHlkxA9RtbOQ+OA7tsg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=m1jhtitRsSjdTE4cEdaqAyjr/LKRuJemggDGKshu8stJNL67byVGNT2HNyM2jxxQtwdWVD9hOe8yJeBYVJB0uWzhKWusHUgmKojVkhwu53Q1qlxBADcT5Bj27ADH85+pZ+rFLNvKXGosbudZndlRsXvlN8a4BwvE9CBaQvlP8cw= 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=ljfSpvoe; arc=none smtp.client-ip=209.85.214.169 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="ljfSpvoe" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-29555415c5fso12397155ad.1 for ; Thu, 20 Nov 2025 08:58:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763657907; x=1764262707; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=pAUx4lPAAt5hhocIlS3eO4JgrnznXmHn7pMUp71lriA=; b=ljfSpvoe0N3NQ8erW40poK901HjpCCTGcn8R5o6kBMJFFETqN+jfrgFJ9rtxLQ6RJD uTb6E9AOnoT0JWpm5HZVzD9uU5QZs9FI4nJa1ONfqhgzHO++WEtxh4TyGvLRG1i+c+Gm wI1XKyv4WTrQHTSzELx56/BG0Dj5MqJiEF2e1ukEV/buQPEYWUcEZ0/myC/+U6kKV+61 duJHiLqz9HdReM+m9iyHeslDzwfyQhNEurRqFIYG+lEF8wNUzSiyqqsIOOtf/gIZYq0Y 0gZlN4DsH2fcMDGPlWUc9t9ef5xJcK8+1twIUNBFoAyd4yFB8HQLX+8k/NJI1Mbcp3EV UykQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763657907; x=1764262707; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pAUx4lPAAt5hhocIlS3eO4JgrnznXmHn7pMUp71lriA=; b=UkjDgWUQBqY8WmGa6b5AkZ7DP6eKiWJCg3W4xoqgsdp6RTK3XBZmxPWjS2mPdic4hV lGgLkmDoUxHMat9IAIQnAV9o6IG+aEsvV7jbibk7THL71Nk8u6O0c1HhbiT0Ck0vl5J+ U8nUEAip1zXl7fQZSgzOeXdCQqcHssL0MRGqWXHogISQf0ywt5UpDnqS0kHdubTWELUM +ClRBpbbzOx2fKXDA1M/KXDiZ9ClYN1Fd1NQ54bl3eTF+24BXYYTZVgXMcBIegh89T2/ DwyX2osvP7DODe5kGQRsVMIPBPUWUcHvCSmoy0h//qCtakRT+8KXV5b+ys2h+IQpeoQi zINw== X-Forwarded-Encrypted: i=1; AJvYcCUXAbyxbNIRRHs5xceh/Iwsh+DP2mJGrTeh//mhcy3a3Kq+Vkzq0W36Vo0zUmp2W5Jz3yk3kPGRFFevUuU=@vger.kernel.org X-Gm-Message-State: AOJu0YzNMXENY6/LHDpr3NO66iQ+XELcEt9QwAFtXtFmBAqkMf79Djxk YfoWCSg9sBH7pOxYCHCv/jWfJK+I14JjUksPDQinMkuZD1aR1qQAs3de X-Gm-Gg: ASbGnctmhCdZ72DDSsKBXCiZ1BqIbn5xFXdjmMARwxiMdIMteSCyJmJdlTiqTpwThLW 17yI2Vwghg9eZO+dLfCCvhaK1kVl+AhYc4vfnEduENJHFqrKFEhPYgsbFkRjkR9Sg/Vh9bEAyFC bsohTfmYlLeK4l/5TLXzj3qnmooTDu8gvHh8HV138WXQkEomTq4nggWGDOlv0Env9Lzlk6KjGzI KxqplhO7J0lJmNPdInJIiosGxx0DL/rzQMDIV37LM7efiPJChhGhCPyDaUu61EFbZ8VtWC1dGvA AERt4x5qeo+bOqICoBhpl9Xhvf6omNzkrRz3IHF2lG7ZjjqA3VS4Lm52ggK01zkaIb2JSSF4sze NvsvYBaJSG/WsDLgZuqoZvDcubcQKgoVlp7MGlvlJT7eXBOzRshjYz0Nx+5sfu1W048R2/rl7Nl puvDbJ0cAohLjHkLvVjBj2Xmru X-Google-Smtp-Source: AGHT+IFVjZ8EjTx36K9+Rzy4uZeI4ftPjrsBQ93SSXpRihhu3ckrFsUsfnJvIRLZA67Vz2mAIT3qHA== X-Received: by 2002:a17:902:db09:b0:298:595d:3d3a with SMTP id d9443c01a7336-29b5b11bed8mr45616265ad.50.1763657907052; Thu, 20 Nov 2025 08:58:27 -0800 (PST) Received: from google.com ([2402:7500:499:ceaa:a749:91bb:2939:6694]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29b5b274d39sm31879535ad.77.2025.11.20.08.58.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Nov 2025 08:58:26 -0800 (PST) Date: Fri, 21 Nov 2025 00:58:23 +0800 From: Kuan-Wei Chiu To: Theodore Tso Cc: David Laight , Guan-Chun Wu <409411716@gms.tku.edu.tw>, Andreas Dilger , linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] ext4: improve str2hashbuf by processing 4-byte chunks Message-ID: References: <20251116130105.1988020-1-409411716@gms.tku.edu.tw> <20251116193513.0f90712a@pumpkin> <20251120155816.GB13687@macsyma-3.local> 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-Disposition: inline Content-Transfer-Encoding: 8bit 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