Added fi_type union typedef to glheader.h.
authorBrian Paul <brian.paul@tungstengraphics.com>
Fri, 15 Jun 2001 15:22:07 +0000 (15:22 +0000)
committerBrian Paul <brian.paul@tungstengraphics.com>
Fri, 15 Jun 2001 15:22:07 +0000 (15:22 +0000)
Replace various float/int casts with the fi_type union cast.
Fixes -fstrict-aliasing problems.

src/mesa/main/glheader.h
src/mesa/main/texutil.c
src/mesa/tnl/t_imm_api.c
src/mesa/tnl/t_vb_render.c

index 0324b42ffd944075bb1570a4731580df14f76e1c..596bd2d01ee3641ecee3e4e6880e3cc2bcd5a8ad 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: glheader.h,v 1.20 2001/05/14 23:11:12 brianp Exp $ */
+/* $Id: glheader.h,v 1.21 2001/06/15 15:22:07 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -241,5 +241,15 @@ typedef struct tagPIXELFORMATDESCRIPTOR PIXELFORMATDESCRIPTOR, *PPIXELFORMATDESC
 #endif
 
 
+/*
+ * Sometimes we treat GLfloats as GLints.  On x86 systems, moving a float
+ * as a int (thereby using integer registers instead of fp registers) is
+ * a performance win.  Typically, this can be done with ordinary casts.
+ * But with gcc's -fstrict-aliasing flag (which defaults to on in gcc 3.0)
+ * these casts generate warnings.
+ * The following union typedef is used to solve that.
+ */
+typedef union { GLfloat f; GLint i; } fi_type;
+
 
 #endif /* GLHEADER_H */
index e7c8fa7608a31d92507c82a8e48916376d70012a..6231f589af228aa7209326a56c7b72f2da5abf9a 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: texutil.c,v 1.24 2001/05/02 21:02:38 brianp Exp $ */
+/* $Id: texutil.c,v 1.25 2001/06/15 15:22:08 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -415,7 +415,7 @@ CONVERT_ARGB4444( texsubimage3d )
          dst = (s >> 1) | ((s & 1) << 15); }
 
 #define CONVERT_TEXEL_DWORD( dst, src )                                        \
-       { const GLuint s = *(GLuint *)src;                              \
+       { const GLuint s = ((fi_type *)src)->i;                         \
          dst = (((s & 0xfffefffe) >> 1) |                              \
                 ((s & 0x00010001) << 15)); }
 
index 9c4894ada749f148953e920a84fa3b99b2c6f3b4..4063c8c3b2ba43c2d0fe62de5fef5f895903f27a 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: t_imm_api.c,v 1.15 2001/06/04 16:09:28 keithw Exp $ */
+/* $Id: t_imm_api.c,v 1.16 2001/06/15 15:22:08 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -543,12 +543,14 @@ _tnl_Indexiv( const GLint *c )
 #define NORMALF( x, y, z )                                     \
 {                                                              \
    GLuint count;                                               \
-   GLint *normal;                                              \
+   fi_type *normal;                                            \
    GET_IMMEDIATE;                                              \
    count = IM->Count;                                          \
    IM->Flag[count] |= VERT_NORM;                               \
-   normal = (GLint *)IM->Normal[count];                                \
-   ASSIGN_3V(normal, *(int*)&(x), *(int*)&(y), *(int*)&(z));   \
+   normal = (fi_type *)IM->Normal[count];                      \
+   normal[0].i = ((fi_type *)&(x))->i;                         \
+   normal[1].i = ((fi_type *)&(y))->i;                         \
+   normal[2].i = ((fi_type *)&(z))->i;                         \
 }
 #else
 #define NORMALF NORMAL
@@ -616,18 +618,18 @@ _tnl_Normal3fv( const GLfloat *v )
 }
 
 #if defined(USE_IEEE)
-#define TEXCOORD2F(s,t)                                \
-{                                              \
-   GLuint count;                               \
-   GLint *tc;                                  \
-   GET_IMMEDIATE;                              \
-   count = IM->Count;                          \
-   IM->Flag[count] |= VERT_TEX0;               \
-   tc = (GLint *)IM->TexCoord0[count];         \
-   tc[0] = *(GLint *)&(s);                     \
-   tc[1] = *(GLint *)&(t);                     \
-   tc[2] = 0;                                  \
-   tc[3] = IEEE_ONE;                           \
+#define TEXCOORD2F(s,t)                                        \
+{                                                      \
+   GLuint count;                                       \
+   fi_type *tc;                                                \
+   GET_IMMEDIATE;                                      \
+   count = IM->Count;                                  \
+   IM->Flag[count] |= VERT_TEX0;                       \
+   tc = (fi_type *)IM->TexCoord0[count];               \
+   tc[0].i = ((fi_type *)&(s))->i;                     \
+   tc[1].i = ((fi_type *)&(t))->i;                     \
+   tc[2].i = 0;                                                \
+   tc[3].i = IEEE_ONE;                                 \
 }
 #else
 #define TEXCOORD2F TEXCOORD2
@@ -721,53 +723,53 @@ _tnl_TexCoord4fv( const GLfloat *v )
 }
 
 #if defined(USE_IEEE)
-#define VERTEX2F(IM, x, y)                     \
-{                                              \
-   GLuint count = IM->Count++;                 \
-   GLint *dest = (GLint *)IM->Obj[count];      \
-   IM->Flag[count] |= VERT_OBJ;                \
-   dest[0] = *(GLint *)&(x);                   \
-   dest[1] = *(GLint *)&(y);                   \
-   dest[2] = 0;                                        \
-   dest[3] = IEEE_ONE;                         \
+#define VERTEX2F(IM, x, y)                             \
+{                                                      \
+   GLuint count = IM->Count++;                         \
+   fi_type *dest = (fi_type *)IM->Obj[count];          \
+   IM->Flag[count] |= VERT_OBJ;                        \
+   dest[0].i = ((fi_type *)&(x))->i;                   \
+   dest[1].i = ((fi_type *)&(y))->i;                   \
+   dest[2].i = 0;                                      \
+   dest[3].i = IEEE_ONE;                               \
 /*     ASSERT(IM->Flag[IM->Count]==0); */              \
    if (count == IMM_MAXDATA - 1)                       \
