From 22aa9e5fa704a37e31c70c4bf0a904ed976b0902 Mon Sep 17 00:00:00 2001
From: cshapiro <cshapiro>
Date: Tue, 1 Apr 2008 07:25:09 +0000
Subject: [PATCH] The x86 calling convention requires the direction flag to be
 cleared across function calls.  Make it so.  With this change we set the
 direction flag only when needed and clear it immediately after its use.  VOPs
 can now assume that the direction flag is always set to zero.  Also, replace
 two uses of the LODS instruction with equivalent simpler instructions.

---
 assembly/x86/assem-rtns.lisp |  8 +++++---
 compiler/x86/call.lisp       | 12 ++++++------
 compiler/x86/nlx.lisp        |  3 ++-
 compiler/x86/values.lisp     |  6 +++---
 4 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/assembly/x86/assem-rtns.lisp b/assembly/x86/assem-rtns.lisp
index e73610f09..cb4fb92d9 100644
--- a/assembly/x86/assem-rtns.lisp
+++ b/assembly/x86/assem-rtns.lisp
@@ -7,7 +7,7 @@
 ;;; Scott Fahlman or slisp-group@cs.cmu.edu.
 ;;;
 (ext:file-comment
- "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/assembly/x86/assem-rtns.lisp,v 1.6 2003/08/03 11:27:50 gerd Exp $")
+ "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/assembly/x86/assem-rtns.lisp,v 1.7 2008/04/01 07:25:08 cshapiro Exp $")
 ;;;
 ;;; **********************************************************************
 ;;; 
@@ -59,11 +59,12 @@
   ;; to iterate from larger addresses to smaller addresses.
   ;; pfw-this says copy ecx words from esi to edi counting down.
   (inst shr ecx 2)			; fixnum to raw word count
-  (inst std)				; count down
   (inst sub esi 4)			; ?
   (inst lea edi (make-ea :dword :base ebx :disp (- word-bytes)))
+  (inst std)				; count down
   (inst rep)
   (inst movs :dword)
+  (inst cld)
 
   ;; Restore the count.
   (inst mov ecx edx)
@@ -153,11 +154,12 @@
   ;; Do the blit.  Because we are coping from smaller addresses to larger
   ;; addresses, we have to start at the largest pair and work our way down.
   (inst shr ecx 2)			; fixnum to raw words
-  (inst std)				; count down
   (inst lea edi (make-ea :dword :base ebp-tn :disp (- word-bytes)))
   (inst sub esi (fixnumize 1))
+  (inst std)				; count down
   (inst rep)
   (inst movs :dword)
+  (inst cld)
 
   ;; Load the register arguments carefully.
   (loadw edx ebp-tn -1)
diff --git a/compiler/x86/call.lisp b/compiler/x86/call.lisp
index 5e88ddc85..d93387a6b 100644
--- a/compiler/x86/call.lisp
+++ b/compiler/x86/call.lisp
@@ -7,7 +7,7 @@
 ;;; Scott Fahlman or slisp-group@cs.cmu.edu.
 ;;;
 (ext:file-comment
- "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/compiler/x86/call.lisp,v 1.20 2004/10/04 02:39:18 rtoy Exp $")
+ "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/compiler/x86/call.lisp,v 1.21 2008/04/01 07:25:09 cshapiro Rel $")
 ;;;
 ;;; **********************************************************************
 ;;;
@@ -395,7 +395,6 @@
       ;; Load EAX with NIL so we can quickly store it, and set up stuff
       ;; for the loop.
       (inst mov eax-tn nil-value)
-      (inst std)
       (inst mov ecx-tn (- nvals register-arg-count))
       ;; Jump into the default loop.
       (inst jmp default-stack-vals)
@@ -431,6 +430,7 @@
       (inst std)
       (inst rep)
       (inst movs :dword)
+      (inst cld)
       ;; Restore ESI.
       (loadw esi-tn ebx-tn (- (1+ 2)))
       ;; Now we have to default the remaining args.  Find out how many.
@@ -444,8 +444,10 @@
       (inst mov eax-tn nil-value)
       ;; Do the store.
       (emit-label default-stack-vals)
+      (inst std)
       (inst rep)
       (inst stos eax-tn)
+      (inst cld)
       ;; Restore EDI, and reset the stack.
       (emit-label restore-edi)
       (loadw edi-tn ebx-tn (- (1+ 1)))
@@ -1271,7 +1273,6 @@
     
     (inst shr ecx-tn word-shift)	; make word count
     ;; And copy the args.
-    (inst cld)				; auto-inc ESI and EDI.
     (inst rep)
     (inst movs :dword)
     
@@ -1380,8 +1381,6 @@
 	 (inst lea dst (make-ea :byte :base dst :disp list-pointer-type))
 	 ;; Convert the count into a raw value, so we can use the LOOP inst.
 	 (inst shr ecx 2)
-	 ;; Set decrement mode (successive args at lower addresses)
-	 (inst std)
 	 ;; Set up the result.
 	 (move result dst)
 	 ;; Jump into the middle of the loop, 'cause that's were we want
@@ -1394,7 +1393,8 @@
 	 (storew dst dst -1 list-pointer-type)
 	 (emit-label enter)
 	 ;; Grab one value and stash it in the car of this cons.
-	 (inst lods eax)
+	 (inst mov eax (make-ea :dword :base src))
+	 (inst sub src 4)
 	 (storew eax dst 0 list-pointer-type)
 	 ;; Go back for more.
 	 (inst loop loop)
diff --git a/compiler/x86/nlx.lisp b/compiler/x86/nlx.lisp
index a9e3df240..cf1a448fc 100644
--- a/compiler/x86/nlx.lisp
+++ b/compiler/x86/nlx.lisp
@@ -7,7 +7,7 @@
 ;;; Scott Fahlman or slisp-group@cs.cmu.edu.
 ;;;
 (ext:file-comment
- "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/compiler/x86/nlx.lisp,v 1.15 2003/08/03 11:27:45 gerd Exp $")
+ "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/compiler/x86/nlx.lisp,v 1.16 2008/04/01 07:25:09 cshapiro Rel $")
 ;;;
 ;;; **********************************************************************
 ;;;
@@ -244,6 +244,7 @@
     (inst std)
     (inst rep)
     (inst movs :dword)
+    (inst cld)
 
     DONE
     ;; Reset the CSP at last moved arg.
diff --git a/compiler/x86/values.lisp b/compiler/x86/values.lisp
index e2e287513..43c0d71e3 100644
--- a/compiler/x86/values.lisp
+++ b/compiler/x86/values.lisp
@@ -7,7 +7,7 @@
 ;;; Scott Fahlman or slisp-group@cs.cmu.edu.
 ;;;
 (ext:file-comment
- "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/compiler/x86/values.lisp,v 1.5 2003/08/03 11:27:45 gerd Exp $")
+ "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/compiler/x86/values.lisp,v 1.6 2008/04/01 07:25:09 cshapiro Rel $")
 ;;;
 ;;; **********************************************************************
 ;;;
@@ -125,9 +125,9 @@
     
     (inst shr temp1 word-shift) ; convert the fixnum to a count.
     
-    (inst std) ; move down the stack as more value are copied to the bottom.
     LOOP
-    (inst lods temp)
+    (inst mov temp (make-ea :dword :base src))
+    (inst sub src 4)
     (inst push temp)
     (inst loop loop)
     
-- 
GitLab