Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp3115331pxb; Tue, 13 Apr 2021 19:42:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8gWwLSQCOTn/r5ljUv0r5uoeG4ZXINXniBZWGc9zUp+3C3Ai0NNljEmXhewg58/ftqJ22 X-Received: by 2002:aa7:d78a:: with SMTP id s10mr37677162edq.226.1618368158571; Tue, 13 Apr 2021 19:42:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618368158; cv=none; d=google.com; s=arc-20160816; b=0Xchf8QgR+9DBwdh0rRcDIuxhc/0grWJmtydW+niLISYslb4W1qBeEt1ctKccmOSWy xhbkGDlPvJXqxZ5u5cwSEedIGTUmBTxuM7imZJjs+oSpTjdrDe3GK1sDXq5V0MMLsVzL K43YkuInRHr6q3Rp7Oj+kb4qOzqoHQgUiTBjMQMisjfXmJSAEDh5nkRImOGcnD2Qv6o6 r0nRgm3IqsHx7/bX0SnQxc2CCaOtL9vKMPYE+o5aICQnCaZlDs7XxFarpK92AO9z7tUl qyZaI9IJNxRg8voT5t7mLUowZ9CHtWL2ucJIZUiwArgeps+VJkqZg3GiMUAGMD0ErqR3 4NXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=nWrbpWnmm/7j3sWD1WvzmoMRp2jsQUzgs0ntjH8MAoQ=; b=IcrMd0zIWLvm3WmZDkUpP8VGU2MFMiKfpHvusn1T5fH6N722DL/sQtyaOyc0rUwIHn 77/tymq4xxCgjcqxCYIA+kKeimbI0BpIb+2uTuDK3QPWfsv6LjyJAMFoNIbWLW0MBmf6 ciUJTnFwIA2XcQUzSVKhCswGRyYYls60JKS3bCEdF7bUVfGM2BCGVjoTDkIduN0mKudm yTWcZdvtyAAN6cxE/E9f67hiDVwD1TEBXca0j7hfcZUFzY0dCQ3z/RnPoJAOr98IlVJE Pf02S5xEJ/8Hj+OQz54F1cmSC0KXtF4u66ggfY26hiasEGv/+9QzVIhDLEfqEZeeu18r 9dVQ== 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 cz23si11434519edb.378.2021.04.13.19.42.14; Tue, 13 Apr 2021 19:42:38 -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 S1346029AbhDMQeT (ORCPT + 99 others); Tue, 13 Apr 2021 12:34:19 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:26114 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345952AbhDMQeQ (ORCPT ); Tue, 13 Apr 2021 12:34:16 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 4FKWQ85jTzz9tyy6; Tue, 13 Apr 2021 18:33:52 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id 0dXyJCLmzTLu; Tue, 13 Apr 2021 18:33:52 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 4FKWQ84QPdz9v20H; Tue, 13 Apr 2021 18:33:52 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id ED1198B7AC; Tue, 13 Apr 2021 18:33:53 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id hU_iZ0QrHbVB; Tue, 13 Apr 2021 18:33:53 +0200 (CEST) Received: from [192.168.4.90] (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 7453D8B75F; Tue, 13 Apr 2021 18:33:53 +0200 (CEST) Subject: Re: [PATCH v1 1/2] powerpc/bitops: Use immediate operand when possible To: Segher Boessenkool Cc: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org References: <09da6fec57792d6559d1ea64e00be9870b02dab4.1617896018.git.christophe.leroy@csgroup.eu> <20210412215428.GM26583@gate.crashing.org> From: Christophe Leroy Message-ID: Date: Tue, 13 Apr 2021 18:33:19 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 MIME-Version: 1.0 In-Reply-To: <20210412215428.GM26583@gate.crashing.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 12/04/2021 à 23:54, Segher Boessenkool a écrit : > Hi! > > On Thu, Apr 08, 2021 at 03:33:44PM +0000, Christophe Leroy wrote: >> For clear bits, on 32 bits 'rlwinm' can be used instead or 'andc' for >> when all bits to be cleared are consecutive. > > Also on 64-bits, as long as both the top and bottom bits are in the low > 32-bit half (for 32 bit mode, it can wrap as well). Yes. But here we are talking about clearing a few bits, all other ones must remain unchanged. An rlwinm on PPC64 will always clear the upper part, which is unlikely what we want. > >> For the time being only >> handle the single bit case, which we detect by checking whether the >> mask is a power of two. > > You could look at rs6000_is_valid_mask in GCC: > > used by rs6000_is_valid_and_mask immediately after it. You probably > want to allow only rlwinm in your case, and please note this checks if > something is a valid mask, not the inverse of a valid mask (as you > want here). This check looks more complex than what I need. It is used for both rlw... and rld..., and it calculates the operants. The only thing I need is to validate the mask. I found a way: By anding the mask with the complement of itself rotated by left bits to 1, we identify the transitions from 0 to 1. If the result is a power of 2, it means there's only one transition so the mask is as expected. So I did that in v2. > > So yes this is pretty involved :-) > > Your patch looks good btw. But please use "n", not "i", as constraint? Done. Christophe