From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69ED1C388F9 for ; Wed, 21 Oct 2020 13:45:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 05E0C2065C for ; Wed, 21 Oct 2020 13:45:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZnCoSqFo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2443017AbgJUNpW (ORCPT ); Wed, 21 Oct 2020 09:45:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:26465 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2441927AbgJUNpW (ORCPT ); Wed, 21 Oct 2020 09:45:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603287921; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=dZHoVIgGTf4WSQvGDru92osBx+3R75QibVdYWPN93hQ=; b=ZnCoSqFoDKubhH4z8TzeWzJFx5Y+m72YlPpefkg1sWHlFmCnUwbF/zle8YL703d4FbGYon gfSrjmlPEPuKbA6Y4x+ama+vU6fPmfcU+4HLPosUsYYwO1KpD4UP1Nes4r5w1bxRZ1Y3F8 B1tyqxF8TWjYrf1g4KsJ1l/xBI4Qqs8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-45-NveFuGx7MBmiJ13jndmGcQ-1; Wed, 21 Oct 2020 09:45:18 -0400 X-MC-Unique: NveFuGx7MBmiJ13jndmGcQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4F4AC108E1A4; Wed, 21 Oct 2020 13:45:17 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-112-37.ams2.redhat.com [10.36.112.37]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EA90D7512A; Wed, 21 Oct 2020 13:45:16 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id 09LDjDYe032616; Wed, 21 Oct 2020 15:45:14 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id 09LDjDRh032615; Wed, 21 Oct 2020 15:45:13 +0200 Date: Wed, 21 Oct 2020 15:45:13 +0200 From: Jakub Jelinek To: Christophe Leroy Cc: linux-toolchains@vger.kernel.org Subject: Re: ilog2 vs. GCC inlining heuristics Message-ID: <20201021134513.GD2176@tucnak> Reply-To: Jakub Jelinek References: <20201021132718.GB2176@tucnak> <14215e71-cd43-81aa-1965-0b0a6fb667fa@csgroup.eu> MIME-Version: 1.0 In-Reply-To: <14215e71-cd43-81aa-1965-0b0a6fb667fa@csgroup.eu> User-Agent: Mutt/1.11.3 (2019-02-01) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jakub@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-toolchains@vger.kernel.org On Wed, Oct 21, 2020 at 03:36:14PM +0200, Christophe Leroy wrote: > > --- a/include/linux/log2.h > > +++ b/include/linux/log2.h > > @@ -156,7 +156,8 @@ unsigned long __rounddown_pow_of_two(unsigned long n) > > #define ilog2(n) \ > > ( \ > > __builtin_constant_p(n) ? \ > > - const_ilog2(n) : \ > > + ((n) < 2 ? 0 : \ > > + 63 - __builtin_clzll (n)) : \ > > That is likely to work only on 64 bits targets. No, it should work on all. __builtin_clzll argument is long long, which should be 64-bit on all architectures Linux kernel supports (and all architectures GCC supports - ok, avr with -mint8 doesn't, but it isn't C requirements compatible in that case). const_ilog2 also uses long long and will work with any long long or unsigned long long value (but e.g. not with __uint128_t values on 64-bit architectures, guess the kernel doesn't need that though). And similarly, for the non-constant operands the sizeof below ensures that __ilog2_u64 is used (even on 32-bit arches) and will handle that. > On 32 bits targets I guess it needs to be 31 - __builtin_clz (n), doesn't it ? > > > (sizeof(n) <= 4) ? \ > > __ilog2_u32(n) : \ > > __ilog2_u64(n) \ > > > > Jakub > > Jakub