10% speedup in to:do:
authorClaus Gittinger <cg@exept.de>
Wed, 18 Jun 1997 10:42:02 +0200
changeset 2693 8ffe0f4374d6
parent 2692 281e46d29478
child 2694 46ba8cbdc013
10% speedup in to:do:
SmallInt.st
SmallInteger.st
--- a/SmallInt.st	Tue Jun 17 18:06:04 1997 +0200
+++ b/SmallInt.st	Wed Jun 18 10:42:02 1997 +0200
@@ -1387,26 +1387,8 @@
 #ifdef WIN32
 # undef UNROLL_LOOPS
 #endif
+
 #ifdef UNROLL_LOOPS
-			if (0) {
-
-			    interrupted0:
-						__interruptL(@line); goto continue0;
-			    interrupted1:
-						__interruptL(@line); goto continue1;
-			    interrupted2:
-						__interruptL(@line); goto continue2;
-			    interrupted3:
-						__interruptL(@line); goto continue3;
-			    interrupted4:
-						__interruptL(@line); goto continue4;
-			    interrupted5:
-						__interruptL(@line); goto continue5;
-			    interrupted6:
-						__interruptL(@line); goto continue6;
-			    interrupted7:
-						__interruptL(@line); goto continue7;
-			}
 
 			/*
 			 * you are not supposed to program like this - I know what I do
@@ -1445,6 +1427,27 @@
 			} while(--tmp);
 
 			RETURN (self);
+#ifdef UNROLL_LOOPS
+			if (0) {
+
+			    interrupted0:
+						__interruptL(@line); goto continue0;
+			    interrupted1:
+						__interruptL(@line); goto continue1;
+			    interrupted2:
+						__interruptL(@line); goto continue2;
+			    interrupted3:
+						__interruptL(@line); goto continue3;
+			    interrupted4:
+						__interruptL(@line); goto continue4;
+			    interrupted5:
+						__interruptL(@line); goto continue5;
+			    interrupted6:
+						__interruptL(@line); goto continue6;
+			    interrupted7:
+						__interruptL(@line); goto continue7;
+			}
+#endif /* UNROLL_LOOPS */
 		    }
 		}
 	    }
@@ -1782,11 +1785,104 @@
 			     */
 #ifdef UNROLL_LOOPS
 			    /*
+			     * The following code is designed to run as fast as possible;
+			     *  - taken branches only if interrupts are pending
+			     *  - only forward branches (which are usually predicted as not taken)
+			     *  - unrolled the loop
+			     *
 			     * you are not supposed to program like this - I know what I do
 			     */
+# if TAG_INT==1
+			    int t8 = (int)(__MKSMALLINT(tmp+8));
+			    tmp = (int)(__MKSMALLINT(tmp));
+			    final = (int)(__MKSMALLINT(final));
+# else
 			    int t8 = tmp+8;
