From patchwork Thu Jul 13 05:38:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Monk Chiang X-Patchwork-Id: 119552 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1607067vqm; Wed, 12 Jul 2023 22:41:03 -0700 (PDT) X-Google-Smtp-Source: APBJJlEQbnft/lDszHd77e3qzc5xrO+wiUCxGhuWuI8Q1jLVSO5ECeZc5eIJVw3y+lk1AnbGqYIl X-Received: by 2002:a17:906:2308:b0:98d:e7e3:5ab7 with SMTP id l8-20020a170906230800b0098de7e35ab7mr459837eja.11.1689226863184; Wed, 12 Jul 2023 22:41:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689226863; cv=none; d=google.com; s=arc-20160816; b=jXLqJACh3CHzydHehIca68BzZSww4fPit9V+4TAeKRQ25UKRyBMFQ72JSG4t2WAExc Y/Yy9oVBa4jzlLmezqealcX0/5PAegPEyWoqfG94DrxzxJnuyQrV96ovhwTB/Oxr/oj/ el+xIRKBIrFrkrkyXfN/QQciZBcVMqhncF7BqBRZ6tq1cDg2Vc+s0iJeBWKLOa4O057I xjPO9G/R+HxX8jB9its3diMQtPkyAh7+bccjtMqrKL3XM4tWJkKPvYKDFcYsW+yuhal0 y0UOl2vHs1QBKgthk//kEMe1Jja7S5FRSz0vylFRRCl+FYmPu+u8oKreWxsgJ5ByQeSG qDOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=C92HLFs5kPQ6rymxikgkieKOT2AmR9ONt/Ei48K+zT4=; fh=qrSW5/0w8xlfh7jG4vyw/+s8w25ncmPbe4tg/uQ/wDo=; b=ik/oGF2oba4KPCCNoP6VxnpvBpALz6y+uh5QHa15PcCW0Ft9yIAHJ/2D6Nqx7tqoN1 D6nUzU6/iwWgP/4OdeQuAL2Ly8QApCgeQca5BDxVa1XIH79Fe2PTMAmSLA/v4kGjRWfn yEEKlPi07Bd2XXpSP6tfQWlBMsfvPowYhX0zxLpyYxrOCsJS3IUC5sGc3lGlobYVe1S3 K4g/PEpQ85PyqvqTwxFVBh2EFONCNkdkEnnneCcuHcIthILtdC0sGeno1in7gqf0pnzF rTHmLBZj3En9rmyqqBRuF+7JnHrAu+NELjcGuVdG1TYUBcVyhZR9mMWs8lRGOTGzkR9U d9yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pbZRcfIp; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id p1-20020a1709060dc100b0099027b40d82si5830317eji.243.2023.07.12.22.41.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 22:41:03 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pbZRcfIp; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3DC8A3856DE6 for ; Thu, 13 Jul 2023 05:40:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3DC8A3856DE6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689226854; bh=C92HLFs5kPQ6rymxikgkieKOT2AmR9ONt/Ei48K+zT4=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=pbZRcfIpxPtuFEB00SaT8ejuNiDuv2PlXfqF0S41XUnMy+0iLZhnqQJm/CS9s5jaQ GvYs0b1swEWWfrwXDFazSyGzcfIFwJkbLt2rQ/U+JdJZ9WNYTadkHf2RGuzQ8ABT9N dwYMmPZv/Q3I9Rl4tReijV/KLECV20rXKlIOPTnY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id 0B9933857341 for ; Thu, 13 Jul 2023 05:39:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0B9933857341 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-68336d06620so350947b3a.1 for ; Wed, 12 Jul 2023 22:39:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689226759; x=1691818759; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=C92HLFs5kPQ6rymxikgkieKOT2AmR9ONt/Ei48K+zT4=; b=c6s8ozUfCnIGbn2VLDSJJ7f8yrcMS0GS74q5PY9y4cvedcfum7MVuvIfOHjxQmb8TZ RRtcB8O4bV6f687Kd2oYSTvGOXArm1F1d1friAjGTUlztjaKqpW8NIlT1D2jD5l6ugPa fkPwwAJIiTvcSW0Tmimsx4qGQV+Y29OaY0mgUGdu092Mom38uEwfM4fNgZ9KysWdohNp FIQ2Td+6X/UBNstqSP3uEWnzBCESIgSxrhmLvk9Yhk7iACzTrzY8PY1ajgDo1DEBpIfg nyELcHP4hGfSURqpehLpu2wRFZiQtEEmrMvOjEO3DM4PasSKMF6XDRqmPcQbjZaINKC/ jE5g== X-Gm-Message-State: ABy/qLZvtq/YS3L9KfzSLNeVBUK+P+pc47pvslpd3SVuGM1RBxCFd1J8 X296aZbwCECKhGJR4nIFiTj24ZKZtYZyQWX3JGDuE9cW6bTODT/aBi/isfYYFlzqE/kSdpPS7Uk ZS1L6gg/CfiZnj/071HG++frZD3MzmTbcokRUpnC2MmHzhtpqPP/dCFA5BYttdU4g4Ic/ukvFCE T5CtoK X-Received: by 2002:a05:6a21:7803:b0:118:eeef:2a25 with SMTP id be3-20020a056a21780300b00118eeef2a25mr567132pzc.34.1689226758696; Wed, 12 Jul 2023 22:39:18 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id m13-20020aa78a0d000000b006828ee9fa69sm4497399pfa.206.2023.07.12.22.39.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 22:39:18 -0700 (PDT) To: gcc-patches@gcc.gnu.org, kito.cheng@gmail.com Cc: Monk Chiang Subject: [PATCH 2/2] RISC-V: Implement locality for __builtin_prefetch Date: Thu, 13 Jul 2023 13:38:56 +0800 Message-Id: <20230713053856.101950-2-monk.chiang@sifive.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230713053856.101950-1-monk.chiang@sifive.com> References: <20230713053856.101950-1-monk.chiang@sifive.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 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: , X-Patchwork-Original-From: Monk Chiang via Gcc-patches From: Monk Chiang Reply-To: Monk Chiang Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771282747229478830 X-GMAIL-MSGID: 1771282747229478830 gcc/ChangeLog: * config/riscv/riscv.cc (riscv_print_operand): Add 'N' for print a non-temporal locality hints instruction. * config/riscv/riscv.md (prefetch): Add NTLH instruction for prefetch.r and prefetch.w. gcc/testsuite/ChangeLog: * gcc.target/riscv/prefetch-zihintntl.c: New test. --- gcc/config/riscv/riscv.cc | 22 +++++++++++++++++++ gcc/config/riscv/riscv.md | 10 ++++++--- .../gcc.target/riscv/prefetch-zihintntl.c | 20 +++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/prefetch-zihintntl.c diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 706c18416db..42f80088bab 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -4532,6 +4532,7 @@ riscv_memmodel_needs_amo_release (enum memmodel model) 'A' Print the atomic operation suffix for memory model OP. 'I' Print the LR suffix for memory model OP. 'J' Print the SC suffix for memory model OP. + 'N' Print a non-temporal locality hints instruction. 'z' Print x0 if OP is zero, otherwise print OP normally. 'i' Print i if the operand is not a register. 'S' Print shift-index of single-bit mask OP. @@ -4718,6 +4719,27 @@ riscv_print_operand (FILE *file, rtx op, int letter) break; } + case 'N': + { + const char *ntl_hint = NULL; + switch (INTVAL (op)) + { + case 0: + ntl_hint = "ntl.all"; + break; + case 1: + ntl_hint = "ntl.pall"; + break; + case 2: + ntl_hint = "ntl.p1"; + break; + } + + if (ntl_hint) + asm_fprintf (file, "%s\n\t", ntl_hint); + break; + } + case 'i': if (code != REG) fputs ("i", file); diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md index 7988026d129..3357c981b5d 100644 --- a/gcc/config/riscv/riscv.md +++ b/gcc/config/riscv/riscv.md @@ -3256,11 +3256,15 @@ { switch (INTVAL (operands[1])) { - case 0: return "prefetch.r\t%a0"; - case 1: return "prefetch.w\t%a0"; + case 0: return TARGET_ZIHINTNTL ? "%N2prefetch.r\t%a0" : "prefetch.r\t%a0"; + case 1: return TARGET_ZIHINTNTL ? "%N2prefetch.w\t%a0" : "prefetch.w\t%a0"; default: gcc_unreachable (); } -}) +} + [(set (attr "length") (if_then_else (and (match_test "TARGET_ZIHINTNTL") + (match_test "INTVAL (operands[2]) != 3")) + (const_string "8") + (const_string "4")))]) (define_insn "riscv_prefetchi_" [(unspec_volatile:X [(match_operand:X 0 "address_operand" "r") diff --git a/gcc/testsuite/gcc.target/riscv/prefetch-zihintntl.c b/gcc/testsuite/gcc.target/riscv/prefetch-zihintntl.c new file mode 100644 index 00000000000..78a3afe6833 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/prefetch-zihintntl.c @@ -0,0 +1,20 @@ +/* { dg-do compile target { { rv64-*-*}}} */ +/* { dg-options "-march=rv64gc_zicbop_zihintntl -mabi=lp64" } */ + +void foo (char *p) +{ + __builtin_prefetch (p, 0, 0); + __builtin_prefetch (p, 0, 1); + __builtin_prefetch (p, 0, 2); + __builtin_prefetch (p, 0, 3); + __builtin_prefetch (p, 1, 0); + __builtin_prefetch (p, 1, 1); + __builtin_prefetch (p, 1, 2); + __builtin_prefetch (p, 1, 3); +} + +/* { dg-final { scan-assembler-times "ntl.all" 2 } } */ +/* { dg-final { scan-assembler-times "ntl.pall" 2 } } */ +/* { dg-final { scan-assembler-times "ntl.p1" 2 } } */ +/* { dg-final { scan-assembler-times "prefetch.r" 4 } } */ +/* { dg-final { scan-assembler-times "prefetch.w" 4 } } */