From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-01-1.mymagenta.at (mail-01-1.mymagenta.at [80.109.253.246]) by sourceware.org (Postfix) with ESMTPS id 740143858412 for ; Mon, 27 Nov 2023 19:28:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 740143858412 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=inode.at Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=inode.at ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 740143858412 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=80.109.253.246 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701113336; cv=none; b=Du0C3YGj0crCewKwhPeWdYKSie2ayeePfbAELXELpNELRBOQYxPF/Gydp1vTSb5miASWEq3q4tZVzzCpvCD8esTawMC5MmjFLhn2g2FcQsRgNTTQXA8yL4UMLnBTTPh0dRmDSWJhbSY7204FvnugaTjKDzbuvlmDMs4/WoD0VeA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701113336; c=relaxed/simple; bh=Eo3vmcwhhMM0Ws9GDk65HZhrqdXpMyJ1eNgHjHMDpOU=; h=DKIM-Signature:Message-ID:Date:MIME-Version:From:Subject:To; b=cDwKeGJy7D51+hJ+yIq9/lJdgd+M0ajcChM4B1mIrDx7xMtsr0ryjaO1MNobkN1wmrRqOyZDZfQyyyXogheTAuSzFF+OyhSJzdcR6N2NTVDBZNvMfHeWqnffX7BG3gBX6nXvpnwAwGgdGiTATn8Yz7DGF/icV+12XXPKNWvymhQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [192.168.232.139] (helo=ren-mail-psmtp-mg53.mail.mymagenta.at) by mail-01.mymagenta.at with esmtp (Exim 4.93) (envelope-from ) id 1r7hHj-0083nx-Rx for libc-alpha@sourceware.org; Mon, 27 Nov 2023 20:28:47 +0100 Received: from [192.168.178.21] ([85.127.183.35]) by ren-mail-psmtp-mg53.mail.mymagenta.at with ESMTPA id 7hHdrApkZFpr27hHjrapvj; Mon, 27 Nov 2023 20:28:47 +0100 X-Env-Mailfrom: aaron_ng@inode.at X-Env-Rcptto: libc-alpha@sourceware.org X-SourceIP: 85.127.183.35 X-CNFS-Analysis: v=2.4 cv=WIoc4lgR c=1 sm=1 tr=0 ts=6564edef a=f73slw0KVQjQTfylLr5q3g==:117 a=f73slw0KVQjQTfylLr5q3g==:17 a=IkcTkHD0fZMA:10 a=CCpqsmhAAAAA:8 a=EPagQJhnlChuzncXKC4A:9 a=QEXdDO2ut3YA:10 a=fTe1n_ifgx4A:10 a=ul9cdbp4aOFLsgKbc677:22 X-Authenticated-Sender: aaron_ng@inode.at DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=inode.at; s=201801custpemceu; t=1701113327; bh=Eo3vmcwhhMM0Ws9GDk65HZhrqdXpMyJ1eNgHjHMDpOU=; h=Date:From:Subject:To; b=An770EgBp+T8Mht3O7bYcnSgNCEq7g+XtunAw5U1kX7EKmGHnCJpLcwSS2fyVRDf3 hKdaik9LPGIfs7czisFF4kFCtfQiKX1MJ6Yu+rFxtfe13eIcKAftqkm+ffTK3Z5pAL kxK16ic4eqUnpDuTlyfyUAitB8SWNz0YzqI/Bc54sb8rVuOFmIjd4EJ37UviZXTSKM FktxolQqUYe1o4V8U1KRTqyV0BnLjzeMRTS+9etszW5ZYHZWRH5sZmSokwWxyqHR2v szyu0B93hZfUtnEpKMr+pi4ZkbwZAfmiMPw0JmJjO1pZfatOZhwvLRaJhe3RNhH7va 4FVqqNkh+/GJQ== Message-ID: <626f0faf-dc80-4147-8463-cd2f5905c038@inode.at> Date: Mon, 27 Nov 2023 20:28:44 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US, de-DE From: Aaron Peter Bachmann Subject: Support for memcpy with equal source and destination To: libc-alpha@sourceware.org Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4xfCrfrD9+1xjuUDHSMYxUbm2v4MCYM6GDHx09hKUrgKDnixjF3o0e+ibwgqG3dYEiCqM3aqfciAQsfU+Fnz75sZz3yocdmQYzHeRCc2VNJtPG0EuyM0LT bm8w35y9BpOxHEUHbtcO5jRtIkf8p4uq/8GcrTp9x7GsMvjLIfSkLEZZeGZLUBNXrmRr8QrzdLIoryT3D+XbntI8oBAa230ejow= X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,JMQ_SPF_NEUTRAL,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE 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: In response to https://sourceware.org/pipermail/libc-alpha/2023-November/152961.html (Since I am not subscribed, I cannot answer directly.) >Here's a sample implementation. When dest == src this function doesn't >dereference either pointer, and this satisfies the C standard's rules >for 'restrict'. I interpret the C-std differently. Unfortunately, I am not entirely sure my interpretation is correct. > > #include > I think, the function signature is a promise that *dest and *src do not overlap. This implies dest != src. > void * > memcpy (void *restrict dest, void const *restrict src, size_t n) > { The comparison (dest != src) does not make dest based on src. The comparison (dest != src) does not make src based on dest. Thus, a conforming compiler could just remove the test which seems to be true always according to the function signature. gcc and clang do not do so presently. > if (dest != src) > { > char *d = dest; > char const *s = src; > for (; n != 0; n--) > *d++ = *s++; > } > return dest; > } Regards, Aaron Peter Bachmann