From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (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 93DAB242D6B for ; Sun, 11 Jan 2026 10:40:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768128011; cv=none; b=ekod9a9LLPoH3dHlUqXV3BWOUjBReOdGYH3pTQEVygFwgKjFchxSwzJvDrz/PmLwgMsiGEf+D778lOFqqeDi64MvIP29+QZkQdg57HKKrUpyoJfh/FZbwO3LLQFZ3BLBlZjPmzq5/P5C7rR5RqqdUiKDYY662Ne8KBbmdRKMV2g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768128011; c=relaxed/simple; bh=aX2g3b1WtWXv10ns5hbv121x9Dc/E2co0B5RZzRgT8k=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=knxMYVGWNY5LaP9iVswRJ9vwlnnq4fhrmcxFqdtKPgpz8EY05zv8wA2KHPKdFnrJmNQ7jIEYkdOnYRWFqexHV0bmklF8Odc7FE+IzUhUKRpFQ/nPz9QRa2ks71rt/YwrVNxx2GmxG3hzU/Rj0yPU4F7+IXYaDLlcpBQBftHfSlA= 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=L4PIjfE6; arc=none smtp.client-ip=209.85.221.54 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="L4PIjfE6" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-432d28870ddso1675213f8f.3 for ; Sun, 11 Jan 2026 02:40:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768128008; x=1768732808; 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=t2eQXpsvYHJfaR4GA8BllRSlSwakwfa1jve2Y5udiNo=; b=L4PIjfE6yAm2iHTGMNqVZ/XzyMxw+31bXXqPvm5U/6gNFUbIEfeS1mVcdMrStN+/Gd KywjiE/FzhVVprG+tv8zYBl9gxcPlpBRdCPXtsm8h0nnvZeUHw4cehWFC6vni82ly8QR xWKDPML80fonmiAMn+wZk+OfxIV2JEvv2igZO/V2LHxnXUv7w96wbB/P9qP9Yc0Pq1aJ EsbIUMv+pjEZ4+GSi57Oc8UsgeTFCGhIy+n/8r60df3ukpBbTi+gTyIw8Pf/C8YtmcUY Owe/yAKxGvpyxyxtNo/tT7mVavArA9j+f0Z9cnawW56oU+Wu2b6B2bpzSgggQPGxhHwF zzbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768128008; x=1768732808; 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=t2eQXpsvYHJfaR4GA8BllRSlSwakwfa1jve2Y5udiNo=; b=IphoJYVNZhtngrF3dbdyZAmpVyGV81++SLJ0EVtyOfFaA4izFLyWUzMeNqdsa9Uuec USnEZamrOkRepM3Lv/ak2grsK9OnSyCoMFdwv0xmm1ChGorZSw/CidXC2/hcQ2gaYxrO BTyZYqzxwKHZeON5JZuq7+95zE1AFgr4exINAV2cZcloi6CbgVHTGQeJr47/1pyuMyEZ Hdcx7SziRW7v4xP7STM70liTayF9U7D/hhQ5wtpz2ifG/qDpgXy8PsCJ+ZYvFPlELxLo eWm0/iFHASygjnn7+5emwjgvJVIMZ3S/jxzPWJ7CxQxn5xt6LdiSQNMKMWBNLdF4kKOP 4rtw== X-Forwarded-Encrypted: i=1; AJvYcCUkt88jo1asQPRx+UvnAzZroMzksBJdP2mnwq2/UwqSTtc5GTxlc+CW/SyDfKLPelU85b1wgjvifePZ+sM=@vger.kernel.org X-Gm-Message-State: AOJu0Yxwz+qzPLvs/aPLfdvomMfCIt0pNPjko2BlMuI1IrATkdBHiQ0/ asO+JvKCbzBHfTgWePAQ4pO6u3nHXIydzHLhJjd50xuoTP3v2b6x4h+0 X-Gm-Gg: AY/fxX5zaN/VUXQlsVwHSFHZ/3cqFQa0YHHcFjnsgVYrGulU6cSbOZ42kbJTfNupoC/ udPoXT096QN4FyZgCL9GS5oa1B7h0/QuvMuFhY1o7sNouzBQ213AuZkC9NrLs2Z6y9lDCJnDMr6 KDuZ7M62M6ki85jVSj9461WDAXe4ZFqKvaLXCQEKVg+IXXPdbGBc6nzoyedOjWp8p7UY8GWu6lP 7JPFrJ3upgejNN4upocy4Za/G8cLLo7t2mS92NCpAid54ELUNzzIARDZCkou/W6uqtYVFYWGOZj CadTYnw1Aaztk1Iem/ki3dOqYeD8Nd9331NFVdMSxV6TLatkuh6Mn8wlSM34Px/8iwtsK1lk1Hg Cq/jouyR0qQ12q+icqFYgouzQ/jJIlfeGRQ+6n0YOd77vxMv3WxCHBqwGtMYqIdVMq4VCuDKkHG yGXOMKamXndhlWqqEC3JeGRamFT9UtRA4ysjt2dX1ZzHBGbsaYamWZ X-Google-Smtp-Source: AGHT+IFdu2wqT5+r7S6M8dlbHEQSusHNDBdM3VWyHB6pSRoVGjWojstar6v76hp0D04FDVepSDMlIg== X-Received: by 2002:a05:6000:4008:b0:430:fd84:3179 with SMTP id ffacd0b85a97d-432c374fc4emr19857221f8f.33.1768128007682; Sun, 11 Jan 2026 02:40:07 -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 ffacd0b85a97d-432bd0e199bsm32230562f8f.16.2026.01.11.02.40.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Jan 2026 02:40:07 -0800 (PST) Date: Sun, 11 Jan 2026 10:40:02 +0000 From: David Laight To: "Maciej W. Rozycki" Cc: Yury Norov , Petr Tesarik , Yury Norov , Rasmus Villemoes , Richard Henderson , Matt Turner , Magnus Lindholm , Vineet Gupta , Geert Uytterhoeven , Thomas Bogendoerfer , Madhavan Srinivasan , Michael Ellerman , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Chris Zankel , Max Filippov , Patrik Jakobsson , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Robin Murphy , Joerg Roedel , Will Deacon , Jakub Kicinski , Andrew Lunn , "David S. Miller" , Eric Dumazet , Paolo Abeni , Oliver Neukum , Arnd Bergmann , Kuan-Wei Chiu , Andrew Morton , Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , Pablo Neira Ayuso , Florian Westphal , linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 2/2] treewide, bits: use ffs_val() where it is open-coded Message-ID: <20260111104002.3e017fe2@pumpkin> In-Reply-To: References: <1ce341045ad0487c66ca21003f9974916aba0bce.1767975412.git.ptesarik@suse.com> <20260110115439.184b7a66@pumpkin> 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=US-ASCII Content-Transfer-Encoding: 7bit On Sun, 11 Jan 2026 03:15:22 +0000 (GMT) "Maciej W. Rozycki" wrote: > On Sat, 10 Jan 2026, David Laight wrote: > > > > > > diff --git a/arch/mips/dec/ecc-berr.c b/arch/mips/dec/ecc-berr.c > > > > > index 1eb356fdd8323..8934b8b1cf375 100644 > > > > > --- a/arch/mips/dec/ecc-berr.c > > > > > +++ b/arch/mips/dec/ecc-berr.c > > > > > @@ -153,7 +153,7 @@ static int dec_ecc_be_backend(struct pt_regs *regs, int is_fixup, int invoker) > > > > > /* Ack now, now we've rewritten (or not). */ > > > > > dec_ecc_be_ack(); > > > > > > > > > > - if (syn && syn == (syn & -syn)) { > > > > > + if (syn && syn == ffs_val(syn)) { > > > > > > > > It opencodes is_power_of_2(). > > > > Badly... > > It's 4 MIPS instructions and exactly the same machine code produced as > compiler output from `is_power_of_2'. The compiler must be detecting that x == (x & -x) is the same as (x & (x - 1)) == 0. Although for MIPS the former is negate, and, beq(x,y) - so 3 instructions. On x86 it is negate, and, cmp, beq(zero flag) - one extra instruction. (The 4th MIPS instruction will be beq(syn,0).) So maybe s/Badly/In an unusual way/ > If you know of a better alternative Doing is_power_of_2() with only one conditional branch would be a gain. But I've not thought about it hard enough to find one. I suspect there may not be one, but all these 'tricks' come from the 1970s (or earlier) and don't allow for the behaviour of modern cpu with multiple execution units and long pipelines. (Although MIPS is likely to be relatively sane.) David > I'll be happy to get enlightened, however it's academic anyway, as it's > the ECC memory error handler. If you get here, then you have a bigger > issue than a couple of extra instructions executed per kernel log entry > produced. If you indeed can get rid of them in the first place, that is. > > Maciej >