Commit a4e08183 authored by Russ Cox's avatar Russ Cox

cmd/dist: sse auto-detect

R=golang-dev, dsymonds, minux.ma, iant, alex.brainman
CC=golang-dev
https://golang.org/cl/7035055
parent 63bee953
...@@ -123,6 +123,7 @@ void runv(Buf *b, char *dir, int mode, Vec *argv); ...@@ -123,6 +123,7 @@ void runv(Buf *b, char *dir, int mode, Vec *argv);
void bgrunv(char *dir, int mode, Vec *argv); void bgrunv(char *dir, int mode, Vec *argv);
void bgwait(void); void bgwait(void);
bool streq(char*, char*); bool streq(char*, char*);
bool cansse(void);
void writefile(Buf*, char*, int); void writefile(Buf*, char*, int);
void xatexit(void (*f)(void)); void xatexit(void (*f)(void));
void xexit(int); void xexit(int);
......
...@@ -104,8 +104,12 @@ init(void) ...@@ -104,8 +104,12 @@ init(void)
goarm = btake(&b); goarm = btake(&b);
xgetenv(&b, "GO386"); xgetenv(&b, "GO386");
if(b.len == 0) if(b.len == 0) {
if(cansse())
bwritestr(&b, "sse");
else
bwritestr(&b, "387"); bwritestr(&b, "387");
}
go386 = btake(&b); go386 = btake(&b);
p = bpathf(&b, "%s/include/u.h", goroot); p = bpathf(&b, "%s/include/u.h", goroot);
......
...@@ -758,4 +758,12 @@ xtryexecfunc(void (*f)(void)) ...@@ -758,4 +758,12 @@ xtryexecfunc(void (*f)(void))
return 0; // suffice for now return 0; // suffice for now
} }
bool
cansse(void)
{
// if we had access to cpuid, could answer this question
// less conservatively.
return 0;
}
#endif // PLAN9 #endif // PLAN9
...@@ -741,6 +741,7 @@ xsamefile(char *f1, char *f2) ...@@ -741,6 +741,7 @@ xsamefile(char *f1, char *f2)
sigjmp_buf sigill_jmpbuf; sigjmp_buf sigill_jmpbuf;
static void sigillhand(int); static void sigillhand(int);
// xtryexecfunc tries to execute function f, if any illegal instruction // xtryexecfunc tries to execute function f, if any illegal instruction
// signal received in the course of executing that function, it will // signal received in the course of executing that function, it will
// return 0, otherwise it will return 1. // return 0, otherwise it will return 1.
...@@ -757,6 +758,7 @@ xtryexecfunc(void (*f)(void)) ...@@ -757,6 +758,7 @@ xtryexecfunc(void (*f)(void))
signal(SIGILL, SIG_DFL); signal(SIGILL, SIG_DFL);
return r; return r;
} }
// SIGILL handler helper // SIGILL handler helper
static void static void
sigillhand(int signum) sigillhand(int signum)
...@@ -765,5 +767,26 @@ sigillhand(int signum) ...@@ -765,5 +767,26 @@ sigillhand(int signum)
siglongjmp(sigill_jmpbuf, 1); 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 // PLAN9
#endif // __WINDOWS__ #endif // __WINDOWS__
...@@ -971,4 +971,29 @@ xtryexecfunc(void (*f)(void)) ...@@ -971,4 +971,29 @@ xtryexecfunc(void (*f)(void))
return 0; // suffice for now 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__ #endif // __WINDOWS__
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment