oops - right shift by int-size did not work on some machines
authorClaus Gittinger <cg@exept.de>
Thu, 31 Jul 1997 23:36:36 +0200
changeset 2824 5295fc0fddb7
parent 2823 eb6feef1dd12
child 2825 99d51c84dd14
oops - right shift by int-size did not work on some machines
SmallInt.st
SmallInteger.st
--- a/SmallInt.st	Thu Jul 31 23:14:09 1997 +0200
+++ b/SmallInt.st	Thu Jul 31 23:36:36 1997 +0200
@@ -738,24 +738,31 @@
     INT bits, count;
 
     if (__isSmallInteger(shiftCount)) {
-	count = __intVal(shiftCount);
-	bits = __intVal(self);
-	if (count > 0) {
-	    bits = bits << count;
-	} else {
-	    bits = bits >> (-count);
-	}
+        count = __intVal(shiftCount);
+        if (count >= 32) {
+            RETURN (__MKSMALLINT(0));
+        }
+
+        bits = __intVal(self);
+        if (count > 0) {
+            bits = bits << count;
+        } else {
+            bits = bits >> (-count);
+        }
 #ifdef alpha64
-	bits &= 0xFFFFFFFFL;
+        bits &= 0xFFFFFFFFL;
 #endif
-	RETURN (__MKINT(bits));
+        RETURN (__MKINT(bits));
     }
 %}.
     ^ self primitiveFailed
 
     "
-     128 bitShift:24    
+     128 bitShift:24   
      128 bitShift32:24  
+
+     1 bitShift:31   
+     1 bitShift32:31  
     "
 !
 
@@ -763,70 +770,77 @@
     "return the value of the receiver shifted by shiftCount bits;
      leftShift if shiftCount > 0; rightShift otherwise.
      Notice: the result of bitShift: on negative receivers is not 
-	     defined in the language standard (since the implementation
-	     is free to choose any internal representation for integers)"
+             defined in the language standard (since the implementation
+             is free to choose any internal representation for integers)"
 
 %{  /* NOCONTEXT */
 
     INT bits, count;
 
     if (__isSmallInteger(shiftCount)) {
-	count = __intVal(shiftCount);
-	bits = __intVal(self);
-	if (bits == 0) {
-	    RETURN (self);
-	}
-
-	if (count > 0) {
+        bits = __intVal(self);
+        if (bits == 0) {
+            RETURN (self);
+        }
+
+        count = __intVal(shiftCount);
+
+        if (count > 0) {
+            /*
+             * a left shift
+             */
 #if defined(USE_LONGLONG)
-	    unsigned LONGLONG result;
-
-	    result = bits;
-	    if (count <= N_INT_BITS) {
-		result <<= count;
-		if (result <= _MAX_INT) {
-		    RETURN ( __MKSMALLINT(result) );
-		}
-		{
-		    extern OBJ __MKLARGEINT64();
-
-		    RETURN (__MKLARGEINT64(1, (INT)(result >> 32), (INT)(result & 0xFFFFFFFF)));
-		}
-	    }
+            unsigned LONGLONG result;
+
+            result = bits;
+            if (count <= N_INT_BITS) {
+                result <<= count;
+                if (result <= _MAX_INT) {
+                    RETURN ( __MKSMALLINT(result) );
+                }
+                {
+                    extern OBJ __MKLARGEINT64();
+
+                    RETURN (__MKLARGEINT64(1, (INT)(result >> 32), (INT)(result & 0xFFFFFFFF)));
+                }
+            }
 #else
-	    /*
-	     * check for overflow
-	     */
-	    if (count < (N_INT_BITS-1)) {
-		if (! (bits >> (N_INT_BITS - 1 - count))) {
-		    RETURN ( __MKSMALLINT(bits << count) );
-		}
-		/*
-		 * so, there is an overflow ...
-		 * handle it as largeInteger
-		 */
-		/* FALL THROUGH */
-	    }
+            /*
+             * check for overflow
+             */
+            if (count < (N_INT_BITS-1)) {
+                if (! (bits >> (N_INT_BITS - 1 - count))) {
+                    RETURN ( __MKSMALLINT(bits << count) );
+                }
+                /*
+                 * so, there is an overflow ...
+                 * handle it as largeInteger
+                 */
+                /* FALL THROUGH */
+            }
 #endif
-	} else {
-	    /*
-	     * right shifts cannot overflow
-	     */
-	    if (count < 0) {
-		/*
-		 * some machines ignore shifts bigger than
-		 * the number of bits in an int ...
-		 */
-		if (count < (-N_INT_BITS-1))
-		    RETURN (__MKSMALLINT(0));
-		RETURN ( __MKSMALLINT(bits >> -count) );
-	    }
-	    RETURN (self );
-	}
+        } else {
+            if (count == 0) {
+                RETURN (self);
+            }
+
+            /*
+             * right shifts cannot overflow
+             *
+             * some machines ignore shifts bigger than
+             * the number of bits in an int ...
+             */
+            count = -count;
+            if (count > (N_INT_BITS-1)) {
+                RETURN (__MKSMALLINT(0));
+            }
+
+            RETURN ( __MKSMALLINT(bits >> count) );
+        }
     }
 %}.
     (shiftCount isMemberOf:SmallInteger) ifTrue:[
-	^ (LargeInteger value:self) bitShift:shiftCount
+        ^ (LargeInteger value:self) bitShift:shiftCount
     ].
     ^ self bitShift:(shiftCount coerce:1)
 !
