From patchwork Tue Jun 6 13:48:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Segher Boessenkool X-Patchwork-Id: 103832 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3407558vqr; Tue, 6 Jun 2023 06:49:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4C12gbWRHhHg9nq6VulYnyjUc35Cuk+I+FJqPl0Y8HVU6z71bFcjmOTEt2kntCsff9KsF/ X-Received: by 2002:aa7:db91:0:b0:516:416b:574d with SMTP id u17-20020aa7db91000000b00516416b574dmr1916008edt.3.1686059358601; Tue, 06 Jun 2023 06:49:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686059358; cv=none; d=google.com; s=arc-20160816; b=UVOGKyNPIjzB8Hy6l3FqAVunGKMBVrezUIIufygMYsry8MDP3tVe1/rHuobdT9x8kq OlBgkQ9Cu3br2RDkvcHFrgB6VFimU2t4G6/WuPTc/ZDy4iAzkCyHsNFS0Z0d5gaq0FF7 SpKo1u5duP8F/7H9PiYi7GKzbi6x5GRpQS/CZWYmEgEXfPKXHq91ttL1QP5sF6iQ+zCB j7rZYFk9m6MqQHdrrBaiGmQ+gn0xDERgN8U2a91VRLYDMV6z3Z1eFSw3nL0F4MOO1sjh LfKv6t3LifCqxqhNgwJ/slQ6lwSUMlo+FJtOy6fEaeFQSqnX4OrGJ9EOZXGi5NoUuxzS xf8Q== 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:message-id:date:subject:cc:to :from:dkim-filter:dkim-filter:dmarc-filter:delivered-to; bh=RCz2E2IsMluZZDI0KLcg4tW2xcA0DJYzQlKKvRNpDXc=; b=RF8bqWUptFUoCi38Ewugu6OXEmzkRYIjXXZe1DA0FoXlm1GPj/BlNu6K6Vad2g8El0 MZmQKMJxwQzBEa3rj2QjsaUqKgXbp1CZlkb9QUCam0sZx8hWZjqbSeWwBoEHy007Wr3f XZfKeDcU/tgze2BIYelPDu2fS8+rNGUPWgNcGKlxpiR/AaF8AF/VLIlnE+wxP8VyxnPu SciKR6e7StoDyiFL9UVGmSbVomK9Y1RMQ0tf5KjUx1cOKHtqyn7YEKs+FGgAvaN4DH06 /CdSpzxQBNj6qkDMIzmlytd1ECi8e3boggmm9lsxMTkRbg+LHHAIWavDC60Gqxjf/nfA Rc1g== ARC-Authentication-Results: i=1; mx.google.com; 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 r16-20020aa7cb90000000b00514a23e7f0fsi6493579edt.485.2023.06.06.06.49.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jun 2023 06:49:18 -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; 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 8FC203857342 for ; Tue, 6 Jun 2023 13:49:12 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by sourceware.org (Postfix) with ESMTPS id 2C2993858D38 for ; Tue, 6 Jun 2023 13:48:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2C2993858D38 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org Authentication-Results: sourceware.org; spf=none smtp.mailfrom=gcc135.osuosl.org Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 7F0B481339; Tue, 6 Jun 2023 13:48:38 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 7F0B481339 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mgLkY_DgDCww; Tue, 6 Jun 2023 13:48:37 +0000 (UTC) Received: from gcc135.osuosl.org (gcc135.osuosl.org [140.211.9.83]) by smtp1.osuosl.org (Postfix) with ESMTP id 7FAFA80EAE; Tue, 6 Jun 2023 13:48:37 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 7FAFA80EAE Received: by gcc135.osuosl.org (Postfix, from userid 61019) id 5A5DD200489; Tue, 6 Jun 2023 13:48:37 +0000 (UTC) From: Segher Boessenkool To: gcc-patches@gcc.gnu.org Cc: dje.gcc@gmail.com, "Kewen.Lin" , Segher Boessenkool Subject: [PATCH 1/2] rs6000: genfusion: Rewrite load/compare code Date: Tue, 6 Jun 2023 13:48:31 +0000 Message-Id: <8092d8e9d8880dc4cd7e3a7e420a7c998597ca69.1686058670.git.segher@kernel.crashing.org> X-Mailer: git-send-email 1.8.3.1 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_NONE, SPF_NONE, 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?1767961377793914118?= X-GMAIL-MSGID: =?utf-8?q?1767961377793914118?= This makes the code more readable, more digestible, more maintainable, more extensible. That kind of thing. It does that by pulling things apart a bit, but also making what stays together more cohesive lumps. The original function was a bunch of loops and early-outs, and then quite a bit of stuff done per iteration, with the iterations essentially independent of each other. This patch moves the stuff done for one iteration to a new _one function. The second big thing is the stuff printed to the .md file is done in "here documents" now, which is a lot more readable than having to quote and escape and double-escape pieces of text. Whitespace inside the here-document is significant (will be printed as-is), which is a bit awkward sometimes, or might take some getting used to, but it is also one of the benefits of using them. Local variables are declared at first use (or close to first use). There also shouldn't be many at all, often you can write easier to read and manage code by omitting to name something that is hard to name in the first place. Finally some things are done in more typical, more modern, and tighter Perl style, for example REs in "if"s or "qw" for lists of constants. 2023-06-06 Segher Boessenkool * config/rs6000/genfusion.pl (gen_ld_cmpi_p10_one): New, rewritten and split out from... (gen_ld_cmpi_p10): ... this. --- gcc/config/rs6000/genfusion.pl | 185 +++++++++++++++++++++++------------------ 1 file changed, 103 insertions(+), 82 deletions(-) diff --git a/gcc/config/rs6000/genfusion.pl b/gcc/config/rs6000/genfusion.pl index e4db352..2851bb7 100755 --- a/gcc/config/rs6000/genfusion.pl +++ b/gcc/config/rs6000/genfusion.pl @@ -53,92 +53,113 @@ sub mode_to_ldst_char return '?'; } +sub gen_ld_cmpi_p10_one +{ + my ($lmode, $result, $ccmode) = @_; + + my $np = "NON_PREFIXED_D"; + my $mempred = "non_update_memory_operand"; + my $extend; + + if ($ccmode eq "CC") { + # ld and lwa are both DS-FORM. + ($lmode =~ /^[SD]I$/) and $np = "NON_PREFIXED_DS"; + ($lmode =~ /^[SD]I$/) and $mempred = "ds_form_mem_operand"; + } else { + if ($lmode eq "DI") { + # ld is DS-form, but lwz is not. + $np = "NON_PREFIXED_DS"; + $mempred = "ds_form_mem_operand"; + } + } + + my $cmpl = ($ccmode eq "CC") ? "" : "l"; + my $echr = ($ccmode eq "CC") ? "a" : "z"; + if ($lmode eq "DI") { $echr = ""; } + my $constpred = ($ccmode eq "CC") ? "const_m1_to_1_operand" + : "const_0_to_1_operand"; + + # For clobber, we need a SI/DI reg in case we + # split because we have to sign/zero extend. + my $clobbermode = ($lmode =~ /^[QH]I$/) ? "GPR" : $lmode; + if ($result =~ /^EXT/ || $result eq "GPR" || $clobbermode eq "GPR") { + # We always need extension if result > lmode. + $extend = ($ccmode eq "CC") ? "sign" : "zero"; + } else { + # Result of SI/DI does not need sign extension. + $extend = "none"; + } + + my $ldst = mode_to_ldst_char($lmode); + print < lmode. - if ( $ccmode eq 'CC' ) { - $extend = "sign"; - } else { - $extend = "zero"; - } - } else { - # Result of SI/DI does not need sign extension. - $extend = "none"; - } - print ";; load-cmpi fusion pattern generated by gen_ld_cmpi_p10\n"; - print ";; load mode is $lmode result mode is $result compare mode is $ccmode extend is $extend\n"; + foreach my $lmode (qw/DI SI HI QI/) { + foreach my $result ("clobber", $lmode, "EXT$lmode") { + # EXTDI does not exist, and we cannot directly produce HI/QI results. + next if $result =~ /^(QI|HI|EXTDI)$/; - print "(define_insn_and_split \"*l${ldst}${echr}_cmp${cmpl}di_cr0_${lmode}_${result}_${ccmode}_${extend}\"\n"; - print " [(set (match_operand:${ccmode} 2 \"cc_reg_operand\" \"=x\")\n"; - print " (compare:${ccmode} (match_operand:${lmode} 1 \"${mempred}\" \"m\")\n"; - if ($ccmode eq 'CCUNS') { print " "; } - print " (match_operand:${lmode} 3 \"${constpred}\" \"n\")))\n"; - if ($result eq 'clobber') { - print " (clobber (match_scratch:${clobbermode} 0 \"=r\"))]\n"; - } elsif ($result eq $lmode) { - print " (set (match_operand:${result} 0 \"gpc_reg_operand\" \"=r\") (match_dup 1))]\n"; - } else { - print " (set (match_operand:${result} 0 \"gpc_reg_operand\" \"=r\") (${extend}_extend:${result} (match_dup 1)))]\n"; - } - print " \"(TARGET_P10_FUSION)\"\n"; - print " \"l${ldst}${echr}%X1 %0,%1\\;cmp${cmpl}di %2,%0,%3\"\n"; - print " \"&& reload_completed\n"; - print " && (cc_reg_not_cr0_operand (operands[2], CCmode)\n"; - print " || !address_is_non_pfx_d_or_x (XEXP (operands[1], 0),\n"; - print " ${lmode}mode, ${np}))\"\n"; + # Don't allow EXTQI because that would allow HI result which we can't do. + $result = "GPR" if $result eq "EXTQI"; - if ($extend eq "none") { - print " [(set (match_dup 0) (match_dup 1))\n"; - } else { - $resultmode = $result; - if ( $result eq 'clobber' ) { $resultmode = $clobbermode } - print " [(set (match_dup 0) (${extend}_extend:${resultmode} (match_dup 1)))\n"; - } - print " (set (match_dup 2)\n"; - print " (compare:${ccmode} (match_dup 0) (match_dup 3)))]\n"; - print " \"\"\n"; - print " [(set_attr \"type\" \"fused_load_cmpi\")\n"; - print " (set_attr \"cost\" \"8\")\n"; - print " (set_attr \"length\" \"8\")])\n"; - print "\n"; + foreach my $ccmode (qw/CC CCUNS/) { + # We do not have signed single-byte loads. + next if ($lmode eq "QI" and $ccmode eq "CC"); + + gen_ld_cmpi_p10_one($lmode, $result, $ccmode); } } }