From patchwork Mon May 8 14:11:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raphael Moreira Zinsly X-Patchwork-Id: 91167 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2187330vqo; Mon, 8 May 2023 07:12:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5lJfiagAQXnvNJjblG2nCJDvSgiNzAkwc0kCigICxfxARUtn3KLgoXrcE4uFSFD/L8pjUJ X-Received: by 2002:aa7:c0d7:0:b0:50b:d53d:7ceb with SMTP id j23-20020aa7c0d7000000b0050bd53d7cebmr7329064edp.40.1683555139414; Mon, 08 May 2023 07:12:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683555139; cv=none; d=google.com; s=arc-20160816; b=Bfs/kZdnMwD+U13D4+GgGjGY9douOHePmQxFfzN6ASnY0sC13si69A8lauQgcDmAuw uX7rnbubNV9aKu1R2x6yZrKJ91DAUz89+jX944mduVfhOGucUFfZSQvRhSPH8TR5UrE7 pSOhGu7AVd1LZknx2l5L2JpJXVtfk9VgDjSJoMocbPD0+r7Ktq9oPAQp6y0hBlzs9G3z gz2qjRtq2qcGkNHq/PMJ/PjGG/t05TjoV2pvLVbHPoFUEMUbZZkyYHL29UdjxB4Og/7q tfN2AfdNIz/IvRAQ36Q7d6mS9UuoQcz9mU7aPqhoN4L1n8EC42bPOSb0s97c3W3/f2WK ARPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dmarc-filter:delivered-to; bh=Tl76gH90wfyu7scc3KBrNhHzzWuCf6q0a5x4H/kiJbU=; b=Ag+Yi+Zdvk40rbjHrJhep8xVtgdOuXHKIjnU7CqCB4AY81z18kAidVNO6KaCf8yIDk SuqlKH4KPLn+eJ//hJ/DneVT30oEyKMgsKAVRqrt74wFH9t2cHw+nGVgFl5joMjxkRDy v6x2jygyz0TiWfwY+jV0FZHmy8DN/TVPifFSF7d/TpxIcfOJOaLakfks7s0Dd1ffQQIT xGHDqFHXXE/99gXP5ZnANn2ZnqNLacieHPhdKUsIaWRKscneMUeFl51vzd+mlczNDikZ IehcstLCtoOL4IJyEKX08rCNor+9MggYjIIIKIwcQlwEo5/uHVBzjcUeFZrvNuW9J1es INyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=edkA5mgB; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id o17-20020a056402039100b00506a3204d0esi9868846edv.475.2023.05.08.07.12.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 May 2023 07:12:19 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=edkA5mgB; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4C6D83853808 for ; Mon, 8 May 2023 14:12:00 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ot1-x32f.google.com (mail-ot1-x32f.google.com [IPv6:2607:f8b0:4864:20::32f]) by sourceware.org (Postfix) with ESMTPS id 302CD3856275 for ; Mon, 8 May 2023 14:11:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 302CD3856275 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=ventanamicro.com Received: by mail-ot1-x32f.google.com with SMTP id 46e09a7af769-6a5eea94963so4208516a34.3 for ; Mon, 08 May 2023 07:11:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1683555090; x=1686147090; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Tl76gH90wfyu7scc3KBrNhHzzWuCf6q0a5x4H/kiJbU=; b=edkA5mgBbHdvN/tRmRJTMtx91gXR2nCUSdmaPbaVnOgT5n1YbJ8swpG/pZMG/rRQEO 7LYuU7Tot/Le7VNDGVEZkB8GcxdAdjF6/rqx7LWi8hT62yZvcOTzTU32GYpQldzFwKRT GJ2ve3x9H+NlaebdzRtGgce/DzWInwN8JRYj6MdDHIx5rz8OrunDjqJknmYBHUcOKdku HT2DGcMKI6/wzvnjFzo9+3o4b/gwio4yf60HFhotGUQAfuieaHJdfQDNw1T1ad+oncZ/ ZtLrfcxkgAdVbTHXyix1O2wLcuM7AaHmmWDCyYivlwZtUOxarTFEZFQlvRVLk1HP+KSB Hvgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683555090; x=1686147090; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Tl76gH90wfyu7scc3KBrNhHzzWuCf6q0a5x4H/kiJbU=; b=f7xzpKkDtGFDN8FflL1r/xobnQ+uvc7YlkBeGxdNfOPtgY57M8s0eB45aGBXIBhYcB I8xxHd+XDytjtaNgI8YuM5+TMpdIQ2lTBbskO9vbXquEwuWsgtffNi5ad59n41iilQJc YEC4+mSjvTwYUvQzXyOba07Lhe6qfOJonmXHXW0JFmr+buoX0EE6nuuzUOauENZDifO2 bXxf+RKLIDc405GkU6gI2eXHMw/XK2EpQ6sfZGc7Ln0RObupdw/v0yHVt5gR6ugB14Px Tg/qlxYGK8LdDlcoyc+D2OEUsN0zKSUqn/nxFjAX9UbRcZivt/oDNLM11Y/GTW+Xu4uW s7nQ== X-Gm-Message-State: AC+VfDxx4uY7i5u6J7UWSILTmfH6+OhAVG95y2pIYLftT0vc9Uj6/WHM FESjzAOusLbVHA9hycCYbTtiMDL0dKGV4/s+LgE= X-Received: by 2002:a9d:67d3:0:b0:6a5:f48b:6b6c with SMTP id c19-20020a9d67d3000000b006a5f48b6b6cmr5192015otn.32.1683555090080; Mon, 08 May 2023 07:11:30 -0700 (PDT) Received: from marvin.dc1.ventanamicro.com ([2804:14d:bac2:9b0b::1000]) by smtp.gmail.com with ESMTPSA id a17-20020a9d74d1000000b006a1508d348dsm4172269otl.22.2023.05.08.07.11.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 May 2023 07:11:29 -0700 (PDT) From: Raphael Moreira Zinsly To: gcc-patches@gcc.gnu.org Cc: jeffreyalaw@gmail.com, Raphael Moreira Zinsly Subject: [PATCH v2] RISC-V: Add bext pattern for ZBS Date: Mon, 8 May 2023 11:11:22 -0300 Message-Id: <20230508141122.127023-1-rzinsly@ventanamicro.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765335513864647330?= X-GMAIL-MSGID: =?utf-8?q?1765335513864647330?= Changes since v1: - Removed name clash change. - Fix new pattern indentation. -- >8 -- When (a & (1 << bit_no)) is tested inside an IF we can use a bit extract. gcc/ChangeLog: * config/riscv/bitmanip.md (branch_bext): New split pattern. gcc/testsuite/ChangeLog: * gcc.target/riscv/zbs-bext-02.c: New test. --- gcc/config/riscv/bitmanip.md | 23 ++++++++++++++++++++ gcc/testsuite/gcc.target/riscv/zbs-bext-02.c | 18 +++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 gcc/testsuite/gcc.target/riscv/zbs-bext-02.c diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md index a27fc3e34a1..df522073344 100644 --- a/gcc/config/riscv/bitmanip.md +++ b/gcc/config/riscv/bitmanip.md @@ -720,6 +720,29 @@ operands[9] = GEN_INT (clearbit); }) +;; IF_THEN_ELSE: test for (a & (1 << BIT_NO)) +(define_insn_and_split "*branch_bext" + [(set (pc) + (if_then_else + (match_operator 1 "equality_operator" + [(zero_extract:X (match_operand:X 2 "register_operand" "r") + (const_int 1) + (zero_extend:X + (match_operand:QI 3 "register_operand" "r"))) + (const_int 0)]) + (label_ref (match_operand 0 "" "")) + (pc))) + (clobber (match_scratch:X 4 "=&r"))] + "TARGET_ZBS" + "#" + "&& reload_completed" + [(set (match_dup 4) (zero_extract:X (match_dup 2) + (const_int 1) + (zero_extend:X (match_dup 3)))) + (set (pc) (if_then_else (match_op_dup 1 [(match_dup 4) (const_int 0)]) + (label_ref (match_dup 0)) + (pc)))]) + ;; ZBKC or ZBC extension (define_insn "riscv_clmul_" [(set (match_operand:X 0 "register_operand" "=r") diff --git a/gcc/testsuite/gcc.target/riscv/zbs-bext-02.c b/gcc/testsuite/gcc.target/riscv/zbs-bext-02.c new file mode 100644 index 00000000000..3f3b8404eca --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zbs-bext-02.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gc_zbs -mabi=lp64" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" "-funroll-loops" } } */ + +int +foo(const long long B, int a) +{ + long long b = 1; + for (int sq = 0; sq < 64; sq++) + if (B & (b << sq)) + a++; + + return a; +} + +/* { dg-final { scan-assembler-times "bext\t" 1 } } */ +/* { dg-final { scan-assembler-not "bset" } } */ +/* { dg-final { scan-assembler-not "and" } } */