@@ -1527,14 +1541,15 @@
 			}
 #endif /* UNROLL_LOOPS */
 			do {
-			    if (InterruptPending != nil) __interruptL(@line);
+			    if (InterruptPending != nil) goto interruptedX;
+	continueX:
 			    (*codeVal)(BLOCK_ARG);
 			} while(--tmp);
 
 			RETURN (self);
-#ifdef UNROLL_LOOPS
+
 			if (0) {
-
+#ifdef UNROLL_LOOPS
 			    interrupted0:
 						__interruptL(@line); goto continue0;
 			    interrupted1:
@@ -1551,8 +1566,10 @@
 						__interruptL(@line); goto continue6;
 			    interrupted7:
 						__interruptL(@line); goto continue7;
+#endif /* UNROLL_LOOPS */
+			    interruptedX:
+						__interruptL(@line); goto continueX;
 			}
-#endif /* UNROLL_LOOPS */
 		    }
 		}
 	    }
@@ -1977,7 +1994,8 @@
 # endif
 				}
 			        while (tmp <= final) {
-				    if (InterruptPending != nil) __interruptL(@line);
+				    if (InterruptPending != nil) goto interruptedX;
+	continueX:
 # if TAG_INT==1
 				    (*codeVal)(BLOCK_ARG, tmp);
 				    tmp += (INT)(__MASKSMALLINT(1));
@@ -2010,6 +2028,8 @@
 						    __interruptL(@line); goto continue1;
 				    interrupted0:
 						    __interruptL(@line); goto continue0;
+				    interruptedX:
+						    __interruptL(@line); goto continueX;
 				}
 			    }
 #else
@@ -2609,5 +2629,5 @@
 !SmallInteger class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Attic/SmallInt.st,v 1.86 1997-07-31 11:19:30 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Attic/SmallInt.st,v 1.87 1997-07-31 21:36:36 cg Exp $'
 ! !
--- a/SmallInteger.st	Thu Jul 31 23:14:09 1997 +0200
+++ b/SmallInteger.st	Thu Jul 31 23:36:36 1997 +0200
@@ -738,24 +738,31 @@
     INT bits, count;
 
     if (__isSmallInteger(shiftCount)) {
-	count = __intVal(shiftCount);
-	bits = __intVal(self);
-	if (count > 0) {
-	    bits = bits << count;
-	} else {
-	    bits = bits >> (-count);
-	}
+        count = __intVal(shiftCount);
+        if (count >= 32) {
+            RETURN (__MKSMALLINT(0));
+        }
+
+        bits = __intVal(self);
+        if (count > 0) {
+            bits = bits << count;
+        } else {
+            bits = bits >> (-count);
+        }
 #ifdef alpha64
-	bits &= 0xFFFFFFFFL;
+        bits &= 0xFFFFFFFFL;
 #endif
-	RETURN (__MKINT(bits));
+        RETURN (__MKINT(bits));
     }
 %}.
     ^ self primitiveFailed
 
     "
-     128 bitShift:24    
+     128 bitShift:24   
      128 bitShift32:24  
+
+     1 bitShift:31   
+     1 bitShift32:31  
     "
 !
 
@@ -763,70 +770,77 @@
     "return the value of the receiver shifted by shiftCount bits;
      leftShift if shiftCount > 0; rightShift otherwise.
      Notice: the result of bitShift: on negative receivers is not 
