From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by sourceware.org (Postfix) with ESMTPS id 7ED8838518BA for ; Mon, 14 Nov 2022 18:17:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7ED8838518BA 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-pl1-x636.google.com with SMTP id p12so10799763plq.4 for ; Mon, 14 Nov 2022 10:17:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=MdGaj1YQqK22J4Lu0YSF0pJxdKxCvyqdc/x86zAdzN8=; b=RmPbKfCWaznBFgE8U9kVSndqKtepqG3P1o/sNXOpq/7mkX1BS4e61EPf+ckB9OiGXP b+heKPtSpbO7oNeOwWx/dQR33hOzlGgTA0ehGy7n1AnGxOZdUYl3dEr6lQCbV4xZkZvW MQmgIQeLIGIZjPR/8+DmAa7V04Cp9S/25uUJ6XcfonAy1agEtQ0ccV6+NnW5Q0mbWptX UqEJTtiyOkKJrmho2HkCTom8jlZhQUzrNrvWnUaWfbc055/ZQw3vedD6f36P06tt6ZSz AobpIMklfHC1i8Q7KCeK5QpWY7w3vdFW80mY81iXIYuS5vgdIFxuN5FLn8AfrhGgE11n LN0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=MdGaj1YQqK22J4Lu0YSF0pJxdKxCvyqdc/x86zAdzN8=; b=grS3yYv+sHpLn6/cQOqT0q7Ky6OR6VhMCKLc1wrTf2bJcEx3dYKOpnfvAEKRMXwaMX xJCiLog/Bvvkps/jvpY3ij/2Ti8bom2cy9UfoNYvxqnd1c7qdcoRWD+R9JzkNhgPtSfi R3eDKUgSqq0sO/QfModHV+gNJ48iRMLS9So5gOXWyYH+ciaHWxYdaL/VpGr6EF1J0xp3 oG4IyjSMAI0n/VSUII5PipTcc1TxPx47V4ffOoIvCYqAOqRjENGv+X8g7F4egdaE518w f6B3f2F3r4CVOoNw+lKs+qZ+oU3eXPn2ESsKnHol7e5lQP2YMIADy6eMbLwJhtnQVSXm x0Hw== X-Gm-Message-State: ANoB5pmeez9lx127b6A4UYazs3jK/hmdnkKx23YKBqFi/x/7SY8YxwSI itwwD4qIJAJjzFxaVEs2VLs= X-Google-Smtp-Source: AA0mqf6CP//q1yQPyM1NDNg5fIkMA3pcF8EdaHnyXsVIDQMQV1qNR+BaCf7vDrZ5AQpd9gffKEMg6w== X-Received: by 2002:a17:90a:4594:b0:217:e054:9ac8 with SMTP id v20-20020a17090a459400b00217e0549ac8mr15029331pjg.246.1668449856382; Mon, 14 Nov 2022 10:17:36 -0800 (PST) Received: from ?IPV6:2601:681:8600:13d0::f0a? ([2601:681:8600:13d0::f0a]) by smtp.gmail.com with ESMTPSA id a9-20020a170902710900b00183c6784704sm7763544pll.291.2022.11.14.10.17.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 14 Nov 2022 10:17:35 -0800 (PST) Message-ID: <62e4fab8-5c8b-2021-e0f3-060130c80039@gmail.com> Date: Mon, 14 Nov 2022 11:17:33 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.1 Subject: Re: [PATCH 6/7] riscv: Add support for strlen inline expansion Content-Language: en-US To: Christoph Muellner , gcc-patches@gcc.gnu.org, Kito Cheng , Jim Wilson , Palmer Dabbelt , Andrew Waterman , Philipp Tomsich , Vineet Gupta References: <20221113230521.712693-1-christoph.muellner@vrull.eu> <20221113230521.712693-7-christoph.muellner@vrull.eu> From: Jeff Law In-Reply-To: <20221113230521.712693-7-christoph.muellner@vrull.eu> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_MANYTO,NICE_REPLY_A,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: On 11/13/22 16:05, Christoph Muellner wrote: > From: Christoph Müllner > > 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. > > /* 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 = 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. > + > +/* Emit proper instruction depending on type of dest. */ s/type/mode/ > + > +/* Emit proper instruction depending on type of dest. */ s/type/mode/ 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. 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.cc. Jeff