mirror of
https://github.com/golang/go
synced 2024-11-23 05:10:09 -07:00
cmd/dist: sse auto-detect
R=golang-dev, dsymonds, minux.ma, iant, alex.brainman CC=golang-dev https://golang.org/cl/7035055
This commit is contained in:
parent
63bee953a2
commit
a4e08183d5
1
src/cmd/dist/a.h
vendored
1
src/cmd/dist/a.h
vendored
@ -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);
|
||||||
|
8
src/cmd/dist/build.c
vendored
8
src/cmd/dist/build.c
vendored
@ -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) {
|
||||||
bwritestr(&b, "387");
|
if(cansse())
|
||||||
|
bwritestr(&b, "sse");
|
||||||
|
else
|
||||||
|
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);
|
||||||
|
8
src/cmd/dist/plan9.c
vendored
8
src/cmd/dist/plan9.c
vendored
@ -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
|
||||||
|
23
src/cmd/dist/unix.c
vendored
23
src/cmd/dist/unix.c
vendored
@ -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))
|
|||||||
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)
|
|||||||
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__
|
||||||
|
25
src/cmd/dist/windows.c
vendored
25
src/cmd/dist/windows.c
vendored
@ -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__
|
||||||
|
Loading…
Reference in New Issue
Block a user