This is the mail archive of the insight@sourceware.org mailing list for the Insight project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Partial Patch: anti-aliasing optimizations are a pain, but we're here now


This patch is semi-mechanical.  "semi-" is the operative part and I've
spent the
time I had to play with it.  The rest of the patching should be pretty
obvious.
This patch is important, by the way, as GCC reserves the right to
permute code
that causes problems if you do not alias pointers with unions.  (Of
course, since
this is a trivial permutation, one could ask why the compiler doesn't
just internally
apply such logic itself.  I've asked that question; but the response is
that you
shouldn't be coding that way.)

Herewith, the partial patch:
--- tcl/generic/tclDate.c-ori	2003-01-21 11:40:02.000000000 -0800
+++ tcl/generic/tclDate.c	2006-11-25 13:02:59.000000000 -0800
@@ -489,9 +489,17 @@ Convert(Month, Day, Year, Hours, Minutes
     Julian += tod;
 
     /* Perform a preliminary DST compensation ?? */
-    if (DSTmode == DSTon
-     || (DSTmode == DSTmaybe && TclpGetDate((TclpTime_t)&Julian, 0)->tm_isdst))
-        Julian -= 60 * 60;
+    {
+        union {
+            time_t    * time_p;
+            TclpTime_t  tcl_time_p;
+        } u;
+        u.time_p = &Julian;
+
+        if (DSTmode == DSTon
+            || (DSTmode == DSTmaybe && TclpGetDate(u.tcl_time_p, 0)->tm_isdst))
+            Julian -= 60 * 60;
+    }
     *TimePtr = Julian;
     return 0;
 }
@@ -504,8 +512,14 @@ DSTcorrect(Start, Future)
 {
     time_t      StartDay;
     time_t      FutureDay;
-    StartDay = (TclpGetDate((TclpTime_t)&Start, 0)->tm_hour + 1) % 24;
-    FutureDay = (TclpGetDate((TclpTime_t)&Future, 0)->tm_hour + 1) % 24;
+    union {
+        time_t    * time_p;
+        TclpTime_t  tcl_time_p;
+    } u;
+    u.time_p = &Start;
+    StartDay = (TclpGetDate(u.tcl_time_p, 0)->tm_hour + 1) % 24;
+    u.time_p = &Future;
+    FutureDay = (TclpGetDate(u.tcl_time_p, 0)->tm_hour + 1) % 24;
     return (Future - Start) + (StartDay - FutureDay) * 60L * 60L;
 }
 
@@ -520,7 +534,14 @@ NamedDay(Start, DayOrdinal, DayNumber)
     time_t      now;
 
     now = Start;
-    tm = TclpGetDate((TclpTime_t)&now, 0);
+    {
+        union {
+            time_t    * time_p;
+            TclpTime_t  tcl_time_p;
+        } u;
+        u.time_p = &now;
+        tm = TclpGetDate(u.tcl_time_p, 0);
+    }
     now += SECSPERDAY * ((DayNumber - tm->tm_wday + 7) % 7);
     now += 7 * SECSPERDAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1);
     return DSTcorrect(Start, now);
@@ -537,7 +558,14 @@ NamedMonth(Start, MonthOrdinal, MonthNum
     int result;
     
     now = Start;
-    tm = TclpGetDate((TclpTime_t)&now, 0);
+    {
+        union {
+            time_t    * time_p;
+            TclpTime_t  tcl_time_p;
+        } u;
+        u.time_p = &now;
+        tm = TclpGetDate(u.tcl_time_p, 0);
+    }
     /* To compute the next n'th month, we use this alg:
      * add n to year value
      * if currentMonth < requestedMonth decrement year value by 1 (so that
@@ -572,7 +600,14 @@ RelativeMonth(Start, RelMonth, TimePtr)
         *TimePtr = 0;
         return 0;
     }
-    tm = TclpGetDate((TclpTime_t)&Start, 0);
+    {
+        union {
+            time_t    * time_p;
+            TclpTime_t  tcl_time_p;
+        } u;
+        u.time_p = &Start;
+        tm = TclpGetDate(u.tcl_time_p, 0);
+    }
     Month = 12 * (tm->tm_year + TM_YEAR_BASE) + tm->tm_mon + RelMonth;
     Year = Month / 12;
     Month = Month % 12 + 1;
@@ -845,7 +880,14 @@ TclGetDate(p, now, zone, timePtr)
     TclDateInput = p;
     /* now has to be cast to a time_t for 64bit compliance */
     Start = now;
-    tm = TclpGetDate((TclpTime_t) &Start, 0);
+    {
+        union {
+            time_t    * time_p;
+            TclpTime_t  tcl_time_p;
+        } u;
+        u.time_p = &Start;
+        tm = TclpGetDate(u.tcl_time_p, 0);
+    }
     thisyear = tm->tm_year + TM_YEAR_BASE;
     TclDateYear = thisyear;
     TclDateMonth = tm->tm_mon + 1;
--- tcl/generic/tclStubLib.c-ori	2003-01-21 11:40:06.000000000 -0800
+++ tcl/generic/tclStubLib.c	2006-11-25 13:06:33.000000000 -0800
@@ -96,8 +96,15 @@ Tcl_InitStubs (interp, version, exact)
         }
     }
 
