DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 61RM0tg71796267
Authentication-Results: delorie.com; dmarc=pass (p=none dis=none) header.from=cygwin.com
Authentication-Results: delorie.com; spf=pass smtp.mailfrom=cygwin.com
DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 61RM0tg71796267
Authentication-Results: delorie.com;
	dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=jqQTCA91
X-Recipient: archive-cygwin@delorie.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 218134BA23FF
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
	s=default; t=1772229654;
	bh=vD1u1/KIC0hmIPqvaLs6mpSKenfkPbCNsHWaYPllkTs=;
	h=Date:To:Cc:In-Reply-To:References:Subject:List-Id:
	 List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe:
	 From:Reply-To:From;
	b=jqQTCA91Yn8HqFAk3au1vBBB+DZS4Z3HdkW9baHTvgJCI/BrjOeMguWV0RP5CBbNj
	 R9/AGiCpoH2FjxYDQxrYzy9iwn6kNjuotWKqA8esbmTTQS7Qyu5aAbnK07mjectlPY
	 I8FXLO5VxkPZXpzFvl//WP8/kAmncIfUgRBc5buA=
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 922304BA23C8
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 922304BA23C8
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1772229602; cv=none;
 b=F/mVYtFf5wtX/YVUbceWMqn1MJKpIwYvanH7RExfW9jmBfKHy2ptWisXMQmhtEX8Ybd1VwM/fm86qtwjBFKblClOzNOkk+ChU0Bp0dQvM0jjoVfP24Zx4yo6IeTlPbn1yfdeG37SbZi27sfb9+puf2smmidlU3OvXN6jpFoz0Y4=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
 t=1772229602; c=relaxed/simple;
 bh=pE7V7rGNEw8jwy8tZa6KdzTgJ2iRbBjAb2iWDBACMnU=;
 h=DKIM-Signature:Date:From:To:Message-ID:Subject:MIME-Version;
 b=Dfum16A87Gv3d2VSX3mtisFTBGAb295OnxTyqL8ts2zSjj1umSckqwO3DHbOrM0QAfCdBiCy3m1amBrbfLmqcRWnnm5PspTmtN8gUb36hkKMEeI1Zcm+sHCcqa/zczZvxtYetOrLrP3kcni3GtQds+ekhKtZ86arqq6i5EVeZk4=
ARC-Authentication-Results: i=1; server2.sourceware.org
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 922304BA23C8
Date: Fri, 27 Feb 2026 13:59:56 -0800 (PST)
To: General Cygwin discussions and problem reports <cygwin@cygwin.com>
Cc: Brian Inglis <Brian.Inglis@SystematicSW.ab.ca>
Message-ID: <2015492551.1552309.1772229596693@connect.xfinity.com>
In-Reply-To: <45c133f7-8285-4cb3-9701-2642cb76ab37@SystematicSW.ab.ca>
References: <547312365.1464244.1771958282029@connect.xfinity.com>
 <aZ7PrbisVR1R4A7v@dimstar.local.net>
 <1670201592.1489273.1772043520008@connect.xfinity.com>
 <e91d8b5b-2690-4271-aa74-e6226440e33d@SystematicSW.ab.ca>
 <1044918836.1507810.1772086967212@connect.xfinity.com>
 <1579472684.1508349.1772092747339@connect.xfinity.com>
 <aaABFf5iEowV1l7I@xps13>
 <1148572549.1808180.1772097444036@mail.yahoo.com>
 <1901597260.1508573.1772100378936@connect.xfinity.com>
 <0C965DD0-856E-41FF-B5A4-15E472292A32@unified-streaming.com>
 <483908609.1508714.1772103775739@connect.xfinity.com>
 <2346fd41-2500-0db6-5849-6788174b5a1d@cs.umass.edu>
 <1462848037.1521935.1772136952077@connect.xfinity.com>
 <399745a1-429a-ebb4-0f67-c32f6282caa6@cs.umass.edu>
 <1093316506.1533154.1772157883568@connect.xfinity.com>
 <3e0de899-a7dd-8fea-7743-10e6b05cc6b6@cs.umass.edu>
 <1990836634.1545853.1772216419837@connect.xfinity.com>
 <45c133f7-8285-4cb3-9701-2642cb76ab37@SystematicSW.ab.ca>
