From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vk1-xa2c.google.com (mail-vk1-xa2c.google.com [IPv6:2607:f8b0:4864:20::a2c]) by sourceware.org (Postfix) with ESMTPS id 271003858CDB for ; Fri, 14 Jul 2023 07:13:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 271003858CDB Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-vk1-xa2c.google.com with SMTP id 71dfb90a1353d-45a0ee1c411so415902e0c.0 for ; Fri, 14 Jul 2023 00:13:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689318813; x=1691910813; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=oYOxE3I7WSLCuPblqsoW7R0tujy/ONn6EpZbmG1yrmg=; b=fr/b6RlSnzu4i9n6EvLQulC6uOEvIn/S+eg+UW05kO95GBov3YYMifUaw9+ZKpPQSe XWjddAIF0FIUfJncyt0unUH3rYMoS845w/sM8ykQAUdWm3YqvUxLQtWFEPAchsZ+1bsH 27g/GXCi0dfw7PoVgutAVZPi4EHDtSJzoKn06X8FAMxjs+07/ZeHTfDMk6wUBjXrUUE9 KSV4ItpOgNAyfG2LWCJNj7gidV9NbIVlc6PtKnz13YY0IeQ6I1dw+zj7qQqwwWWA+5sm HPTI50PIH/PMJnaVKsqjJvxCi3wRcajmrfrIhdclP6vhZD1jnZm103aNTuV3Ze9GnaRE 3Jww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689318813; x=1691910813; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oYOxE3I7WSLCuPblqsoW7R0tujy/ONn6EpZbmG1yrmg=; b=YHkf8RQISQmmVVizFtxsL9aVcrpAH2qfqScooBIoMkeOAzLq/2N+UNKjqA/YbaH/5z Dcj4pkqZlQqPCYokItlZyI+q+ny/OxYW5xErFURfadYTEsj+Luc3XpOVmctEOZmt1nEA nXA9b0oFh8uCqmzfZhqWf1jN7WFG+lp5XUdDg0YPl5o3NJNaFvoslG0416vzZwryQ6Gt +N0dhc+Sf/e2+k8BnpEGRN7diKWgFJrHBSYkTCDvKoE7wT2gjMJ68OE07IWDlXfsPioS 6VXdV0++W30GR6VMeHY7JfWDD+XoQ7cGtKBcIM0imJOMmTcBDKfzaBwW/jfdT/GEJ7l3 QEFg== X-Gm-Message-State: ABy/qLbm8toU0wroe+KCvD5Vaow/5GaknJWmoEuXRwaexOjcnDl2Pjtz 0+vXmyidlFdwf1F2U5lsfW1z0qZA/LRu37pf2NVvpJa5CP4= X-Google-Smtp-Source: APBJJlEVXb3Bz56W4XSEd6/1y2z5A7xnymSCxs6rjwWlk8fch8mKqx03YwgagNaL33kguxYXlkAZL3fkyJTpA0My+xo= X-Received: by 2002:a1f:4396:0:b0:481:2f38:f7fc with SMTP id q144-20020a1f4396000000b004812f38f7fcmr1383218vka.7.1689318812927; Fri, 14 Jul 2023 00:13:32 -0700 (PDT) MIME-Version: 1.0 References: <20230713053856.101950-1-monk.chiang@sifive.com> <20230713053856.101950-2-monk.chiang@sifive.com> In-Reply-To: <20230713053856.101950-2-monk.chiang@sifive.com> From: Kito Cheng Date: Fri, 14 Jul 2023 15:13:21 +0800 Message-ID: Subject: Re: [PATCH 2/2] RISC-V: Implement locality for __builtin_prefetch To: Monk Chiang Cc: gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE,URIBL_BLACK autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Corresponding PR on c-api-doc under discussion, so defer this until that settles down :) https://github.com/riscv-non-isa/riscv-c-api-doc/pull/46 On Thu, Jul 13, 2023 at 1:40=E2=80=AFPM Monk Chiang via Gcc-patches wrote: > > 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 mod= el) > '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 lette= r) > break; > } > > + case 'N': > + { > + const char *ntl_hint =3D NULL; > + switch (INTVAL (op)) > + { > + case 0: > + ntl_hint =3D "ntl.all"; > + break; > + case 1: > + ntl_hint =3D "ntl.pall"; > + break; > + case 2: > + ntl_hint =3D "ntl.p1"; > + break; > + } > + > + if (ntl_hint) > + asm_fprintf (file, "%s\n\t", ntl_hint); > + break; > + } > + > case 'i': > if (code !=3D 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]) !=3D 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/te= stsuite/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=3Drv64gc_zicbop_zihintntl -mabi=3Dlp64" } */ > + > +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 } } */ > -- > 2.40.1 >