-    actualVersion = Tcl_PkgRequireEx(interp, "Tcl", version, exact,
-	    (ClientData *) &tmp);
+    {
+        union {
+            TclStubs * p1;
+            ClientData * p2;
+        } u;
+        u.p1 = &tmp;
+
+        actualVersion = Tcl_PkgRequireEx(interp, "Tcl", version, exact, u.p2);
+    }
     if (actualVersion == NULL) {
 	tclStubsPtr = NULL;
 	return NULL;
--- tcl/generic/tclNamesp.c-ori	2003-01-21 11:40:05.000000000 -0800
+++ tcl/generic/tclNamesp.c	2006-11-25 13:05:02.000000000 -0800
@@ -2965,9 +2965,15 @@ NamespaceEvalCmd(dummy, interp, objc, ob
      * Make the specified namespace the current namespace and evaluate
      * the command(s).
      */
-
-    result = Tcl_PushCallFrame(interp, (Tcl_CallFrame *) &frame, 
-            namespacePtr, /*isProcCallFrame*/ 0);
+    {
+        union {
+            CallFrame *     p1;
+            Tcl_CallFrame * p2;
+        } u;
+        u.p1 = &frame;
+        result = Tcl_PushCallFrame(interp, u.p2, namespacePtr,
+                                   /*isProcCallFrame*/ 0);
+    }
     if (result != TCL_OK) {
         return TCL_ERROR;
     }
--- tcl/generic/tclClock.c-ori	2003-01-21 11:40:02.000000000 -0800
+++ tcl/generic/tclClock.c	2006-11-25 12:56:31.000000000 -0800
@@ -313,8 +313,15 @@ FormatClock(interp, clockVal, useGMT, fo
 #endif
 
     tclockVal = clockVal;
-    timeDataPtr = TclpGetDate((TclpTime_t) &tclockVal, useGMT);
-    
+    {
+        union {
+            time_t    * time_p;
+            TclpTime_t  tcl_time_p;
+        } u;
+        u.time_p = &tclockVal;
+        timeDataPtr = TclpGetDate(u.tcl_time_p, useGMT);
+    }
+
     /*
      * Make a guess at the upper limit on the substituted string size
      * based on the number of percents in the string.
--- tcl/unix/tclUnixChan.c-ori	2003-01-21 11:40:20.000000000 -0800
+++ tcl/unix/tclUnixChan.c	2006-11-25 13:10:29.000000000 -0800
@@ -3207,10 +3207,17 @@ TclUnixWaitForFile(fd, mask, timeout)
 	/*
 	 * Wait for the event or a timeout.
 	 */
+        {
+            union {
+                fd_mask *     p1;
+                SELECT_MASK * p2;
+            } m1, m2, m3;
+            m1.p1 = readyMasks;
+            m3.p1 = readyMasks + (2 * MASK_SIZE);
+            m2.p1 = readyMasks + MASK_SIZE;
+            numFound = select(fd+1, m1.p2, m2.p2, m3.p2, timeoutPtr);
+        }
 
-	numFound = select(fd+1, (SELECT_MASK *) &readyMasks[0],
-		(SELECT_MASK *) &readyMasks[MASK_SIZE],
-		(SELECT_MASK *) &readyMasks[2*MASK_SIZE], timeoutPtr);
 	if (numFound == 1) {
 	    if (readyMasks[index] & bit) {
 		result |= TCL_READABLE;
--- tk/generic/tkConfig.c-ori	2003-01-21 12:24:43.000000000 -0800
+++ tk/generic/tkConfig.c	2006-11-25 13:34:36.000000000 -0800
@@ -1463,85 +1463,116 @@ Tk_RestoreSavedOptions(savePtr)
 	if (specPtr->internalOffset >= 0) {
 	    switch (specPtr->type) {
 		case TK_OPTION_BOOLEAN: {
-		    *((int *) internalPtr)
-			    = *((int *) &savePtr->items[i].internalForm);
+                    union { char * p; double * p1; int * p2; } u1, u2;
+                    u1.p1 = &(savePtr->items[i].internalForm);
+                    u2.p  = internalPtr;
+                    *(u2.p2) = *(u1.p2);
 		    break;
 		}
 		case TK_OPTION_INT: {
-		    *((int *) internalPtr)
-			    = *((int *) &savePtr->items[i].internalForm);
+                    union { char * p; double * p1; int * p2; } u1, u2;
+                    u1.p1 = &(savePtr->items[i].internalForm);
+                    u2.p  = internalPtr;
+                    *(u2.p2) = *(u1.p2);
 		    break;
 		}
 		case TK_OPTION_DOUBLE: {
-		    *((double *) internalPtr)
-			    = *((double *) &savePtr->items[i].internalForm);
+                    union { char * p; double * p1; double * p2; } u1, u2;
+                    u1.p1 = &(savePtr->items[i].internalForm);
+                    u2.p  = internalPtr;
+                    *(u2.p2) = *(u1.p2);
 		    break;
 		}
 		case TK_OPTION_STRING: {
-		    *((char **) internalPtr)
-			    = *((char **) &savePtr->items[i].internalForm);
+                    union { char * p; double * p1; char ** p2; } u1, u2;
+                    u1.p1 = &(savePtr->items[i].internalForm);
+                    u2.p  = internalPtr;
+                    *(u2.p2) = *(u1.p2);
 		    break;
 		}
 		case TK_OPTION_STRING_TABLE: {
-		    *((int *) internalPtr)
-			    = *((int *) &savePtr->items[i].internalForm);
+                    union { char * p; double * p1; int * p2; } u1, u2;
+                    u1.p1 = &(savePtr->items[i].internalForm);
+                    u2.p  = internalPtr;
+                    *(u2.p2) = *(u1.p2);
 		    break;
 		}
 		case TK_OPTION_COLOR: {
-		    *((XColor **) internalPtr)
-			    = *((XColor **) &savePtr->items[i].internalForm);
+                    union { char * p; double * p1; XColor * p2; } u1, u2;
+                    u1.p1 = &(savePtr->items[i].internalForm);
+                    u2.p  = internalPtr;
+                    *(u2.p2) = *(u1.p2);
 		    break;
 		}
 		case TK_OPTION_FONT: {
-		    *((Tk_Font *) internalPtr)
-			    = *((Tk_Font *) &savePtr->items[i].internalForm);
+                    union { char * p; double * p1; Tk_Font * p2; } u1, u2;
+                    u1.p1 = &(savePtr->items[i].internalForm);
+                    u2.p  = internalPtr;
+                    *(u2.p2) = *(u1.p2);
 		    break;
 		}
 		case TK_OPTION_STYLE: {
-		    *((Tk_Style *) internalPtr)
-			    = *((Tk_Style *) &savePtr->items[i].internalForm);
+                    union { char * p; double * p1; Tk_Style * p2; } u1, u2;
+                    u1.p1 = &(savePtr->items[i].internalForm);
+                    u2.p  = internalPtr;
+                    *(u2.p2) = *(u1.p2);
 		    break;
 		}
 		case TK_OPTION_BITMAP: {
-		    *((Pixmap *) internalPtr)
-			    = *((Pixmap *) &savePtr->items[i].internalForm);
+                    union { char * p; double * p1; Pixmap * p2; } u1, u2;
+                    u1.p1 = &(savePtr->items[i].internalForm);
+                    u2.p  = internalPtr;
+                    *(u2.p2) = *(u1.p2);
 		    break;
 		}
 		case TK_OPTION_BORDER: {
-		    *((Tk_3DBorder *) internalPtr)
-			    = *((Tk_3DBorder *) &savePtr->items[i].internalForm);
+                    union { char * p; double * p1; Tk_3DBorder * p2; } u1, u2;
+                    u1.p1 = &(savePtr->items[i].internalForm);
+                    u2.p  = internalPtr;
+                    *(u2.p2) = *(u1.p2);
 		    break;
 		}
 		case TK_OPTION_RELIEF: {
-		    *((int *) internalPtr)
-			    = *((int *) &savePtr->items[i].internalForm);
+                    union { char * p; double * p1; int * p2; } u1, u2;
+                    u1.p1 = &(savePtr->items[i].internalForm);
+                    u2.p  = internalPtr;
+                    *(u2.p2) = *(u1.p2);
 		    break;
 		}
 		case TK_OPTION_CURSOR: {
-		    *((Tk_Cursor *) internalPtr)
-			    = *((Tk_Cursor *) &savePtr->items[i].internalForm);
-		    Tk_DefineCursor(savePtr->tkwin,
-			    *((Tk_Cursor *) internalPtr));
+                    union { char * p; double * p1; Tk_Cursor * p2; } u1, u2;
+                    u1.p1 = &(savePtr->items[i].internalForm);
+                    u2.p  = internalPtr;
+                    *(u2.p2) = *(u1.p2);
+		    Tk_DefineCursor(savePtr->tkwin, *(u2.p2));
 		    break;
 		}
 		case TK_OPTION_JUSTIFY: {
-		    *((Tk_Justify *) internalPtr)
-			    = *((Tk_Justify *) &savePtr->items[i].internalForm);
+                    union { char * p; double * p1; Tk_Justify * p2; } u1, u2;
+                    u1.p1 = &(savePtr->items[i].internalForm);
+                    u2.p  = internalPtr;
+                    *(u2.p2) = *(u1.p2);
 		    break;
 		}
 		case TK_OPTION_ANCHOR: {
-		    *((Tk_Anchor *) internalPtr)
-			    = *((Tk_Anchor *) &savePtr->items[i].internalForm);
+                    union { char * p; double * p1; Tk_Anchor * p2; } u1, u2;
+                    u1.p1 = &(savePtr->items[i].internalForm);
+                    u2.p  = internalPtr;
+                    *(u2.p2) = *(u1.p2);
 		    break;
 		}
 		case TK_OPTION_PIXELS: {
-		    *((int *) internalPtr)
-			    = *((int *) &savePtr->items[i].internalForm);
+                    union { char * p; double * p1; int * p2; } u1, u2;
+                    u1.p1 = &(savePtr->items[i].internalForm);
+                    u2.p  = internalPtr;
+                    *(u2.p2) = *(u1.p2);
 		    break;
 		}
 		case TK_OPTION_WINDOW: {
-		    *((Tk_Window *) internalPtr)
-			    = *((Tk_Window *) &savePtr->items[i].internalForm);
+                    union { char * p; double * p1; Tk_Window * p2; } u1, u2;
+                    u1.p1 = &(savePtr->items[i].internalForm);
+                    u2.p  = internalPtr;
+                    *(u2.p2) = *(u1.p2);
 		    break;
 		}
 		case TK_OPTION_CUSTOM: {

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]