[Mesa-dev] [PATCH] i965: Compile the driver with -march/-mtune appropriate for the HW.

Eric Anholt eric at anholt.net
Mon Jan 28 16:55:51 PST 2013


While most of our development and testing is on x86-64, some of our
major consumers of the driver are on i386 still.  On i386, the compiler
defaults to maximum compatibility, so we aren't taking advantage of cmov
instructions or SSE for floating point math, unless the user went out of
their way to choose a -march flag (unlikely).

Our driver can only get probed on G965 and newer chipsets, which only
support in the worst case the P4 EE CPUs like SL7AA that only do up to
SSE2.  This means that we can't rely on SSE3, but we can use SSE2
instructions even while tuning for core2 pipelines.

v2: Drop down to p4-compatible -march, while retaining tuning for core2.
    Also add -mfpmath=sse2 to use sse where possible within the driver
    (though it doesn't extend into Mesa core)
---

I also dropped the commit message about performance, since I haven't
retested with the new flags due to being away at LCA.  Thanks to Roland
for tracking down the actual worst-case CPUwe'.

 configure.ac                          |   19 +++++++++++++++++++
 src/mesa/drivers/dri/i965/Makefile.am |    3 ++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 1e352db..cf50d89 100644
--- a/configure.ac
+++ b/configure.ac
@@ -492,6 +492,25 @@ if test "x$enable_asm" = xyes; then
 fi
 AC_SUBST([MESA_ASM_FILES])
 
+# If the user hasn't set an explicit -march flag, then autodetect a set for
+# use by the i965 driver.  The driver can only be probed on G965 and newer,
+# which only supports P4s and better (though most installed CPUs are core2s).
+if echo $CFLAGS | grep -v march > /dev/null; then
+    case "$host_cpu" in
+        i?86 | x86_64)
+            save_CFLAGS="$CFLAGS"
+            MARCHFLAGS="-march=pentium4 -mtune=core2 -mfpmath=sse"
+            AC_MSG_CHECKING([whether $CC supports $MARCHFLAGS])
+            CFLAGS="$save_CFLAGS $MARCHFLAGS"
+            AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[]])],
+                              [AC_MSG_RESULT([yes]); MARCH_I965="$MARCHFLAGS"],
+                              [AC_MSG_RESULT([no]); MARCH_I965=""])
+            CFLAGS="$save_CFLAGS"
+            ;;
+    esac
+fi
+AC_SUBST([MARCH_I965])
+
 dnl Check to see if dlopen is in default libraries (like Solaris, which
 dnl has it in libc), or if libdl is needed to get it.
 AC_CHECK_FUNC([dlopen], [DEFINES="$DEFINES -DHAVE_DLOPEN"],
diff --git a/src/mesa/drivers/dri/i965/Makefile.am b/src/mesa/drivers/dri/i965/Makefile.am
index dc140df..e057b54 100644
--- a/src/mesa/drivers/dri/i965/Makefile.am
+++ b/src/mesa/drivers/dri/i965/Makefile.am
@@ -38,7 +38,8 @@ AM_CFLAGS = \
 	$(DEFINES) \
 	$(API_DEFINES) \
 	$(VISIBILITY_CFLAGS) \
-	$(INTEL_CFLAGS)
+	$(INTEL_CFLAGS) \
+	$(MARCH_I965)
 
 AM_CXXFLAGS = $(AM_CFLAGS)
 
-- 
1.7.10.4



More information about the mesa-dev mailing list