www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1999/05/24/10:21:30

Message-Id: <m10lvjs-000bQEC@ice.inti.gov.ar>
Date: Mon, 24 May 1999 11:30:00 -0300 (ART)
To: djgpp-workers AT delorie DOT com
Subject: memmove slow
From: salvador AT inti DOT gov DOT ar
Reply-To: djgpp-workers AT delorie DOT com

Hi All!

  This was discussed months ago, perhaps even years. The memmove function is
unnecesary slow.
  The code provided here is twice faster in average at least in my system.
  Is that reliable? that's the code I used in the editor for a long time and
that Robert uses in RHIDE so I think it works very well.
  If for any reason the code is not included in 2.03 PLEASE tell me and
schedule it for next reales, I think it wasn't included in 2.01 because it
wasn't enough tested, but it was a long time ago.

SET
--------------djmdr.s-------------
--- src/libc/pc_hw/mem/djmdr.S~	Sun May 23 15:26:06 1999
+++ src/libc/pc_hw/mem/djmdr.S	Sun May 23 15:12:42 1999
@@ -0,0 +1,57 @@
+/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
+/* Modified by SET to copy in reverse order */
+# This routine moves %ecx bytes from %ds:%esi to %es:%edi.  It clobbers
+# %eax, %ecx, %esi, %edi, and eflags. 
+
+	.file "djmdr.s"
+	.text
+	.align 4
+	.globl ___dj_movedata_rev
+___dj_movedata_rev:
+	std
+        # Add the counter to the index
+        addl    %ecx,%edi
+        addl    %ecx,%esi
+        decl    %esi
+        decl    %edi
+
+	cmpl	$15,%ecx
+	jle	small_move
+	jmp	mod_4_check
+	
+	# Transfer bytes until either %esi or %edi is aligned % 3
+align_mod_4:	
+	movsb
+	decl	%ecx
+mod_4_check:
+        movl    %esi,%eax
+        andl    $3,%eax
+	cmpl	$3,%eax
+	jz big_move
+        movl    %edi,%eax
+        andl    $3,%eax
+	cmpl	$3,%eax
+	jnz	align_mod_4
+
+big_move:
+	movb	%cl,%al	 # We will store leftover count in %al
+	shrl	$2,%ecx
+	andb	$3,%al
+        # Now retrocess the index 3 positions
+        subl    $3,%edi
+        subl    $3,%esi
+	rep
+	movsl
+
+	# %ecx known to be zero here, so insert the leftover count in %al
+	movb	%al,%cl
+
+        # advance the index by 3
+        addl    $3,%edi
+        addl    $3,%esi
+
+small_move:
+	rep
+	movsb
+	ret
+
----------------------------------------
-------------memmove.S------------------
--- src/libc/ansi/string/memmove.S~	Tue Mar 28 04:14:46 1995
+++ src/libc/ansi/string/memmove.S	Sun May 23 15:12:50 1999
@@ -10,18 +10,14 @@
 	movl	12(%ebp),%esi
 	movl	16(%ebp),%ecx
 	jecxz	L2
-	cld
+
 	cmpl	%esi,%edi
 	jb	L3
 
-	std
-	addl	%ecx,%esi
-	addl	%ecx,%edi
-	decl	%esi
-	decl	%edi
+        call    ___dj_movedata_rev
+        jmp     L2
 L3:
-	rep
-	movsb
+	call    ___dj_movedata
 
 L2:
 	cld
-----------------------------------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019