From: zippel@fh-brandenburg.de (Roman Zippel)
Subject: L68K: optimize patches
To: linux-m68k@phil.uni-sb.de
Date: Fri, 23 May 1997 10:15:09 +0200 (MET DST)
Sender: owner-linux-m68k@phil.uni-sb.de
Reply-To: linux-m68k@phil.uni-sb.de

Hi,

The first patch saves some instruction at interrupt entry
and the other patch optimizes some memory functions.

bye, Roman


--- linux-2.1.38/arch/m68k/kernel/entry.S.old	Thu May 22 18:55:12 1997
+++ linux-2.1.38/arch/m68k/kernel/entry.S	Fri May 23 00:30:32 1997
@@ -100,21 +100,39 @@
  * the kernel doesn't mess with usp unless it needs to
  */
 #ifndef CONFIG_KGDB
-#define SAVE_ALL			\
-	clrl	%sp@-;    /* stk_adj */	\
-	movel	%d0,%sp@-; /* orig d0 */	\
-	movel	%d0,%sp@-; /* d0 */	\
-	moveml	%d1-%d5/%a0-%a1/%curptr,%sp@-;
+/*
+ * a -1 in the orig_d0 field signifies
+ * that the stack frame is NOT for syscall
+ */
+#define SAVE_ALL_INT				\
+	clrl	%sp@-;		/* stk_adj */	\
+	pea	-1:w;		/* orig d0 */	\
+	movel	%d0,%sp@-;	/* d0 */	\
+	moveml	%d1-%d5/%a0-%a1/%curptr,%sp@-
+
+#define SAVE_ALL_SYS				\
+	clrl	%sp@-;		/* stk_adj */	\
+	movel	%d0,%sp@-;	/* orig d0 */	\
+	movel	%d0,%sp@-;	/* d0 */	\
+	moveml  %d1-%d5/%a0-%a1/%curptr,%sp@-
 #else
 /* Need to save the "missing" registers for kgdb...
  */
-#define SAVE_ALL						\
-	clrl	%sp@-;    /* stk_adj */				\
-	movel	%d0,%sp@-; /* orig d0 */			\
-	movel	%d0,%sp@-; /* d0 */				\
+#define SAVE_ALL_INT						\
+	clrl	%sp@-;		/* stk_adj */			\
+	pea	-1:w;		/* orig d0 */			\
+	movel	%d0,%sp@-;	/* d0 */			\
+	moveml	%d1-%d5/%a0-%a1/%curptr,%sp@-;			\
+	moveml	%d6-%d7,SYMBOL_NAME(kgdb_registers)+GDBOFFA_D6;	\
+	moveml	%a3-%a6,SYMBOL_NAME(kgdb_registers)+GDBOFFA_A3
+
+#define SAVE_ALL_SYS						\
+	clrl	%sp@-;		/* stk_adj */			\
+	movel	%d0,%sp@-;	/* orig d0 */			\
+	movel	%d0,%sp@-;	/* d0 */			\
 	moveml	%d1-%d5/%a0-%a1/%curptr,%sp@-;			\
 	moveml	%d6-%d7,SYMBOL_NAME(kgdb_registers)+GDBOFFA_D6;	\
-	moveml	%a3-%a6,SYMBOL_NAME(kgdb_registers)+GDBOFFA_A3;
+	moveml	%a3-%a6,SYMBOL_NAME(kgdb_registers)+GDBOFFA_A3
 #endif
 
 #define RESTORE_ALL			\
@@ -146,12 +164,7 @@
 
 .text
 ENTRY(buserr)
-	SAVE_ALL
-	moveq	#-1,%d0
-	movel	%d0,%sp@(LORIG_D0)	| a -1 in the ORIG_D0 field
-					| signifies that the stack frame
-					| is NOT for syscall
-
+	SAVE_ALL_INT
 	GET_CURRENT(%d0)
 	movel	%sp,%sp@- 		| stack frame pointer argument
 	bsrl	SYMBOL_NAME(buserr_c)
@@ -159,11 +172,7 @@
 	jra	SYMBOL_NAME(ret_from_exception)
 
 ENTRY(trap)
-	SAVE_ALL
-	moveq	#-1,%d0
-	movel	%d0,%sp@(LORIG_D0)	| a -1 in the ORIG_D0 field
-					| signifies that the stack frame
-					| is NOT for syscall
+	SAVE_ALL_INT
 	GET_CURRENT(%d0)
 	movel	%sp,%sp@- 		| stack frame pointer argument
 	bsrl	SYMBOL_NAME(trap_c)
@@ -202,7 +211,7 @@
 	jra	SYMBOL_NAME(ret_from_exception)
 
 ENTRY(system_call)
-	SAVE_ALL
+	SAVE_ALL_SYS
 	movel	%d0,%d2
 
 	GET_CURRENT(%d0)
@@ -268,11 +277,7 @@
 ** This is the main interrupt handler, responsible for calling process_int()
 */
 SYMBOL_NAME_LABEL(inthandler)
