Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp163902pxu; Thu, 22 Oct 2020 19:07:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxduX4ApXMHZ4QON7ilanAmQC879VZThDqtlS15o9noyQ/AUL7PwjJAIyASbcoaidkak+Mr X-Received: by 2002:a17:907:2110:: with SMTP id qn16mr5367580ejb.133.1603418822600; Thu, 22 Oct 2020 19:07:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603418822; cv=none; d=google.com; s=arc-20160816; b=Pma7NUN/8EzuKA18U7zIeFIMdo56SJnzpwX0t3Lw3H/M0QqcFiyKt5a6ASHxl40Jff Y5QNJEoLGo4lxvZqWm5pu69NcBp1FOpLZuZw/HIsmbcoSylFdEvwTbV+S7ZPgXHocsAA AWI2Sgg4kP0ec0dGzR3635a3Sq537/sSuUHTPZTEOv531ZJwELJkPtbNUTB0hIjuPxHs rUOcgIya4xEPiPzKuhmYpAJaE9msgczhAZROcHtwO+c4anMXytV+6ah6xuNF2svpZkkN 7fIYPursHyS7E6LUZ70Rv4BCIPGaqKGNLTNiCo9/5wDMIIRIC3q1wzMvD98qJxqa/uch HQXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=TdWIJMNoapUnGTxeGJhgMcOhWseD+I3R+4gsvShygCU=; b=dBty74B5X1qQN2r7l1SjAy/vmGeNeunH2KA//3WUaj1DkCOUvK79hNT1pAXjVAGzmC y0oZYkUXxI0SZp0TfE61Gyu9sLBfKDT971o4ECplZnUE33CsFUtxUl6Mo21rEMAJfkbT w8zsEqo64JqOkB7W8H0RGfZqijF4KhIcEUa85t80FujZOJrDXZnuyuja4lhFyFdrn/mT oFHHYWbSwD/FwQ1zK/ekLOJwer1ofBeXC6Yv70YMi0AswWU3vPWjk7M5M/OkFF87Ex8J guOE1HuTLg6f3fgJjfLipQ3rN+vzgC3MBZSz5QWKLgLC09k9czRM+HqGz3VOFTksUyer 3fpw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q6si2069066edw.213.2020.10.22.19.06.39; Thu, 22 Oct 2020 19:07:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2897703AbgJVQnN (ORCPT + 99 others); Thu, 22 Oct 2020 12:43:13 -0400 Received: from gate.crashing.org ([63.228.1.57]:45828 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2503628AbgJVQnN (ORCPT ); Thu, 22 Oct 2020 12:43:13 -0400 Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 09MGbfEF008755; Thu, 22 Oct 2020 11:37:41 -0500 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 09MGbdTR008754; Thu, 22 Oct 2020 11:37:39 -0500 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Thu, 22 Oct 2020 11:37:39 -0500 From: Segher Boessenkool To: Christophe Leroy Cc: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , jakub@redhat.com, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: Re: [PATCH] powerpc/bitops: Fix possible undefined behaviour with fls() and fls64() Message-ID: <20201022163739.GU2672@gate.crashing.org> References: <348c2d3f19ffcff8abe50d52513f989c4581d000.1603375524.git.christophe.leroy@csgroup.eu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <348c2d3f19ffcff8abe50d52513f989c4581d000.1603375524.git.christophe.leroy@csgroup.eu> User-Agent: Mutt/1.4.2.3i Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 22, 2020 at 02:05:46PM +0000, Christophe Leroy wrote: > fls() and fls64() are using __builtin_ctz() and _builtin_ctzll(). > On powerpc, those builtins trivially use ctlzw and ctlzd power > instructions. > > Allthough those instructions provide the expected result with > input argument 0, __builtin_ctz() and __builtin_ctzll() are > documented as undefined for value 0. > When the input of fls(x) is a constant, just check x for nullity and > return either 0 or __builtin_clz(x). Otherwise, use cntlzw instruction > directly. That looks good :-) Acked-by: Segher Boessenkool Segher