-	     defined in the language standard (since the implementation
-	     is free to choose any internal representation for integers)"
+             defined in the language standard (since the implementation
+             is free to choose any internal representation for integers)"
 
 %{  /* NOCONTEXT */
 
     INT bits, count;
 
     if (__isSmallInteger(shiftCount)) {
-	count = __intVal(shiftCount);
-	bits = __intVal(self);
-	if (bits == 0) {
-	    RETURN (self);
-	}
-
-	if (count > 0) {
+        bits = __intVal(self);
+        if (bits == 0) {
+            RETURN (self);
+        }
+
+        count = __intVal(shiftCount);
+
+        if (count > 0) {
+            /*
+             * a left shift
+             */
 #if defined(USE_LONGLONG)
-	    unsigned LONGLONG result;
-
-	    result = bits;
-	    if (count <= N_INT_BITS) {
-		result <<= count;
-		if (result <= _MAX_INT) {
-		    RETURN ( __MKSMALLINT(result) );
-		}
-		{
-		    extern OBJ __MKLARGEINT64();
-
-		    RETURN (__MKLARGEINT64(1, (INT)(result >> 32), (INT)(result & 0xFFFFFFFF)));
-		}
-	    }
+            unsigned LONGLONG result;
+
+            result = bits;
+            if (count <= N_INT_BITS) {
+                result <<= count;
+                if (result <= _MAX_INT) {
+                    RETURN ( __MKSMALLINT(result) );
+                }
+                {
+                    extern OBJ __MKLARGEINT64();
+
+                    RETURN (__MKLARGEINT64(1, (INT)(result >> 32), (INT)(result & 0xFFFFFFFF)));
+                }
+            }
 #else
-	    /*
-	     * check for overflow
-	     */
-	    if (count < (N_INT_BITS-1)) {
-		if (! (bits >> (N_INT_BITS - 1 - count))) {
-		    RETURN ( __MKSMALLINT(bits << count) );
-		}
-		/*
-		 * so, there is an overflow ...
-		 * handle it as largeInteger
-		 */
-		/* FALL THROUGH */
-	    }
+            /*
+             * check for overflow
+             */
+            if (count < (N_INT_BITS-1)) {
+                if (! (bits >> (N_INT_BITS - 1 - count))) {
+                    RETURN ( __MKSMALLINT(bits << count) );
+                }
+                /*
+                 * so, there is an overflow ...
+                 * handle it as largeInteger
+                 */
+                /* FALL THROUGH */
+            }
 #endif
-	} else {
-	    /*
-	     * right shifts cannot overflow
-	     */
-	    if (count < 0) {
-		/*
-		 * some machines ignore shifts bigger than
-		 * the number of bits in an int ...
-		 */
-		if (count < (-N_INT_BITS-1))
-		    RETURN (__MKSMALLINT(0));
-		RETURN ( __MKSMALLINT(bits >> -count) );
-	    }
-	    RETURN (self );
-	}
+        } else {
+            if (count == 0) {
+                RETURN (self);
+            }
+
+            /*
+             * right shifts cannot overflow
+             *
+             * some machines ignore shifts bigger than
+             * the number of bits in an int ...
+             */
+            count = -count;
+            if (count > (N_INT_BITS-1)) {
+                RETURN (__MKSMALLINT(0));
+            }
+
+            RETURN ( __MKSMALLINT(bits >> count) );
+        }
     }
 %}.
     (shiftCount isMemberOf:SmallInteger) ifTrue:[
-	^ (LargeInteger value:self) bitShift:shiftCount
+        ^ (LargeInteger value:self) bitShift:shiftCount
     ].
     ^ self bitShift:(shiftCount coerce:1)
 !
@@ -1527,14 +1541,15 @@
 			}
 #endif /* UNROLL_LOOPS */
 			do {
-			    if (InterruptPending != nil) __interruptL(@line);
+			    if (InterruptPending != nil) goto interruptedX;
+	continueX:
 			    (*codeVal)(BLOCK_ARG);
 			} while(--tmp);
 
 			RETURN (self);
-#ifdef UNROLL_LOOPS
+
 			if (0) {
-
+#ifdef UNROLL_LOOPS
 			    interrupted0:
 						__interruptL(@line); goto continue0;
 			    interrupted1:
@@ -1551,8 +1566,10 @@
 						__interruptL(@line); goto continue6;
 			    interrupted7:
 						__interruptL(@line); goto continue7;
+#endif /* UNROLL_LOOPS */
+			    interruptedX:
+						__interruptL(@line); goto continueX;
 			}
-#endif /* UNROLL_LOOPS */
 		    }
 		}
 	    }
@@ -1977,7 +1994,8 @@
 # endif
 				}
 			        while (tmp <= final) {
-				    if (InterruptPending != nil) __interruptL(@line);
+				    if (InterruptPending != nil) goto interruptedX;
+	continueX:
 # if TAG_INT==1
 				    (*codeVal)(BLOCK_ARG, tmp);
 				    tmp += (INT)(__MASKSMALLINT(1));
@@ -2010,6 +2028,8 @@
 						    __interruptL(@line); goto continue1;
 				    interrupted0:
 						    __interruptL(@line); goto continue0;
+				    interruptedX:
+						    __interruptL(@line); goto continueX;
 				}
 			    }
 #else
@@ -2609,5 +2629,5 @@
 !SmallInteger class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.86 1997-07-31 11:19:30 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.87 1997-07-31 21:36:36 cg Exp $'
 ! !