+# endif
 
 			    for (;;) {
+
+				while (t8 <= final) {
+# if TAG_INT==1
+				    t8 += (int)(__MASKSMALLINT(8));
+# else
+				    t8 += 8;
+# endif
+				    if (InterruptPending != nil) goto interrupted0;
+	continue0:
+# if TAG_INT==1
+				    (*codeVal)(BLOCK_ARG, tmp);
+# else
+				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp));
+# endif
+				    if (InterruptPending != nil) goto interrupted1;
+	continue1:
+# if TAG_INT==1
+				    (*codeVal)(BLOCK_ARG, tmp+(int)(__MASKSMALLINT(1)) );
+# else
+				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+1));
+# endif
+				    if (InterruptPending != nil) goto interrupted2;
+	continue2:
+# if TAG_INT==1
+				    (*codeVal)(BLOCK_ARG, tmp+(int)(__MASKSMALLINT(2)) );
+# else
+				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+2));
+# endif
+				    if (InterruptPending != nil) goto interrupted3;
+	continue3:
+# if TAG_INT==1
+				    (*codeVal)(BLOCK_ARG, tmp+(int)(__MASKSMALLINT(3)) );
+# else
+				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+3));
+# endif
+				    if (InterruptPending != nil) goto interrupted4;
+	continue4:
+# if TAG_INT==1
+				    (*codeVal)(BLOCK_ARG, tmp+(int)(__MASKSMALLINT(4)) );
+# else
+				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+4));
+# endif
+				    if (InterruptPending != nil) goto interrupted5;
+	continue5:
+# if TAG_INT==1
+				    (*codeVal)(BLOCK_ARG, tmp+(int)(__MASKSMALLINT(5)) );
+# else
+				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+5));
+# endif
+				    if (InterruptPending != nil) goto interrupted6;
+	continue6:
+# if TAG_INT==1
+				    (*codeVal)(BLOCK_ARG, tmp+(int)(__MASKSMALLINT(6)) );
+# else
+				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+6));
+# endif
+				    if (InterruptPending != nil) goto interrupted7;
+	continue7:
+# if TAG_INT==1
+				    (*codeVal)(BLOCK_ARG, tmp+(int)(__MASKSMALLINT(7)) );
+# else
+				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+7));
+# endif
+
+# if TAG_INT==1
+				    tmp += (int)(__MASKSMALLINT(8));
+# else
+				    tmp += 8;
+# endif
+				}
+			        while (tmp <= final) {
+				    if (InterruptPending != nil) __interruptL(@line);
+# if TAG_INT==1
+				    (*codeVal)(BLOCK_ARG, tmp);
+				    tmp += (int)(__MASKSMALLINT(1));
+# else
+				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp));
+				    tmp++;
+# endif
+			        }
+			        RETURN (self);
+
 				if (0) {
 				    /*
 				     * no discussion about those gotos ...
@@ -1810,41 +1906,6 @@
 				    interrupted0:
 						    __interruptL(@line); goto continue0;
 				}
-
-				while (t8 <= final) {
-				    t8 += 8;
-				    if (InterruptPending != nil) goto interrupted0;
-	continue0:
-				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp));
-				    if (InterruptPending != nil) goto interrupted1;
-	continue1:
-				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+1));
-				    if (InterruptPending != nil) goto interrupted2;
-	continue2:
-				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+2));
-				    if (InterruptPending != nil) goto interrupted3;
-	continue3:
-				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+3));
-				    if (InterruptPending != nil) goto interrupted4;
-	continue4:
-				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+4));
-				    if (InterruptPending != nil) goto interrupted5;
-	continue5:
-				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+5));
-				    if (InterruptPending != nil) goto interrupted6;
-	continue6:
-				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+6));
-				    if (InterruptPending != nil) goto interrupted7;
-	continue7:
-				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+7));
-				    tmp += 8;
-				}
-			        while (tmp <= final) {
-				    if (InterruptPending != nil) __interruptL(@line);
-				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp));
-				    tmp ++;
-			        }
-			        RETURN (self);
 			    }
 #else
 			    while (tmp <= final) {
@@ -2398,5 +2459,5 @@
 !SmallInteger class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Attic/SmallInt.st,v 1.78 1997-06-06 14:48:20 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Attic/SmallInt.st,v 1.79 1997-06-18 08:42:02 cg Exp $'
 ! !
--- a/SmallInteger.st	Tue Jun 17 18:06:04 1997 +0200
+++ b/SmallInteger.st	Wed Jun 18 10:42:02 1997 +0200
@@ -1387,26 +1387,8 @@
 #ifdef WIN32
 # undef UNROLL_LOOPS
 #endif
+
 #ifdef UNROLL_LOOPS
-			if (0) {
-
-			    interrupted0:
-						__interruptL(@line); goto continue0;
-			    interrupted1:
-						__interruptL(@line); goto continue1;
-			    interrupted2:
-						__interruptL(@line); goto continue2;
-			    interrupted3:
-						__interruptL(@line); goto continue3;
-			    interrupted4:
-						__interruptL(@line); goto continue4;
-			    interrupted5:
-						__interruptL(@line); goto continue5;
-			    interrupted6:
-						__interruptL(@line); goto continue6;
-			    interrupted7:
-						__interruptL(@line); goto continue7;
-			}
 
 			/*
 			 * you are not supposed to program like this - I know what I do
@@ -1445,6 +1427,27 @@
 			} while(--tmp);
 
 			RETURN (self);
+#ifdef UNROLL_LOOPS
+			if (0) {
+
+			    interrupted0:
+						__interruptL(@line); goto continue0;
+			    interrupted1:
+						__interruptL(@line); goto continue1;
+			    interrupted2:
+						__interruptL(@line); goto continue2;
+			    interrupted3:
+						__interruptL(@line); goto continue3;
+			    interrupted4:
+						__interruptL(@line); goto continue4;
+			    interrupted5:
+						__interruptL(@line); goto continue5;
+			    interrupted6:
+						__interruptL(@line); goto continue6;
+			    interrupted7:
+						__interruptL(@line); goto continue7;
+			}
+#endif /* UNROLL_LOOPS */
 		    }
 		}
 	    }
@@ -1782,11 +1785,104 @@
 			     */
 #ifdef UNROLL_LOOPS
 			    /*
+			     * The following code is designed to run as fast as possible;
+			     *  - taken branches only if interrupts are pending
+			     *  - only forward branches (which are usually predicted as not taken)
+			     *  - unrolled the loop
+			     *
 			     * you are not supposed to program like this - I know what I do
 			     */
