From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oo1-xc36.google.com (mail-oo1-xc36.google.com [IPv6:2607:f8b0:4864:20::c36]) by sourceware.org (Postfix) with ESMTPS id 7BDE53858D1E for ; Mon, 6 Feb 2023 14:01:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7BDE53858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oo1-xc36.google.com with SMTP id c29-20020a4ad21d000000b00517a55a78d4so1106833oos.12 for ; Mon, 06 Feb 2023 06:01:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=MRr+r1NbMyB5QiC9PuaohpMiick/uBM8o7xkxvLJ9DU=; b=NjJUN4cH2ZyK67l2roqslaWyxRyOwffYy+4+O/ZFyC2at4NAmlmMu26qSYXbNHSkkd Z+Uk4IGVqAGymmZVMivtDrKQojXmkKLq/VQhI/6AaZb+6yTv1CmRSb1HyI7H9Emq0/Tp oFgvyVWv784owG+TZtOAU1mYFsk/7YbK4u/Rc4/7+0CoqvXFAxhnN1OgVRLWy++4Fllp feMTslarpui6oL2LZ80C0MoC/q8zSrb+gl7zDqBaajI8W7ed3N6NJw4EysaKuBVHnsBM J0fG93FoMHQZrRMhpOV0+dDc49+vPBorxG65MRVGmA3D+TX2rMQ4RCEH9noLx4kdl0Eg e/4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization: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=MRr+r1NbMyB5QiC9PuaohpMiick/uBM8o7xkxvLJ9DU=; b=wp443VHnIK/W+EE/KLrF9mMX7wvz5e8dFbBxS2WZAcwrNYXqR3VbV6QUsh03Z7nhbB vTXFJgvdgQIojcZmNBP790tfoJYrnkGdC+UE3DPhAVZp+fnhLSUvq2jASWjGlUed2DVv XXFS4LCgEwMcDUMafm4AozR+vxD9leRDgDsRSWJc5gFhp5YkvwhOJMj4e7Wt7wg4emam s7EYSA5koYyLnHRhTf3vGtvdDthhqnYPIgFON8jLiDM7idmUN4+d4/Lkstp7t3GpBVN0 9gNoF2rIwl0PGCjTIwyR6l9T3YumeNSR8McvX2SuLhWYdkPsUmCkZKzs8vnBz3EhOZf+ D45A== X-Gm-Message-State: AO0yUKV2hdq/b7HoHv0xsJpZEd8Jy4KY6VtAjB5cBSjsW0NwX+a3MMBX vv61ovXMa+7yQmWznDydd6FjbA== X-Google-Smtp-Source: AK7set9s/ZwkzpKsoBiPZHt/D731xUOXTr9bc6zYYujvub0CwSrykScSaSw54DdhJbg0JfTrMkQfCw== X-Received: by 2002:a4a:c80f:0:b0:517:98b6:b08b with SMTP id s15-20020a4ac80f000000b0051798b6b08bmr9262200ooq.2.1675692068450; Mon, 06 Feb 2023 06:01:08 -0800 (PST) Received: from ?IPV6:2804:1b3:a7c2:8ced:8a3:838:7129:e0bf? ([2804:1b3:a7c2:8ced:8a3:838:7129:e0bf]) by smtp.gmail.com with ESMTPSA id g17-20020a4adc91000000b00517bfd71ce1sm4607834oou.9.2023.02.06.06.01.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 06 Feb 2023 06:01:07 -0800 (PST) Message-ID: Date: Mon, 6 Feb 2023 11:01:04 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: [PATCH v12 14/31] string: Improve generic strrchr with memrchr and strlen Content-Language: en-US To: Richard Henderson , libc-alpha@sourceware.org, Jeff Law , Xi Ruoyao , Noah Goldstein References: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> <20230202181149.2181553-15-adhemerval.zanella@linaro.org> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,URIBL_BLACK autolearn=no 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 04/02/23 00:06, Richard Henderson wrote: > On 2/2/23 08:11, Adhemerval Zanella wrote: >> Now that both strlen and memrchr have word vectorized implementation, >> it should be faster to implement strrchr based on memrchr over the >> string length instead of calling strchr on a loop. >> >> Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc-linux-gnu, >> and powerpc64-linux-gnu by removing the arch-specific assembly >> implementation and disabling multi-arch (it covers both LE and BE >> for 64 and 32 bits). >> --- >>   string/strrchr.c | 18 +----------------- >>   1 file changed, 1 insertion(+), 17 deletions(-) > > memrchr needs libc_hidden_builtin_proto.  On riscv64: > >    c:   00000097                auipc   ra,0x0 >                         c: R_RISCV_CALL __GI_strlen >                         c: R_RISCV_RELAX        *ABS* >   10:   000080e7                jalr    ra # c <__GI_strrchr+0xc> > ... >   24:   00000317                auipc   t1,0x0 >                         24: R_RISCV_CALL_PLT    __memrchr >                         24: R_RISCV_RELAX       *ABS* >   28:   00030067                jr      t1 # 24 <.LVL2+0x8> > > > r~ Similar to strchr [1], static linker ends up creating the expected local call: $ riscv64-glibc-linux-gnu-objdump -dr libc.so [...] 0000000000088f5c : 88f5c: 7179 addi sp,sp,-48 88f5e: e84a sd s2,16(sp) 88f60: 000e7917 auipc s2,0xe7 88f64: 73893903 ld s2,1848(s2) # 170698 <__stack_chk_guard@GLIBC_2.27> 88f68: 00093783 ld a5,0(s2) [...] 88f9a: 6145 addi sp,sp,48 88f9c: c70fd06f j 8640c 88fa0: 193500ef jal ra,d9932 <__stack_chk_fail> [...] But I agree that we should change to have the libc_hidden_builin_proto in this case. I will send a patch to fix it. [1] https://sourceware.org/pipermail/libc-alpha/2023-February/145322.html