Subject: Re: Memmove causing program crashes, giving SIGTRAP in GDB(?)
MIME-Version: 1.0
X-Priority: 3
Importance: Normal
X-Mailer: Open-Xchange Mailer v7.10.6-Rev83
X-Originating-IP: ::ffff:50.47.202.14
X-Originating-Port: 18474
X-Originating-Client: open-xchange-appsuite
X-CMAE-Envelope: MS4xfMXm+iWtk63ZG8XjsXjz26h5qgIL+lHjB1irLiEAHG6K2Lt01AQv39iZVbcfuR+Xz3QFE2EXEmGy3NkybpIgrvc3VVbPBVwUAot8Blvxei2eKmDenRJ2
 E3/VYmncnbrJfAOKL3EOumJV9qOJvXWcLfXy/+iAwV5UIHU9Dkzz3wcAwPeP04JRg4Hd1xUueI5N4eiHWl83/yIF8LomS7rDN/P2cmykyYtAvsFOJE2DJI9J
 gjs1NWeUQ/zY0kPfRlDLse9L81vYVtSob18xO69PdUc=
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.30
Precedence: list
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
From: KENNON J CONRAD via Cygwin <cygwin@cygwin.com>
Reply-To: KENNON J CONRAD <kennonconrad@comcast.net>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: cygwin-bounces~archive-cygwin=delorie.com@cygwin.com
Sender: "Cygwin" <cygwin-bounces~archive-cygwin=delorie.com@cygwin.com>

Hi Brian,

   Thanks for replying.

   Is there a way to simplify to rep movsb (or movsw since the array is uint16_t) without using assembly code?
The code is currently 100% C and I would prefer to avoid having a mix of C and assembly code.  Also, it is unclear to me that even repsw would be faster than my bloated C code that generates assembly code that does 8 word moves in 5 instructions:

.L25:
movdqu -16(%rax), %xmm1
subq $16, %rax
movups %xmm1, 2(%rax)
cmpq %rdx, %rax
jnb .L25

   I am currently evaluating the stash and move method for the uint16_t data at the start that can't be moved in 16 byte chunks.
It uses two extra 64 bit registers but that may be better than having the compiler move addresses into registers for a memmove
call that moves the last 2 - 14 bytes (which is what the compiler does).  I didn't think of that option until looking at the
memmove assembly code.

   I thought alignment might be an issue, but noticed that the memmove assembly code does not perform alignment.  It first checks
the number of bytes to move.  If the number of bytes to move is less than 8 it jumps to the movsb section.  If the length is
8 or more it stashes the highest address bytes that need to be moved. Then it moves the data with rep movsq starting at the
beginning or near the end (for backward moves) of the array, moving the data until the remaining length is less than 8 bytes
(or 0 bytes for backward moves).  Then it uses the stashed data to finish the move.  The addresses for the rep movsq could have
any alignment that is consistent with the alignment of the data being moved.  Since this code is moving uint16_t's, the alignment is only 2 byte alignment for the rep movsq.  At least if I am reading the assembly code correctly....

Best Regards,

Kennon



  
> On 02/27/2026 11:49 AM PST Brian Inglis via Cygwin <cygwin@cygwin.com> wrote:
> 
>  
> Hi Kennon,
> 
> Some perf reports and analysis imply that backward moves (with overlap?) are no 
> faster than straight rep movsb on some CPUs, so it may be better to just 
> simplify to that, unless you want to stash the final element(s) to be moved out 
> of the way in register(s), and use multiple registers in unrolled wide moves for 
> the aligned portion?
>

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple
