]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/dist: sse auto-detect
authorRuss Cox <rsc@golang.org>
Fri, 4 Jan 2013 15:59:10 +0000 (10:59 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 4 Jan 2013 15:59:10 +0000 (10:59 -0500)
R=golang-dev, dsymonds, minux.ma, iant, alex.brainman
CC=golang-dev
https://golang.org/cl/7035055

src/cmd/dist/a.h
src/cmd/dist/build.c
src/cmd/dist/plan9.c
src/cmd/dist/unix.c
src/cmd/dist/windows.c

index f6d90df638a4ad1f9d16ac9a2ad5bfeef64ee970..7c6516dab63b35c820f1fe4eab8e15867cb24595 100644 (file)
@@ -123,6 +123,7 @@ void        runv(Buf *b, char *dir, int mode, Vec *argv);
 void   bgrunv(char *dir, int mode, Vec *argv);
 void   bgwait(void);
 bool   streq(char*, char*);
+bool   cansse(void);
 void   writefile(Buf*, char*, int);
 void   xatexit(void (*f)(void));
 void   xexit(int);
index 4749a1615732496a384cb07c2e7ce787a709f039..2dc3b9ba4eb88518a8c3dc06720ea1977890fcd9 100644 (file)
@@ -104,8 +104,12 @@ init(void)
        goarm = btake(&b);
 
        xgetenv(&b, "GO386");
-       if(b.len == 0)
-               bwritestr(&b, "387");
+       if(b.len == 0) {
+               if(cansse())
+                       bwritestr(&b, "sse");
+               else
+                       bwritestr(&b, "387");
+       }
        go386 = btake(&b);
 
        p = bpathf(&b, "%s/include/u.h", goroot);
index 5bf2c3736d67cf06a2aa9d742d715bf735fefa72..8fef74f95df26b02f37ee056731c60697dd01033 100644 (file)
@@ -758,4 +758,12 @@ xtryexecfunc(void (*f)(void))
        return 0; // suffice for now
 }
 
+bool
+cansse(void)
+{
+       // if we had access to cpuid, could answer this question
+       // less conservatively.
+       return 0;
+}
+
 #endif // PLAN9
index b82bf1ddbd9bca9fd769fd8b4b493388c25b4be3..a99e5bfc4605187574afe35f191dcb57c0fa9afd 100644 (file)
@@ -741,6 +741,7 @@ xsamefile(char *f1, char *f2)
 
 sigjmp_buf sigill_jmpbuf;
 static void sigillhand(int);
+
 // xtryexecfunc tries to execute function f, if any illegal instruction
 // signal received in the course of executing that function, it will
 // return 0, otherwise it will return 1.
@@ -757,6 +758,7 @@ xtryexecfunc(void (*f)(void))
        signal(SIGILL, SIG_DFL);
        return r;
 }
+
 // SIGILL handler helper
 static void
 sigillhand(int signum)
@@ -765,5 +767,26 @@ sigillhand(int signum)
        siglongjmp(sigill_jmpbuf, 1);
 }
 
+static void
+__cpuid(int dst[4], int ax)
+{
+#if defined(__i386__) || defined(__x86_64__)
+       asm volatile("cpuid"
+               : "=a" (dst[0]), "=b" (dst[1]), "=c" (dst[2]), "=d" (dst[3])
+               : "0" (ax));
+#else
+       dst[0] = dst[1] = dst[2] = dst[3] = 0;
+#endif
+}
+
+bool
+cansse(void)
+{
+       int info[4];
+       
+       __cpuid(info, 1);
+       return (info[3] & (1<<26)) != 0;        // SSE2
+}
+
 #endif // PLAN9
 #endif // __WINDOWS__
index 37f8ea02ec6ed7ec4df288ba42d0b1885949d52f..4edb39cb586dcd2ecd223b4ccf45d5fd36c610f9 100644 (file)
@@ -971,4 +971,29 @@ xtryexecfunc(void (*f)(void))
        return 0; // suffice for now
 }
 
+static void
+cpuid(int dst[4], int ax)
+{
+       // NOTE: This asm statement is for mingw.
+       // If we ever support MSVC, use __cpuid(dst, ax)
+       // to use the built-in.
+#if defined(__i386__) || defined(__x86_64__)
+       asm volatile("cpuid"
+               : "=a" (dst[0]), "=b" (dst[1]), "=c" (dst[2]), "=d" (dst[3])
+               : "0" (ax));
+#else
+       dst[0] = dst[1] = dst[2] = dst[3] = 0;
+#endif
+}
+
+bool
+cansse(void)
+{
+       int info[4];
+       
+       cpuid(info, 1);
+       return (info[3] & (1<<26)) != 0;        // SSE2
+}
+
+
 #endif // __WINDOWS__