-	SAVE_ALL
-	moveq	#-1,%d0
-	movel	%d0,%sp@(LORIG_D0)	| a -1 in the ORIG_D0 field
-					| signifies that the stack frame
-					| is NOT for syscall
+	SAVE_ALL_INT
 	GET_CURRENT(%d0)
 	addql	#1,SYMBOL_NAME(local_irq_count)
 					|  put exception # in d0
--- linux-2.1.38/arch/m68k/mm/memory.c.old	Thu May 22 18:45:24 1997
+++ linux-2.1.38/arch/m68k/mm/memory.c	Thu May 22 20:13:07 1997
@@ -552,39 +552,26 @@
 void cache_clear (unsigned long paddr, int len)
 {
     if (CPU_IS_040_OR_060) {
+	int tmp;
+
 	/*
 	 * cwe need special treatment for the first page, in case it
 	 * is not page-aligned.
 	 */
-	if (paddr & (PAGE_SIZE - 1)){
+	if ((tmp = -paddr & (PAGE_SIZE - 1))) {
 	    pushcl040(paddr);
-	    if (len <= PAGE_SIZE){
-		if (((paddr + len - 1) ^ paddr) & PAGE_MASK) {
-		    pushcl040(paddr + len - 1);
-		}
+	    if ((len -= tmp) <= 0)
 		return;
-	    }else{
-		len -=PAGE_SIZE;
-		paddr += PAGE_SIZE;
-	    }
+	    paddr += tmp;
 	}
-		
-	while (len > PAGE_SIZE) {
-#if 0
-	    pushcl040(paddr);
-#else
+	tmp = PAGE_SIZE;
+	while ((len -= tmp) >= 0) {
 	    clear040(paddr);
-#endif
-	    len -= PAGE_SIZE;
-	    paddr += PAGE_SIZE;
+	    paddr += tmp;
 	}
-	if (len > 0) {
+	if ((len += tmp))
+	    /* a page boundary gets crossed at the end */
 	    pushcl040(paddr);
-	    if (((paddr + len - 1) ^ paddr) & PAGE_MASK) {
-		/* a page boundary gets crossed at the end */
-		pushcl040(paddr + len - 1);
-	    }
-	}
     }
     else /* 68030 or 68020 */
 	asm volatile ("movec %/cacr,%/d0\n\t"
@@ -605,26 +592,19 @@
 void cache_push (unsigned long paddr, int len)
 {
     if (CPU_IS_040_OR_060) {
+	int tmp = PAGE_SIZE;
+
 	/*
          * on 68040 or 68060, push cache lines for pages in the range;
 	 * on the '040 this also invalidates the pushed lines, but not on
 	 * the '060!
 	 */
-	while (len > PAGE_SIZE) {
+	len += paddr & (PAGE_SIZE - 1);
+	do {
 	    pushcli040(paddr);
-	    len -= PAGE_SIZE;
-	    paddr += PAGE_SIZE;
-	    }
-	if (len > 0) {
-	    pushcli040(paddr);
-	    if (((paddr + len - 1) ^ paddr) & PAGE_MASK) {
-		/* a page boundary gets crossed at the end */
-		pushcli040(paddr + len - 1);
-		}
-	    }
-	}
-    
-    
+	    paddr += tmp;
+	} while ((len -= tmp) > 0);
+    }
     /*
      * 68030/68020 have no writeback cache. On the other hand,
      * cache_push is actually a superset of cache_clear (the lines
@@ -654,34 +634,24 @@
 void cache_push_v (unsigned long vaddr, int len)
 {
     if (CPU_IS_040) {
+	int tmp = PAGE_SIZE;
+
 	/* on 68040, push cache lines for pages in the range */
-	while (len > PAGE_SIZE) {
+	len += vaddr & (PAGE_SIZE - 1);
+	do {
 	    pushv040(vaddr);
-	    len -= PAGE_SIZE;
-	    vaddr += PAGE_SIZE;
-	    }
-	if (len > 0) {
-	    pushv040(vaddr);
-	    if (((vaddr + len - 1) ^ vaddr) & PAGE_MASK) {
-		/* a page boundary gets crossed at the end */
-		pushv040(vaddr + len - 1);
-		}
-	    }
-	}
+	    vaddr += tmp;
+	} while ((len -= tmp) > 0);
+    }
     else if (CPU_IS_060) {
+	int tmp = PAGE_SIZE;
+
 	/* on 68040, push cache lines for pages in the range */
-	while (len > PAGE_SIZE) {
+	len += vaddr & (PAGE_SIZE - 1);
+	do {
 	    pushv060(vaddr);
-	    len -= PAGE_SIZE;
-	    vaddr += PAGE_SIZE;
-	}
-	if (len > 0) {
-	    pushv060(vaddr);
-	    if (((vaddr + len - 1) ^ vaddr) & PAGE_MASK) {
-		/* a page boundary gets crossed at the end */
-		pushv060(vaddr + len - 1);
-	    }
-	}
+	    vaddr += tmp;
+	} while ((len -= tmp) > 0);
     }
     /* 68030/68020 have no writeback cache; still need to clear icache. */
     else /* 68030 or 68020 */
