more variable-inst accesses; use switch instead of multiway-if.
--- a/Object.st Mon Jan 12 14:16:03 1998 +0100
+++ b/Object.st Mon Jan 12 14:17:31 1998 +0100
@@ -491,15 +491,18 @@
unsigned char *cp;
unsigned short *sp;
short *ssp;
- unsigned long *lp;
- long *slp;
- unsigned long ul;
- long l;
+#ifdef alpha64
+# define int32 int
+#else
+# define int32 long
+#endif
+ unsigned int32 *lp;
+ int32 *slp;
+ unsigned int32 ul;
+ int32 l;
OBJ *op;
-/* int nInstBytes, nInstVars, flags; */
REGISTER int n;
-
/*
* notice the missing test for self being a nonNilObject -
* this can be done since basicAt: is defined both in UndefinedObject
@@ -513,71 +516,112 @@
nbytes = __qSize(self) - n /* nInstBytes */;
pFirst = (char *)(__InstPtr(self)) + n /* nInstBytes */;
- /*
- * replaced switch by open-coded if; this is slightly faster
- * since it avoids the range check and also handles the most common case first
- */
- n = (INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK);
-
- if ((n == __MASKSMALLINT(POINTERARRAY))
- || (n == __MASKSMALLINT(WKPOINTERARRAY))) {
- if ((indx >= 0) && (indx < (__BYTES2OBJS__(nbytes)))) {
- op = (OBJ *)pFirst + indx;
- RETURN ( *op );
- }
- } else if (n == __MASKSMALLINT(BYTEARRAY)) {
- if ((indx >= 0) && (indx < (nbytes / sizeof(char)))) {
- cp = (unsigned char *)pFirst + indx;
- RETURN ( __MKSMALLINT(*cp & 0xFF) );
- }
- } else if (n == __MASKSMALLINT(FLOATARRAY)) {
- if ((indx >= 0) && (indx < (nbytes / sizeof(float)))) {
- float *fp;
-
- fp = (float *)pFirst + indx;
- RETURN ( __MKFLOAT((double)(*fp)));
- }
- } else if (n == __MASKSMALLINT(DOUBLEARRAY)) {
- if ((indx >= 0) && (indx < (nbytes / sizeof(double)))) {
- double *dp;
+ switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) {
+ case __MASKSMALLINT(POINTERARRAY):
+ case __MASKSMALLINT(WKPOINTERARRAY):
+ /*
+ * pointers
+ */
+ if ((indx >= 0) && (indx < (__BYTES2OBJS__(nbytes)))) {
+ op = (OBJ *)pFirst + indx;
+ RETURN ( *op );
+ }
+ break;
+
+ case __MASKSMALLINT(BYTEARRAY):
+ /*
+ * (unsigned) bytes
+ */
+ if ((indx >= 0) && (indx < (nbytes / sizeof(char)))) {
+ cp = (unsigned char *)pFirst + indx;
+ RETURN ( __MKSMALLINT(*cp & 0xFF) );
+ }
+ break;
+
+ case __MASKSMALLINT(FLOATARRAY):
+ /*
+ * native floats
+ */
+ if ((indx >= 0) && (indx < (nbytes / sizeof(float)))) {
+ float *fp;
+ OBJ v;
+
+ fp = (float *)pFirst + indx;
+ __qMKSFLOAT(v, *fp);
+ RETURN (v);
+ }
+ break;
+
+ case __MASKSMALLINT(DOUBLEARRAY):
+ /*
+ * native doubles
+ */
+ if ((indx >= 0) && (indx < (nbytes / sizeof(double)))) {
+ double *dp;
+ OBJ v;
#ifdef NEED_DOUBLE_ALIGN
- /*
- * care for filler
- */
- pFirst += sizeof(FILLTYPE);
+ /*
+ * care for filler
+ */
+ pFirst += sizeof(FILLTYPE);
#endif
- dp = (double *)pFirst + indx;
- RETURN ( __MKFLOAT(*dp));
- }
- } else if (n == __MASKSMALLINT(WORDARRAY)) {
- if ((indx >= 0) && (indx < (nbytes / sizeof(short)))) {
- sp = (unsigned short *)pFirst + indx;
- RETURN ( __MKSMALLINT(*sp & 0xFFFF) );
- }
- } else if (n == __MASKSMALLINT(SWORDARRAY)) {
- if ((indx >= 0) && (indx < (nbytes / sizeof(short)))) {
- ssp = (short *)pFirst + indx;
- RETURN ( __MKSMALLINT(*ssp) );
- }
- } else if (n == __MASKSMALLINT(LONGARRAY)) {
- if ((indx >= 0) && (indx < (nbytes / sizeof(long)))) {
- lp = (unsigned long *)pFirst + indx;
- ul = *lp;
- if (ul <= _MAX_INT)
- RETURN ( __MKSMALLINT(ul) );
- RETURN ( __MKULARGEINT(ul) );
- }
- } else if (n == __MASKSMALLINT(SLONGARRAY)) {
- if ((indx >= 0) && (indx < (nbytes / sizeof(long)))) {
- slp = (long *)pFirst + indx;
- l = *slp;
- if ((l >= _MIN_INT) && (l <= _MAX_INT))
- RETURN ( __MKSMALLINT(l) );
- RETURN ( __MKLARGEINT(l) );
- }
+ dp = (double *)pFirst + indx;
+ __qMKFLOAT(v, *dp);
+ RETURN (v);
+ }
+ break;
+
+ case __MASKSMALLINT(WORDARRAY):
+ /*
+ * unsigned 16bit ints
+ */
+ if ((indx >= 0) && (indx < (nbytes / sizeof(short)))) {
+ sp = (unsigned short *)pFirst + indx;
+ RETURN ( __MKSMALLINT(*sp & 0xFFFF) );
+ }
+ break;
+
+ case __MASKSMALLINT(SWORDARRAY):
+ /*
+ * signed 16bit ints
+ */
+ if ((indx >= 0) && (indx < (nbytes / sizeof(short)))) {
+ ssp = (short *)pFirst + indx;
+ RETURN ( __MKSMALLINT(*ssp) );
+ }
+ break;
+
+ case __MASKSMALLINT(LONGARRAY):
+ /*
+ * unsigned native 32bit ints
+ */
+ if ((indx >= 0) && (indx < (nbytes / sizeof(int32)))) {
+ lp = (unsigned int32 *)pFirst + indx;
+ ul = *lp;
+ if (ul <= _MAX_INT)
+ RETURN ( __MKSMALLINT(ul) );
+ RETURN ( __MKULARGEINT(ul) );
+ }
+ break;
+
+ case __MASKSMALLINT(SLONGARRAY):
+ /*
+ * signed native 32bit ints
+ */
+ if ((indx >= 0) && (indx < (nbytes / sizeof(int32)))) {
+ slp = (int32 *)pFirst + indx;
+ l = *slp;
+ if ((l >= _MIN_INT) && (l <= _MAX_INT))
+ RETURN ( __MKSMALLINT(l) );
+ RETURN ( __MKLARGEINT(l) );
+ }
+ break;
}
}
+
+# undef int32
+
%}.
index isInteger ifFalse:[
^ self indexNotInteger
@@ -600,8 +644,13 @@
char *cp;
unsigned short *sp;
short *ssp;
- unsigned long *lp;
- long *slp;
+#ifdef alpha64
+# define int32 int
+#else
+# define int32 long
+#endif
+ unsigned int32 *lp;
+ int32 *slp;
OBJ *op;
/* int nInstBytes, ninstvars, flags; */
REGISTER int n;
@@ -620,117 +669,144 @@
nbytes = __qSize(self) - n /* nInstBytes */;
pFirst = (char *)(__InstPtr(self)) + n /* nInstBytes */;
- n = (INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK);
-
- /*
- * replaced switch by open-coded if; this is slightly faster
- * since it avoids the range check and also handles the most common case first
- */
- if ((n == __MASKSMALLINT(POINTERARRAY))
- || (n == __MASKSMALLINT(WKPOINTERARRAY))) {
- if ((indx >= 0) && (indx < (__BYTES2OBJS__(nbytes)))) {
- op = (OBJ *)pFirst + indx;
- *op = anObject;
- __STORE(self, anObject);
- RETURN ( anObject );
- }
- } else if (n == __MASKSMALLINT(BYTEARRAY)) {
- if (__isSmallInteger(anObject)) {
- val = __intVal(anObject);
- if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) {
- if ((indx >= 0) && (indx < (nbytes / sizeof(char)))) {
- cp = pFirst + indx;
- *cp = val;
- RETURN ( anObject );
+ switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) {
+ case __MASKSMALLINT(POINTERARRAY):
+ case __MASKSMALLINT(WKPOINTERARRAY):
+ if ((indx >= 0) && (indx < (__BYTES2OBJS__(nbytes)))) {
+ op = (OBJ *)pFirst + indx;
+ *op = anObject;
+ __STORE(self, anObject);
+ RETURN ( anObject );
+ }
+ break;
+
+ case __MASKSMALLINT(BYTEARRAY):
+ if (__isSmallInteger(anObject)) {
+ val = __intVal(anObject);
+ if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) {
+ if ((indx >= 0) && (indx < (nbytes / sizeof(char)))) {
+ cp = pFirst + indx;
+ *cp = val;
+ RETURN ( anObject );
+ }
}
- }
- }
- } else if (n == __MASKSMALLINT(FLOATARRAY)) {
- if ((indx >= 0) && (indx < (nbytes / sizeof(float)))) {
- float *fp;
-
- fp = (float *)pFirst + indx;
- if (__isFloatLike(anObject)) {
- *fp = _floatVal(anObject);
- RETURN ( anObject );
- }
- if (__isSmallInteger(anObject)) {
- *fp = (float) __intVal(anObject);
- RETURN ( anObject );
- }
- }
- } else if (n == __MASKSMALLINT(DOUBLEARRAY)) {
- if ((indx >= 0) && (indx < (nbytes / sizeof(double)))) {
- double *dp;
+ }
+ break;
+
+ case __MASKSMALLINT(FLOATARRAY):
+ if ((indx >= 0) && (indx < (nbytes / sizeof(float)))) {
+ float *fp;
+
+ fp = (float *)pFirst + indx;
+ if (__isFloatLike(anObject)) {
+ *fp = (float)(__floatVal(anObject));
+ RETURN ( anObject );
+ }
+ if (__isSmallInteger(anObject)) {
+ *fp = (float) __intVal(anObject);
+ RETURN ( anObject );
+ }
+ if (__isShortFloat(anObject)) {
+ *fp = __shortFloatVal(anObject);
+ RETURN ( anObject );
+ }
+ }
+ break;
+
+ case __MASKSMALLINT(DOUBLEARRAY):
+ if ((indx >= 0) && (indx < (nbytes / sizeof(double)))) {
+ double *dp;
#ifdef NEED_DOUBLE_ALIGN
- /*
- * care for filler
- */
- pFirst += sizeof(FILLTYPE);
+ /*
+ * care for filler
+ */
+ pFirst += sizeof(FILLTYPE);
#endif
- dp = (double *)pFirst + indx;
- if (__isFloatLike(anObject)) {
- *dp = _floatVal(anObject);
- RETURN ( anObject );
- }
- if (__isSmallInteger(anObject)) {
- *dp = (double) __intVal(anObject);
- RETURN ( anObject );
- }
- }
- } else if (n == __MASKSMALLINT(WORDARRAY)) {
- if (__isSmallInteger(anObject)) {
- val = __intVal(anObject);
- if ((val >= 0) && (val <= 0xFFFF)) {
- if ((indx >= 0) && (indx < (nbytes / sizeof(short)))) {
- sp = (unsigned short *)pFirst + indx;
- *sp = val;
- RETURN ( anObject );
+ dp = (double *)pFirst + indx;
+ if (__isFloatLike(anObject)) {
+ *dp = __floatVal(anObject);
+ RETURN ( anObject );
+ }
+ if (__isSmallInteger(anObject)) {
+ *dp = (double) __intVal(anObject);
+ RETURN ( anObject );
+ }
+ if (__isShortFloat(anObject)) {
+ *dp = (double)__shortFloatVal(anObject);
+ RETURN ( anObject );
+ }
+ }
+ break;
+
+ case __MASKSMALLINT(WORDARRAY):
+ if (__isSmallInteger(anObject)) {
+ val = __intVal(anObject);
+ if ((val >= 0) && (val <= 0xFFFF)) {
+ if ((indx >= 0) && (indx < (nbytes / sizeof(short)))) {
+ sp = (unsigned short *)pFirst + indx;
+ *sp = val;
+ RETURN ( anObject );
+ }
}
- }
- }
- } else if (n == __MASKSMALLINT(SWORDARRAY)) {
- if (__isSmallInteger(anObject)) {
- val = __intVal(anObject);
- if ((val >= -32768) && (val < 32768)) {
- if ((indx >= 0) && (indx < (nbytes / sizeof(short)))) {
- ssp = (short *)pFirst + indx;
- *ssp = val;
- RETURN ( anObject );
+ }
+ break;
+
+ case __MASKSMALLINT(SWORDARRAY):
+ if (__isSmallInteger(anObject)) {
+ val = __intVal(anObject);
+ if ((val >= -32768) && (val < 32768)) {
+ if ((indx >= 0) && (indx < (nbytes / sizeof(short)))) {
+ ssp = (short *)pFirst + indx;
+ *ssp = val;
+ RETURN ( anObject );
+ }
+ }
+ }
+ break;
+
+ case __MASKSMALLINT(SLONGARRAY):
+ if ((indx >= 0) && (indx < (nbytes / sizeof(int32)))) {
+ slp = (int32 *)pFirst + indx;
+ if (__isSmallInteger(anObject)) {
+ *slp = __intVal(anObject);
+ RETURN ( anObject );
}
- }
- }
- } else if (n == __MASKSMALLINT(SLONGARRAY)) {
- if ((indx >= 0) && (indx < (nbytes / sizeof(long)))) {
- slp = (long *)pFirst + indx;
- if (__isSmallInteger(anObject)) {
- *slp = __intVal(anObject);
- RETURN ( anObject );
- }
- n = __signedLongIntVal(anObject);
- /* zero means failure for an int larger than 4 bytes ... (would be a smallInteger) */
- if (n) {
- *slp = n;
- RETURN ( anObject );
- }
- }
- } else if (n == __MASKSMALLINT(LONGARRAY)) {
- if ((indx >= 0) && (indx < (nbytes / sizeof(long)))) {
- lp = (unsigned long *)pFirst + indx;
- if (anObject == __MKSMALLINT(0)) {
- *lp = 0;
- RETURN ( anObject );
- }
- u = __longIntVal(anObject);
- /* zero means failure for an int larger than 4 bytes ... (would be a smallInteger) */
- if (u) {
- *lp = u;
- RETURN ( anObject );
- }
- }
+ n = __signedLongIntVal(anObject);
+ /*
+ * zero means failure for an int larger than 4 bytes
+ * (would be a smallInteger)
+ */
+ if (n) {
+ *slp = n;
+ RETURN ( anObject );
+ }
+ }
+ break;
+
+ case __MASKSMALLINT(LONGARRAY):
+ if ((indx >= 0) && (indx < (nbytes / sizeof(int32)))) {
+ lp = (unsigned int32 *)pFirst + indx;
+ if (anObject == __MKSMALLINT(0)) {
+ *lp = 0;
+ RETURN ( anObject );
+ }
+ u = __longIntVal(anObject);
+ /*
+ * zero means failure for an int larger than 4 bytes
+ * (would be a smallInteger)
+ */
+ if (u) {
+ *lp = u;
+ RETURN ( anObject );
+ }
+ }
+ break;
}
}
+
+# undef int32
+
%}.
index isInteger ifFalse:[
"
@@ -787,14 +863,14 @@
if (__isNonNilObject(slf)) {
cls = __qClass(slf);
- switch (__intVal(__ClassInstPtr(cls)->c_flags) & ARRAYMASK) {
- case BYTEARRAY:
- case WORDARRAY:
- case LONGARRAY:
- case SWORDARRAY:
- case SLONGARRAY:
- case FLOATARRAY:
- case DOUBLEARRAY:
+ switch ((INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK)) {
+ case __MASKSMALLINT(BYTEARRAY):
+ case __MASKSMALLINT(WORDARRAY):
+ case __MASKSMALLINT(LONGARRAY):
+ case __MASKSMALLINT(SWORDARRAY):
+ case __MASKSMALLINT(SLONGARRAY):
+ case __MASKSMALLINT(FLOATARRAY):
+ case __MASKSMALLINT(DOUBLEARRAY):
indx = __intVal(index) - 1;
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
nIndex = __byteArraySize(slf);
@@ -842,14 +918,14 @@
if (__isNonNilObject(slf)) {
cls = __qClass(slf);
- switch (__intVal(__ClassInstPtr(cls)->c_flags) & ARRAYMASK) {
- case BYTEARRAY:
- case WORDARRAY:
- case LONGARRAY:
- case SWORDARRAY:
- case SLONGARRAY:
- case FLOATARRAY:
- case DOUBLEARRAY:
+ switch ((INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK)) {
+ case __MASKSMALLINT(BYTEARRAY):
+ case __MASKSMALLINT(WORDARRAY):
+ case __MASKSMALLINT(LONGARRAY):
+ case __MASKSMALLINT(SWORDARRAY):
+ case __MASKSMALLINT(SLONGARRAY):
+ case __MASKSMALLINT(FLOATARRAY):
+ case __MASKSMALLINT(DOUBLEARRAY):
indx = __intVal(index) - 1;
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
nIndex = __byteArraySize(slf);
@@ -4840,7 +4916,11 @@
REGISTER int nbytes;
REGISTER OBJ myClass;
- REGISTER INT flags;
+#ifdef alpha64
+# define int32 int
+#else
+# define int32 long
+#endif
/*
* notice the missing test for self being a nonNilObject -
@@ -4852,24 +4932,20 @@
- OHDR_SIZE
- __OBJS2BYTES__(__intVal(__ClassInstPtr(myClass)->c_ninstvars));
- flags = (INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK);
- /*
- * replaced switch by open-if; this is slightly faster since
- * it avoids the range check and also checks the most common case first
- */
- if (flags == __MASKSMALLINT(POINTERARRAY)) {
- RETURN ( __MKSMALLINT(__BYTES2OBJS__(nbytes)) );
- }
- if (flags == __MASKSMALLINT(BYTEARRAY)) {
+ switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) {
+ case __MASKSMALLINT(POINTERARRAY):
+ RETURN ( __MKSMALLINT(__BYTES2OBJS__(nbytes)) );
+
+ case __MASKSMALLINT(BYTEARRAY):
RETURN ( __MKSMALLINT(nbytes / sizeof(char)) );
- }
- if (flags == __MASKSMALLINT(WKPOINTERARRAY)) {
- RETURN ( __MKSMALLINT(__BYTES2OBJS__(nbytes)) );
- }
- if (flags == __MASKSMALLINT(FLOATARRAY)) {
- RETURN ( __MKSMALLINT(nbytes / sizeof(float)) );
- }
- if (flags == __MASKSMALLINT(DOUBLEARRAY)) {
+
+ case __MASKSMALLINT(WKPOINTERARRAY):
+ RETURN ( __MKSMALLINT(__BYTES2OBJS__(nbytes)) );
+
+ case __MASKSMALLINT(FLOATARRAY):
+ RETURN ( __MKSMALLINT(nbytes / sizeof(float)) );
+
+ case __MASKSMALLINT(DOUBLEARRAY):
#ifdef NEED_DOUBLE_ALIGN
/*
* care for filler
@@ -4877,13 +4953,18 @@
nbytes -= sizeof(FILLTYPE);
#endif
RETURN ( __MKSMALLINT(nbytes / sizeof(double)) );
- }
- if ((flags == __MASKSMALLINT(WORDARRAY)) || (flags == __MASKSMALLINT(SWORDARRAY))) {
- RETURN ( __MKSMALLINT(nbytes / sizeof(short)) );
+
+ case __MASKSMALLINT(WORDARRAY):
+ case __MASKSMALLINT(SWORDARRAY):
+ RETURN ( __MKSMALLINT(nbytes / sizeof(short)) );
+
+ case __MASKSMALLINT(LONGARRAY):
+ case __MASKSMALLINT(SLONGARRAY):
+ RETURN ( __MKSMALLINT(nbytes / sizeof(int32)) );
}
- if ((flags == __MASKSMALLINT(LONGARRAY)) || (flags == __MASKSMALLINT(SLONGARRAY))) {
- RETURN ( __MKSMALLINT(nbytes / sizeof(long)) );
- }
+
+# undef int32
+
%}.
^ 0
!
@@ -4906,14 +4987,14 @@
if (__isNonNilObject(slf)) {
cls = __qClass(slf);
- switch (__intVal(__ClassInstPtr(cls)->c_flags) & ARRAYMASK) {
- case BYTEARRAY:
- case WORDARRAY:
- case LONGARRAY:
- case SWORDARRAY:
- case SLONGARRAY:
- case FLOATARRAY:
- case DOUBLEARRAY:
+ switch ((INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK)) {
+ case __MASKSMALLINT(BYTEARRAY):
+ case __MASKSMALLINT(WORDARRAY):
+ case __MASKSMALLINT(LONGARRAY):
+ case __MASKSMALLINT(SWORDARRAY):
+ case __MASKSMALLINT(SLONGARRAY):
+ case __MASKSMALLINT(FLOATARRAY):
+ case __MASKSMALLINT(DOUBLEARRAY):
nIndex = __byteArraySize(slf);
nIndex -= __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
RETURN ( __MKSMALLINT(nIndex) );
@@ -6241,6 +6322,6 @@
!Object class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Object.st,v 1.215 1997-12-19 08:38:43 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Object.st,v 1.216 1998-01-12 13:17:31 cg Exp $'
! !
Object initialize!