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 BBD4CC4363A for ; Thu, 22 Oct 2020 07:12:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E46121775 for ; Thu, 22 Oct 2020 07:12:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TFeYWUo0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2505377AbgJVHMo (ORCPT ); Thu, 22 Oct 2020 03:12:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:57444 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2505374AbgJVHMo (ORCPT ); Thu, 22 Oct 2020 03:12:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603350763; 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=K8ZvFix1Js8ZOxFrC9gpjodvVUvaXf4DDzZWd0L9AcM=; b=TFeYWUo03qcQoWh+HSgTaLoIDjrh84W/FUGakbhM2BUbZIN4ZqlFNBD9cEOfguufNZTIIE Y4yxRt+TRJq/xwRDBZpsZh2tUyOBdtOwpv4Bf06UkM6XA6q9ExuYtCqahsatZaHAaOgitL MFJ7l0qBCUlFfag9fw5YoYYPIRNwWAI= 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-262-dwJRiB4BM6ymy_Fpi2YrGw-1; Thu, 22 Oct 2020 03:12:41 -0400 X-MC-Unique: dwJRiB4BM6ymy_Fpi2YrGw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 09710804B60; Thu, 22 Oct 2020 07:12:40 +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 5AE2360BFA; Thu, 22 Oct 2020 07:12:39 +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 09M7Ca50013875; Thu, 22 Oct 2020 09:12:36 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id 09M7CX3K013874; Thu, 22 Oct 2020 09:12:33 +0200 Date: Thu, 22 Oct 2020 09:12:33 +0200 From: Jakub Jelinek To: Randy Dunlap Cc: Christophe Leroy , Peter Zijlstra , linux-toolchains@vger.kernel.org Subject: Re: ilog2 vs. GCC inlining heuristics Message-ID: <20201022071233.GK2176@tucnak> Reply-To: Jakub Jelinek References: <20201021132718.GB2176@tucnak> <20201021151947.GL2628@hirez.programming.kicks-ass.net> <21556974-eea1-ed6a-ea6f-3e97a6eea4bc@csgroup.eu> MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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 09:01:01PM -0700, Randy Dunlap wrote: > I ran a (new) lib/test_log2.ko before and after Jakub's patch and got the > same results, although I am not claiming that it has an exhaustive set of > tests in it. [it is attached] The test most likely tests the non-constant paths (which is something I haven't changed), unless all the loops would be completely unrolled, all the arrays determined to be never written to and turned into const and all the loads from those arrays optimized into constants. If you want to test both the non-constant and constant paths, it would be good to make sure to guarantee that. For non-constant, e.g. use those arrays but add some optimization barrier so that the compiler can't optimize them into constants (e.g. make the arrays volatile, or add __asm__ ("" : : "g" (test_power_of_2) : "memory"); etc. barriers at the start of test function etc. And for constants, perhaps put the test values into macros, through which to place it both #define TEST_ILOG2_UINT \ TEST (1, 0) TEST (2, 1) TEST (4, 2) TEST (~0U, 31) \ TEST (0x80000000U, 31) and once define TEST(x, y) as { x, y }, then #undef TEST and in another place as if (ilog2(x) != y) ... Also, you do want to test even behavior of ilog2 at 0, e.g. the powerpc fls/fls64 implementations are incorrect for that value as could be seen with -fsanitize=undefined. And you do want to test also unsigned long long. Jakub