-      _tnl_flush_immediate( IM );              \
+      _tnl_flush_immediate( IM );                      \
 }
 #else
 #define VERTEX2F VERTEX2
 #endif
 
 #if defined(USE_IEEE)
-#define VERTEX3F(IM, x, y, z)                  \
-{                                              \
-   GLuint count = IM->Count++;                 \
-   GLint *dest = (GLint *)IM->Obj[count];      \
-   IM->Flag[count] |= VERT_OBJ_23;             \
-   dest[0] = *(GLint *)&(x);                   \
-   dest[1] = *(GLint *)&(y);                   \
-   dest[2] = *(GLint *)&(z);                   \
-   dest[3] = IEEE_ONE;                         \
-/*     ASSERT(IM->Flag[IM->Count]==0);  */     \
+#define VERTEX3F(IM, x, y, z)                          \
+{                                                      \
+   GLuint count = IM->Count++;                         \
+   fi_type *dest = (fi_type *)IM->Obj[count];          \
+   IM->Flag[count] |= VERT_OBJ_23;                     \
+   dest[0].i = ((fi_type *)&(x))->i;                   \
+   dest[1].i = ((fi_type *)&(y))->i;                   \
+   dest[2].i = ((fi_type *)&(z))->i;                   \
+   dest[3].i = IEEE_ONE;                               \
+/*     ASSERT(IM->Flag[IM->Count]==0);  */             \
    if (count == IMM_MAXDATA - 1)                       \
-      _tnl_flush_immediate( IM );              \
+      _tnl_flush_immediate( IM );                      \
 }
 #else
 #define VERTEX3F VERTEX3
 #endif
 
 #if defined(USE_IEEE)
-#define VERTEX4F(IM, x, y, z, w)               \
-{                                              \
-   GLuint count = IM->Count++;                 \
-   GLint *dest = (GLint *)IM->Obj[count];      \
-   IM->Flag[count] |= VERT_OBJ_234;            \
-   dest[0] = *(GLint *)&(x);                   \
-   dest[1] = *(GLint *)&(y);                   \
-   dest[2] = *(GLint *)&(z);                   \
-   dest[3] = *(GLint *)&(w);                   \
+#define VERTEX4F(IM, x, y, z, w)                       \
+{                                                      \
+   GLuint count = IM->Count++;                         \
+   fi_type *dest = (fi_type *)IM->Obj[count];          \
+   IM->Flag[count] |= VERT_OBJ_234;                    \
+   dest[0].i = ((fi_type *)&(x))->i;                   \
+   dest[1].i = ((fi_type *)&(y))->i;                   \
+   dest[2].i = ((fi_type *)&(z))->i;                   \
+   dest[3].i = ((fi_type *)&(w))->i;                   \
    if (count == IMM_MAXDATA - 1)                       \
-      _tnl_flush_immediate( IM );              \
+      _tnl_flush_immediate( IM );                      \
 }
 #else
 #define VERTEX4F VERTEX4
@@ -886,12 +888,12 @@ _tnl_Vertex4fv( const GLfloat *v )
    GLuint texunit = target - GL_TEXTURE0_ARB;                  \
    if (texunit < IM->MaxTextureUnits) {                                \
       GLuint count = IM->Count;                                        \
-      GLint *tc = (GLint *)IM->TexCoord[texunit][count];       \
+      fi_type *tc = (fi_type *)IM->TexCoord[texunit][count];   \
       IM->Flag[count] |= VERT_TEX(texunit);                    \
-      tc[0] = *(int *)&(s);                                    \
-      tc[1] = *(int *)&(t);                                    \
-      tc[2] = 0;                                               \
-      tc[3] = IEEE_ONE;                                                \
+      tc[0].i = ((fi_type *)&(s))->i;                          \
+      tc[1].i = ((fi_type *)&(t))->i;                          \
+      tc[2].i = 0;                                             \
+      tc[3].i = IEEE_ONE;                                      \
    }                                                           \
 }
 #else
index 414c6bd34ab20c205cad1085f28a60bfc45c6390..ec3cb02bb66869dce05d1b7a8a45546f5f7d1831 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: t_vb_render.c,v 1.20 2001/05/11 15:53:06 keithw Exp $ */
+/* $Id: t_vb_render.c,v 1.21 2001/06/15 15:22:08 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -69,8 +69,8 @@
 
 
 #if defined(USE_IEEE)
-#define NEGATIVE(x) ((*(GLuint *)&x) & (1<<31))
-#define DIFFERENT_SIGNS(x,y) (((*(GLuint *)&x)^(*(GLuint *)&y)) & (1<<31))
+#define NEGATIVE(x) (GET_FLOAT_BITS(x) & (1<<31))
+#define DIFFERENT_SIGNS(x,y) ((GET_FLOAT_BITS(x) ^ GET_FLOAT_BITS(y)) & (1<<31))
 #else
 #define NEGATIVE(x) (x < 0)
 #define DIFFERENT_SIGNS(x,y) (x * y <= 0 && x - y != 0)