From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 3F6952045A0; Fri, 14 Mar 2025 19:06:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741979174; cv=none; b=tpAxo9pujx8mJUp6oQD1LheZuE4/7SZPLrnyOlRljeabY9dv4U4sG9Y2BepZTvyhl5mGIk01+QcjIeymO7npc35objl4KTSwKkN4UbeiRipitNz4FZFzInTKrzRCnkoZMh9ndaM1ZOJ3zTHfsC97enx7qPzdu0lyDqi9KBnEs8M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741979174; c=relaxed/simple; bh=ajFs9F0tAspFsaI2EHxXJ0ngkqO/JuYLnCLOEmhLTss=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=I3GG2qKdlro5hEExXi4euScqjyxE2U4da6jrQI8yjR3Co76uaJ1Nn0w0t9Nm8OSw8YjKzywLo1ARtzS5fxxLfbEt25NrtuEqjRDu+X4pYNzVB6gM2BbGSCde0RRMDeGEz7gKC9H1tVG3ztE8a8o31wvPGFiI10pTiTACXtO4ncg= 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=XlLHyDl3; arc=none smtp.client-ip=209.85.128.47 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="XlLHyDl3" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-43ce71582e9so349795e9.1; Fri, 14 Mar 2025 12:06:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741979170; x=1742583970; 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=EIoPbweeHXZ8jSMzIt/eB2E0Gri/NMU0G6vQgDoXF0o=; b=XlLHyDl3eUOprv01lXeEemsM1FgnYwaEs/0b5Chk/DA7ktGFKaVodjN0GQekqwUjhn bqz6dvobhPIgIuMFv5gOlIfNXXKN0CLf8OJSecqtxNgwmsIP+bUm2jQoKr6BJ2SZNIO5 ZDZq2+lc1CijfG2ojAokidmCalOIq1KpGLlPxu4iDWNGUBvO426wr3rkxggd2rt3yN/V oLky0o/sk+KNqMAnj8PbkSuaLgr3ioJESog/1jva4X34+7666kT/oAG0PATA5V/Zrfou lV251g8RiGcgqe7+AEBNgFOt9Z/6sz0WI5EAoEK25J0H3Vl7Xu2yFthT1xfC/rZQzMxT M1RQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741979170; x=1742583970; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EIoPbweeHXZ8jSMzIt/eB2E0Gri/NMU0G6vQgDoXF0o=; b=AZYhYoQqdW15wamZsdWf7N/sgTikbrxPlqchufXJp2m3HsnFDTTQBHGsY4PHM9SWfB vfUvyM/Rd5rNBIC5QzGCC659s1xZduL5xoAkTG+bhvlgGK9ujIAOC9ceYqAzmzLpCfmI LUgYnY95tly3Z41zZwjYrLiYz0k8enwhnH+xe+Xr+sp104IWh7T5eUNF6h5fh3s3PxH3 x7QCZNXydv7ocKbXDu56cUd9FdP+m/32cN/bKJBVmqb2DHi4z/JtN0jzuiuMEUAovP3w S6m06m35T/puFt9XuLH2p6WuITmWZwP5z6blxGPrCOlchFLzPdWWleXKHkasQUDvi4Oz 0/xA== X-Forwarded-Encrypted: i=1; AJvYcCU0fWx0MiJ96GFzzFC/asOs4Kg3xF8JFEc3LzKNVya/T/yUq60JrBh/1WGtxyVfB26xjNatXVwRVKBAVeY=@vger.kernel.org, AJvYcCUbAqPMXQI1rpULNbBTOsHJTKGcu75EWa00Vc6zLVZqnEDdBxOeZDnoia45E8vOyQ6rH3cyX+YT@vger.kernel.org, AJvYcCV85Wd3hCkA7WpLetwOIja3v5qZHIhDI0oSafly2rEgxqsMuVoItnFNr2nTLz6nwy2P1m5N9FLrPIQt4ImwLGk=@vger.kernel.org, AJvYcCVfgFhj40wxYlDAvV27ROdhViWQAotLjBnqXFuG2nMIpg47ray4DJHvMfqctEiM9tOl6oc=@vger.kernel.org, AJvYcCVoVrdKL5nEQ+u3eCtB2cJrhTXAr1H08c/WQCyZ/RWtY/l+Vy812eWcDETV0PFLe+I03dnFub5JUNfDkmE=@vger.kernel.org, AJvYcCXQfGXFGJDL/LvL5TBugYkV7biGENukGiB7ctrQBS3KIPuOl1e+oeESGDQdUOKqKRkVBS02morkqKff17nY@vger.kernel.org, AJvYcCXq291kN7oM93pqX24EUs31AYIbFltuLCxgORnco4H5fuJrf0qDDk4hHLDKckMATe9zwmg9N91cNUDwe2K+@vger.kernel.org X-Gm-Message-State: AOJu0YxDBlsu7uUqMD3E0XSTN1hRE2sFm/Xl+1jhObjkdjeIyX6GSPYO 1pg4YsvDir5/6r+r4zqQfh0+cPcZWpy+x8qy6y5Y+KgXHEVnRIlq X-Gm-Gg: ASbGncsOAgKHb1xE/Fj8LBYRbf46QM2ntS+roMiApYgDNk8SCi3r+beCZWDSVxfzAbb MYAWbY8lJTLJxTo+O096pScQh+UYWf+2ceZca5brwQYvqVl0DTl3XtVCHHGF+KaDjSUtzpscxEL 1XqJ+wAKhIalf5otzLe/zQHHB6KugqYHSvz6ebtfh0PyP1Eap/OlDv1SMF8iZQXv2zPrOwZuU0V LKM4SVtERWr/MlHWy0/QxcKo+QJB3qv3kY759O3Du4QdRwrtANYBHkOaSH2DV46zy/7+LWYEoGj nGOh5o+pyF2/mwTFwhjltbqbyfY4Kx/AjDYm6tn+5yMmjvXP+cMFGyeAIOorSLjZE70MHfC/+OH 2OK5VTJ0= X-Google-Smtp-Source: AGHT+IEjEm1NLGYF77AUJiqADkJJt9c0HAwrROWKW9ldaOHP/gE/432Db9RpHAyqooeI7TNtApdt1Q== X-Received: by 2002:a05:600c:4447:b0:43c:eea9:f45a with SMTP id 5b1f17b1804b1-43d1ec646demr47176475e9.4.1741979169941; Fri, 14 Mar 2025 12:06:09 -0700 (PDT) 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-43d200fae32sm25534355e9.31.2025.03.14.12.06.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Mar 2025 12:06:09 -0700 (PDT) Date: Fri, 14 Mar 2025 19:06:04 +0000 From: David Laight To: Jacob Keller Cc: "H. Peter Anvin" , Yury Norov , Jiri Slaby , Ingo Molnar , Kuan-Wei Chiu , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Yu-Chun Lin Subject: Re: [PATCH v3 01/16] bitops: Change parity8() return type to bool Message-ID: <20250314190604.53470966@pumpkin> In-Reply-To: References: <20250306162541.2633025-1-visitorckw@gmail.com> <20250306162541.2633025-2-visitorckw@gmail.com> <9d4b77da-18c5-4551-ae94-a2b9fe78489a@kernel.org> <20250307193643.28065d2d@pumpkin> <0F794C6F-32A9-4F34-9516-CEE24EA4BC49@zytor.com> <795281B1-9B8A-477F-8012-DECD14CB53E5@zytor.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-media@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 Thu, 13 Mar 2025 14:09:24 -0700 Jacob Keller wrote: > On 3/13/2025 9:36 AM, H. Peter Anvin wrote: > > On March 13, 2025 9:24:38 AM PDT, Yury Norov wrote: > >> On Wed, Mar 12, 2025 at 05:09:16PM -0700, H. Peter Anvin wrote: > >>> On March 12, 2025 4:56:31 PM PDT, Jacob Keller wrote: > >> > >> [...] > >> > >>>> This is really a question of whether you expect odd or even parity as > >>>> the "true" value. I think that would depend on context, and we may not > >>>> reach a good consensus. > >>>> > >>>> I do agree that my brain would jump to "true is even, false is odd". > >>>> However, I also agree returning the value as 0 for even and 1 for odd > >>>> kind of made sense before, and updating this to be a bool and then > >>>> requiring to switch all the callers is a bit obnoxious... > >>> > >>> Odd = 1 = true is the only same definition. It is a bitwise XOR, or sum mod 1. > >> > >> The x86 implementation will be "popcnt(val) & 1", right? So if we > >> choose to go with odd == false, we'll have to add an extra negation. > >> So because it's a purely conventional thing, let's just pick a simpler > >> one? > >> > >> Compiler's builtin parity() returns 1 for odd. > >> > >> Thanks, > >> Yury > > > > The x86 implementation, no, but there will be plenty of others having that exact definition. > > Makes sense to stick with that existing convention then. Enough to > convince me. There is the possibility that the compiler will treat the builtin as having an 'int' result without the constraint of it being zero or one. In which case the conversion to bool will be a compare. This doesn't happen on x86-64 (gcc or clang) - but who knows elsewhere. For x86 popcnt(val) & 1 is best (except for parity8) but requires a non-archaic cpu. (Probably Nehelem or K10 or later - includes Sandy bridge and all the 'earth movers'.) Since performance isn't critical the generic C code is actually ok. (The 'parity' flag bit is only set on the low 8 bits.) David