From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from aye.elm.relay.mailchannels.net (aye.elm.relay.mailchannels.net [23.83.212.6]) by sourceware.org (Postfix) with ESMTPS id AA0A0389942E for ; Mon, 9 May 2022 13:35:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AA0A0389942E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gotplt.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 3A7F5761C58; Mon, 9 May 2022 13:35:14 +0000 (UTC) Received: from pdx1-sub0-mail-a305.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id CFD0D761DCC; Mon, 9 May 2022 13:35:13 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1652103313; a=rsa-sha256; cv=none; b=IWbK3R5lTTunNtPPiOZy7j8xsoTPOYKCAZZBZo43aroMdd7ZHDDp3zdVsSYfT9YM+x04zK eNj5/O5tUFGHu0ZsIFfbSGlC3IFESWIuA/sLjExH5U54zJrICVu4KmYVngZMBOf5OxDQ5c 7SVh+C5IqM6J1VKf45zRv+lPHz340pQHMGosCfh3h3GYIV1PVPTTZR+EmGfVf2Ig2PcD2p OkZaNk1aQ8nfL9EYaC47tcAsDdlNRrP1TxivC7P36zjRaSu3a+HzulYv+ll45DTKsFrM2R Vw5khvwXBGwYmM1Y2zsE2zr//NKED90iTFYoJ4DC+6MQ98oIGsg786hBaerBaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1652103313; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=2gB4JvMd+KmtUDO+UL5N4PYLyqhcCUGuggvs/u+OugE=; b=Zz4I7w/RJP3QOiICE03AkDSYd7YRr32XPovvmq370Az2M49yo1tL7RoRzGUZfN14ozqjhQ mvAs5hudn32TK8bPvyDljmTN/YdVb029awrPvAHjfIdKMMcgM+swDYdh7iRi1SMzff/CtN TssYFdoVnw6HKom/eCBgedV/ZxAt4F43LZ1Oj3U0UTJmf/boRMMjgD61SXf/XBHq18RBms P3DnlQd0AEsP9QYTSQVWa6aBOyIC+gKFkzgq2+e4q6Ky9sHqtpb1ioNBXNucSuTIg2hNw1 XBPtu5NV6YQXzWYTtFMJRaMVLQ6n8k9iWiiDtSpLat7TSIYB5lOKd4Gbm1lAqg== ARC-Authentication-Results: i=1; rspamd-c4dc5ff8f-k7bkv; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Arithmetic-Abiding: 195024776d283082_1652103314082_815689792 X-MC-Loop-Signature: 1652103314081:2191081412 X-MC-Ingress-Time: 1652103314081 Received: from pdx1-sub0-mail-a305.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.116.106.76 (trex/6.7.1); Mon, 09 May 2022 13:35:14 +0000 Received: from [192.168.1.174] (unknown [1.186.121.104]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a305.dreamhost.com (Postfix) with ESMTPSA id 4KxhxX4g60z1Nj; Mon, 9 May 2022 06:35:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1652103313; bh=2gB4JvMd+KmtUDO+UL5N4PYLyqhcCUGuggvs/u+OugE=; h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding; b=LiJZO7msQBJcRD0NheYk/mYrEGB/hLVdTASq1QZUZX3VFA6vzVLJ6q1PQwbESkiFf ZQ81vVabveMlRtnv81dnIpgO1J3GN9TZfjDqiwkuoXQhtNFq8bnqlGvS7iIgAS3CSm z+d6OyAQOSbS01zOHAmxWVEu2A0SLzKtQncf0mI9i88jm8lw19iJBdrhfDepWlAtAr eiEPijmy+qoW8W5s2FXYwvux3sg2CkkTtxmC9kb9HzVjbQhemuOc56rwEYHAn1rjis rLYUvUVKQZ2wxKdhZywohZPmb2Ox8UuamtG6P1fxUAjewbNwOndBzfD2LWls+lzIxA cCMCqbjEu+YQw== Message-ID: Date: Mon, 9 May 2022 19:05:08 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [PATCH v2] wcrtomb: Make behavior POSIX compliant Content-Language: en-US To: Adhemerval Zanella , libc-alpha@sourceware.org References: <20220505184348.3357550-3-siddhesh@sourceware.org> <20220506140415.1275807-1-siddhesh@sourceware.org> <1eba6382-8db1-d269-2ed1-a2c408e5be33@linaro.org> From: Siddhesh Poyarekar In-Reply-To: <1eba6382-8db1-d269-2ed1-a2c408e5be33@linaro.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3030.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_SBL, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 May 2022 13:35:17 -0000 On 09/05/2022 18:52, Adhemerval Zanella via Libc-alpha wrote: > > > On 06/05/2022 11:04, Siddhesh Poyarekar via Libc-alpha wrote: > >> + >> + if (__glibc_likely (result < 2)) >> + *s = *buf; >> + else if (__glibc_likely (result == 2)) >> + memcpy (s, buf, result); /* Help the compiler. */ >> + else >> + memcpy (s, buf, result); >> + } >> + } > > I am not following how this help the compiler here, it just duplicates the > same memcpy call. > It should be able to inline the first memcpy call into a copy instruction sequence. With just an `else`, result may be 2 or more, so the compiler doesn't have enough information to do any inlining. However, it just occurred to me that maybe something like this: if (result <= MB_LEN_MAX) memcpy (s, buf, result); else __builtin_unreachable (); will likely produce an always avoid the memcpy call and generate an inlined sequence. I'll test that and repost. Thanks for making me think about this a bit more. I'll also update the manual based on the discussion in the weekly call to make the blurb more backport-friendly. Thanks, Siddhesh