From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by sourceware.org (Postfix) with ESMTPS id 90C413858D32 for ; Mon, 14 Nov 2022 21:07:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 90C413858D32 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu Received: by mail-pg1-x536.google.com with SMTP id n17so3690346pgh.9 for ; Mon, 14 Nov 2022 13:07:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=YdWFzFi5rqn7RDbv7149n8cIWyOubuRp19Z3ddE2b4k=; b=GJFIGYuIlKXIXFmUxamm5jApCik3jPcJQOqU3eG0UaS/9e0+W3S84HCAnLv+aRU5Cv beZiKapK+Tr2023PUDEdOAAv78ScjnFHAzuJufTDN2hzpDGufK7dd4CHY2Xn5acK6WbA eM6PQbwRwLgP27RFsWZBUaoakSfHGFozx97JV/mgzZMGUbLM5/W6d7929J5dVd0FVL2F eKuwIhCUy48pE5WnhaCQN6jddVQQO31z3VGWWKF9ifottQzl0ed177tlnWVlIq9LStjz SHErkMyQwDjkjscM6IpMuGNeJfEVbsu+QtogernjgtVxKY4aaDyWRFvSBnwYZ4lIIfmX T9GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=YdWFzFi5rqn7RDbv7149n8cIWyOubuRp19Z3ddE2b4k=; b=d3I6fzXaKOBg6MI5miAAMBr7wpkR/9zl+FkyC6NaqNJFInux0Q359Ls5AhmSP80DmG zxi8Ar5p8eg7qi6RKWtwd6psgBNbZpAAMH8gMuEVi2vYZTO94LbYEQoXM++siadfGiK6 ROdvqQO5rjErIlZBm5f1XnXKERnj/3tzF0OguYph0pbm/AEQu5AJQWdUDVspxGxMb6Ym wKDZItUCz3v4YhKlUTwcMjNNXtADHlqxzvvJzGni03uyL7Z0f86qg5oAjCFs0mV+yxer 3C4LFivjE3T4ArYhR2rH/ybT8Aj5ZKjGUzNpBHal8pEmYZGWithzZzKTy4WJcnNW46TI L87g== X-Gm-Message-State: ANoB5pnbUVTPwPBTq2oxIHQbCyowyzyNJuEy9hS8wYr0y3oRT9khF4ja Z29kYmV9amk/6AkxeEn0jVFVHBKJV+4ePErjoS1MDA== X-Google-Smtp-Source: AA0mqf6fh20l0ogDgPjVJSG0KG1UZzmg8OZS13eXgtuufOySsOCVHjOPtUEGS8UQmMfC1SGYCO/O/bgr4GWEWnmWzt8= X-Received: by 2002:a05:6a00:d78:b0:56c:8dbc:f83e with SMTP id n56-20020a056a000d7800b0056c8dbcf83emr15280692pfv.41.1668460075594; Mon, 14 Nov 2022 13:07:55 -0800 (PST) MIME-Version: 1.0 References: <20221113230521.712693-1-christoph.muellner@vrull.eu> <20221113230521.712693-7-christoph.muellner@vrull.eu> <62e4fab8-5c8b-2021-e0f3-060130c80039@gmail.com> In-Reply-To: <62e4fab8-5c8b-2021-e0f3-060130c80039@gmail.com> From: =?UTF-8?Q?Christoph_M=C3=BCllner?= Date: Mon, 14 Nov 2022 22:07:41 +0100 Message-ID: Subject: Re: [PATCH 6/7] riscv: Add support for strlen inline expansion To: Jeff Law Cc: gcc-patches@gcc.gnu.org, Kito Cheng , Jim Wilson , Palmer Dabbelt , Andrew Waterman , Philipp Tomsich , Vineet Gupta Content-Type: multipart/alternative; boundary="00000000000020cdf705ed74a2a9" X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,HTML_MESSAGE,JMQ_SPF_NEUTRAL,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP 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: --00000000000020cdf705ed74a2a9 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Nov 14, 2022 at 7:17 PM Jeff Law wrote: > > On 11/13/22 16:05, Christoph Muellner wrote: > > From: Christoph M=C3=BCllner > > > > This patch implements the expansion of the strlen builtin > > using Zbb instructions (if available) for aligned strings > > using the following sequence: > > > > li a3,-1 > > addi a4,a0,8 > > .L2: ld a5,0(a0) > > addi a0,a0,8 > > orc.b a5,a5 > > beq a5,a3,6 <.L2> > > not a5,a5 > > ctz a5,a5 > > srli a5,a5,0x3 > > add a0,a0,a5 > > sub a0,a0,a4 > > > > This allows to inline calls to strlen(), with optimized code for > > determining the length of a string. > > > > gcc/ChangeLog: > > > > * config/riscv/riscv-protos.h (riscv_expand_strlen): New > > prototype. > > * config/riscv/riscv-string.cc (riscv_emit_unlikely_jump): New > > function. > > (GEN_EMIT_HELPER2): New helper macro. > > (GEN_EMIT_HELPER3): New helper macro. > > (do_load_from_addr): New helper function. > > (riscv_expand_strlen_zbb): New function. > > (riscv_expand_strlen): New function. > > * config/riscv/riscv.md (strlen): Invoke expansion > > functions for strlen. > > > > > > +extern bool riscv_expand_strlen (rtx[]); > > Consider adding the number of elements in the RTX array here. Martin S's > work from a little while ago will make use of it to try and catch > over-reads and over-writes if the data is available. > Done. > > > > > > /* Information about one CPU we know about. */ > > struct riscv_cpu_info { > > diff --git a/gcc/config/riscv/riscv-string.cc > b/gcc/config/riscv/riscv-string.cc > > index 1137df475be..bf96522b608 100644 > > --- a/gcc/config/riscv/riscv-string.cc > > +++ b/gcc/config/riscv/riscv-string.cc > > @@ -38,6 +38,81 @@ > > #include "predict.h" > > #include "optabs.h" > > > > +/* Emit unlikely jump instruction. */ > > + > > +static rtx_insn * > > +riscv_emit_unlikely_jump (rtx insn) > > +{ > > + rtx_insn *jump =3D emit_jump_insn (insn); > > + add_reg_br_prob_note (jump, profile_probability::very_unlikely ()); > > + return jump; > > +} > > I was a bit surprised that we didn't have this as a generic routine. > Consider adding this to emit-rtl.cc along with its companion > emit_likely_jump. Not a requirement to move forward, but it seems like > the right thing to do. > I created both and called them emit_[un]likely_jump_insn() to match emit_jump_insn(). > > > > > > + > > +/* Emit proper instruction depending on type of dest. */ > > s/type/mode/ > Done. > > > > > + > > +/* Emit proper instruction depending on type of dest. */ > > s/type/mode/ > Done. > > > You probably want to undefine GEN_EMIT_HELPER once you're done when > them. That's become fairly standard practice for these kind of helper > macros. > Done. > > OK with the nits fixed. Your call on whether or not to move the > implementation of emit_likely_jump and emit_unlikely_jump into emit-rtl.c= c. > I've made all the requested and suggested changes and rested again. Thanks! > > > Jeff > > > --00000000000020cdf705ed74a2a9--