+# if TAG_INT==1
+			    int t8 = (int)(__MKSMALLINT(tmp+8));
+			    tmp = (int)(__MKSMALLINT(tmp));
+			    final = (int)(__MKSMALLINT(final));
+# else
 			    int t8 = tmp+8;
+# endif
 
 			    for (;;) {
+
+				while (t8 <= final) {
+# if TAG_INT==1
+				    t8 += (int)(__MASKSMALLINT(8));
+# else
+				    t8 += 8;
+# endif
+				    if (InterruptPending != nil) goto interrupted0;
+	continue0:
+# if TAG_INT==1
+				    (*codeVal)(BLOCK_ARG, tmp);
+# else
+				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp));
+# endif
+				    if (InterruptPending != nil) goto interrupted1;
+	continue1:
+# if TAG_INT==1
+				    (*codeVal)(BLOCK_ARG, tmp+(int)(__MASKSMALLINT(1)) );
+# else
+				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+1));
+# endif
+				    if (InterruptPending != nil) goto interrupted2;
+	continue2:
+# if TAG_INT==1
+				    (*codeVal)(BLOCK_ARG, tmp+(int)(__MASKSMALLINT(2)) );
+# else
+				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+2));
+# endif
+				    if (InterruptPending != nil) goto interrupted3;
+	continue3:
+# if TAG_INT==1
+				    (*codeVal)(BLOCK_ARG, tmp+(int)(__MASKSMALLINT(3)) );
+# else
+				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+3));
+# endif
+				    if (InterruptPending != nil) goto interrupted4;
+	continue4:
+# if TAG_INT==1
+				    (*codeVal)(BLOCK_ARG, tmp+(int)(__MASKSMALLINT(4)) );
+# else
+				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+4));
+# endif
+				    if (InterruptPending != nil) goto interrupted5;
+	continue5:
+# if TAG_INT==1
+				    (*codeVal)(BLOCK_ARG, tmp+(int)(__MASKSMALLINT(5)) );
+# else
+				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+5));
+# endif
+				    if (InterruptPending != nil) goto interrupted6;
+	continue6:
+# if TAG_INT==1
+				    (*codeVal)(BLOCK_ARG, tmp+(int)(__MASKSMALLINT(6)) );
+# else
+				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+6));
+# endif
+				    if (InterruptPending != nil) goto interrupted7;
+	continue7:
+# if TAG_INT==1
+				    (*codeVal)(BLOCK_ARG, tmp+(int)(__MASKSMALLINT(7)) );
+# else
+				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+7));
+# endif
+
+# if TAG_INT==1
+				    tmp += (int)(__MASKSMALLINT(8));
+# else
+				    tmp += 8;
+# endif
+				}
+			        while (tmp <= final) {
+				    if (InterruptPending != nil) __interruptL(@line);
+# if TAG_INT==1
+				    (*codeVal)(BLOCK_ARG, tmp);
+				    tmp += (int)(__MASKSMALLINT(1));
+# else
+				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp));
+				    tmp++;
+# endif
+			        }
+			        RETURN (self);
+
 				if (0) {
 				    /*
 				     * no discussion about those gotos ...
@@ -1810,41 +1906,6 @@
 				    interrupted0:
 						    __interruptL(@line); goto continue0;
 				}
-
-				while (t8 <= final) {
-				    t8 += 8;
-				    if (InterruptPending != nil) goto interrupted0;
-	continue0:
-				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp));
-				    if (InterruptPending != nil) goto interrupted1;
-	continue1:
-				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+1));
-				    if (InterruptPending != nil) goto interrupted2;
-	continue2:
-				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+2));
-				    if (InterruptPending != nil) goto interrupted3;
-	continue3:
-				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+3));
-				    if (InterruptPending != nil) goto interrupted4;
-	continue4:
-				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+4));
-				    if (InterruptPending != nil) goto interrupted5;
-	continue5:
-				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+5));
-				    if (InterruptPending != nil) goto interrupted6;
-	continue6:
-				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+6));
-				    if (InterruptPending != nil) goto interrupted7;
-	continue7:
-				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+7));
-				    tmp += 8;
-				}
-			        while (tmp <= final) {
-				    if (InterruptPending != nil) __interruptL(@line);
-				    (*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp));
-				    tmp ++;
-			        }
-			        RETURN (self);
 			    }
 #else
 			    while (tmp <= final) {
@@ -2398,5 +2459,5 @@
 !SmallInteger class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.78 1997-06-06 14:48:20 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.79 1997-06-18 08:42:02 cg Exp $'
 ! !