summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorS. Gilles <sgilles@math.umd.edu>2018-03-13 05:07:24 -0400
committerOri Bernstein <ori@eigenstate.org>2018-03-20 21:02:00 -0700
commit65c3b339b547b49d1c1d11c56d86ca81f756e9be (patch)
tree14d9e0b004daab16e7bc5a73fa491959b689129c
parent40503a54ab7d481d67807eb35b2c359379a8415a (diff)
downloadmc-65c3b339b547b49d1c1d11c56d86ca81f756e9be.tar.gz
Allow CPU feature detection by mbld, and add "sse4" tag
This allows writing graceful degradation of optimizations. In practice, it justifies less-than-optimal floating point implementations by allowing a portable upgrade path through AVX, SIMD, &c. Bootstrap scripts are updated by genboostrap.sh on Linux+amd64, and by hand on all others.
-rw-r--r--mbld/bld.sub1
-rw-r--r--mbld/cpufeatures+x64.s10
-rw-r--r--mbld/opts.myr12
-rw-r--r--mbld/syssel.myr10
-rwxr-xr-xmk/bootstrap/bootstrap+Darwin-x86_64.sh3
-rwxr-xr-xmk/bootstrap/bootstrap+FreeBSD-amd64.sh3
-rwxr-xr-xmk/bootstrap/bootstrap+Linux-x86_64.sh3
-rwxr-xr-xmk/bootstrap/bootstrap+NetBSD-amd64.sh3
-rwxr-xr-xmk/bootstrap/bootstrap+OpenBSD-amd64.sh3
-rwxr-xr-xmk/bootstrap/bootstrap+Plan9-amd64.sh3
10 files changed, 41 insertions, 10 deletions
diff --git a/mbld/bld.sub b/mbld/bld.sub
index 15ad4cf..7374bb3 100644
--- a/mbld/bld.sub
+++ b/mbld/bld.sub
@@ -1,5 +1,6 @@
bin mbld =
build.myr
+ cpufeatures+x64.s
deps.myr
libs.myr
install.myr
diff --git a/mbld/cpufeatures+x64.s b/mbld/cpufeatures+x64.s
new file mode 100644
index 0000000..8202ca1
--- /dev/null
+++ b/mbld/cpufeatures+x64.s
@@ -0,0 +1,10 @@
+.globl bld$cpufeatures
+.globl bld$_cpufeatures
+bld$cpufeatures:
+bld$_cpufeatures:
+ mov $0x1, %eax
+ cpuid
+ mov %ecx, %eax
+ rol $32, %rax
+ shrd $32, %rdx, %rax
+ ret
diff --git a/mbld/opts.myr b/mbld/opts.myr
index a4679c7..b82921f 100644
--- a/mbld/opts.myr
+++ b/mbld/opts.myr
@@ -7,6 +7,7 @@ pkg bld =
var opt_arch : byte[:]
var opt_sys : byte[:]
var opt_sysvers : (int, int, int)
+ var opt_cpufeatures : uint64
var opt_runtime : byte[:]
var opt_genasm : bool
var opt_incpaths : byte[:][:]
@@ -31,14 +32,19 @@ pkg bld =
const initopts : (-> void)
const parseversion : (v : byte[:] -> (int, int, int))
+
+ /* not exactly portable, but good enough for now */
+ const CpuidSSE4 : uint64= 0x180000
+ extern const cpufeatures : (-> uint64)
;;
var opt_arch = ""
var opt_sys = ""
var opt_binname = ""
+var opt_cpufeatures = 0ul
var opt_libname = ""
var opt_runtime = ""
-var opt_incpaths /* FIXME: taking a constant slice is a nonconstant initializer */
+var opt_incpaths = [][:]
var opt_instbase = ""
var opt_destdir = ""
var opt_sysvers
@@ -77,8 +83,10 @@ const initopts = {
| unknown: std.fatal("unknown architecture \"{}\"\n", unknown)
;;
+ /* from cpuid with EAX=1; EDX at top, ECX at bottom */
+ opt_cpufeatures = cpufeatures()
+
opt_maxproc = 2*(thread.ncpu() : std.size)
- opt_incpaths = [][:]
opt_instbase = config.Instroot
opt_destdir = std.getenvv("DESTDIR", "")
opt_mc = std.getenvv("MYR_MC", "6m")
diff --git a/mbld/syssel.myr b/mbld/syssel.myr
index f1452dc..756cf4d 100644
--- a/mbld/syssel.myr
+++ b/mbld/syssel.myr
@@ -160,9 +160,15 @@ const addsysattrs = {b, tags
;;
match opt_arch
- | "x64": tag(b, "x64")
- | unknown: std.fatal("unknown architecture {}\n", unknown)
+ | "x64":
+ tag(b, "x64")
+ if opt_cpufeatures & CpuidSSE4 == CpuidSSE4
+ tag(b, "sse4")
+ ;;
+ | unknown:
+ std.fatal("unknown architecture {}\n", unknown)
;;
+
for t : tags
tag(b, t)
;;
diff --git a/mk/bootstrap/bootstrap+Darwin-x86_64.sh b/mk/bootstrap/bootstrap+Darwin-x86_64.sh
index 276c6c7..ae2dbce 100755
--- a/mk/bootstrap/bootstrap+Darwin-x86_64.sh
+++ b/mk/bootstrap/bootstrap+Darwin-x86_64.sh
@@ -4,6 +4,7 @@
pwd=`pwd`
set -x
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/config.myr
+ as -g -o mbld/cpufeatures.o mbld/cpufeatures+x64.s
as -g -o lib/thread/start.o lib/thread/start+osx-x64.s
as -g -o lib/thread/atomic-impl.o lib/thread/atomic-impl+x64.s
as -g -o lib/std/getbp.o lib/std/getbp+posixy-x64.s
@@ -140,5 +141,5 @@ set -x
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/test.myr
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/deps.myr
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/main.myr
- ld -pagezero_size 0x100000000 -macosx_version_min 10.6 -o mbld/mbld $pwd/rt/_myrrt.o mbld/deps.o mbld/main.o mbld/util.o mbld/libs.o mbld/syssel.o mbld/config.o mbld/opts.o mbld/subtest.o mbld/types.o mbld/test.o mbld/install.o mbld/parse.o mbld/build.o -Llib/thread -lthread -Llib/bio -lbio -Llib/regex -lregex -Llib/std -lstd -Llib/sys -lsys -macosx_version_min 10.6
+ ld -pagezero_size 0x100000000 -macosx_version_min 10.6 -o mbld/mbld $pwd/rt/_myrrt.o mbld/deps.o mbld/main.o mbld/util.o mbld/cpufeatures.o mbld/libs.o mbld/syssel.o mbld/config.o mbld/opts.o mbld/subtest.o mbld/types.o mbld/test.o mbld/install.o mbld/parse.o mbld/build.o -Llib/thread -lthread -Llib/bio -lbio -Llib/regex -lregex -Llib/std -lstd -Llib/sys -lsys -macosx_version_min 10.6
true
diff --git a/mk/bootstrap/bootstrap+FreeBSD-amd64.sh b/mk/bootstrap/bootstrap+FreeBSD-amd64.sh
index 3117a4c..63c27dc 100755
--- a/mk/bootstrap/bootstrap+FreeBSD-amd64.sh
+++ b/mk/bootstrap/bootstrap+FreeBSD-amd64.sh
@@ -4,6 +4,7 @@
pwd=`pwd`
set -x
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/config.myr
+ as -g -o mbld/cpufeatures.o mbld/cpufeatures+x64.s
as -g -o lib/thread/exit.o lib/thread/exit+freebsd-x64.s
as -g -o lib/thread/atomic-impl.o lib/thread/atomic-impl+x64.s
as -g -o lib/std/getbp.o lib/std/getbp+posixy-x64.s
@@ -141,5 +142,5 @@ set -x
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/test.myr
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/deps.myr
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/main.myr
- ld --gc-sections -o mbld/mbld $pwd/rt/_myrrt.o mbld/deps.o mbld/main.o mbld/util.o mbld/libs.o mbld/syssel.o mbld/config.o mbld/opts.o mbld/subtest.o mbld/types.o mbld/test.o mbld/install.o mbld/parse.o mbld/build.o -Llib/thread -lthread -Llib/bio -lbio -Llib/regex -lregex -Llib/std -lstd -Llib/sys -lsys
+ ld --gc-sections -o mbld/mbld $pwd/rt/_myrrt.o mbld/deps.o mbld/main.o mbld/util.o mbld/cpufeatures.o mbld/libs.o mbld/syssel.o mbld/config.o mbld/opts.o mbld/subtest.o mbld/types.o mbld/test.o mbld/install.o mbld/parse.o mbld/build.o -Llib/thread -lthread -Llib/bio -lbio -Llib/regex -lregex -Llib/std -lstd -Llib/sys -lsys
true
diff --git a/mk/bootstrap/bootstrap+Linux-x86_64.sh b/mk/bootstrap/bootstrap+Linux-x86_64.sh
index c6d4da8..91c5c38 100755
--- a/mk/bootstrap/bootstrap+Linux-x86_64.sh
+++ b/mk/bootstrap/bootstrap+Linux-x86_64.sh
@@ -4,6 +4,7 @@
pwd=`pwd`
set -x
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/config.myr
+ as -g -o mbld/cpufeatures.o mbld/cpufeatures+x64.s
as -g -o lib/thread/exit.o lib/thread/exit+linux-x64.s
as -g -o lib/thread/atomic-impl.o lib/thread/atomic-impl+x64.s
as -g -o lib/std/getbp.o lib/std/getbp+posixy-x64.s
@@ -141,5 +142,5 @@ set -x
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/test.myr
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/deps.myr
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/main.myr
- ld --gc-sections -o mbld/mbld $pwd/rt/_myrrt.o mbld/deps.o mbld/main.o mbld/util.o mbld/libs.o mbld/syssel.o mbld/config.o mbld/opts.o mbld/subtest.o mbld/types.o mbld/test.o mbld/install.o mbld/parse.o mbld/build.o -Llib/thread -lthread -Llib/bio -lbio -Llib/regex -lregex -Llib/std -lstd -Llib/sys -lsys
+ ld --gc-sections -o mbld/mbld $pwd/rt/_myrrt.o mbld/deps.o mbld/main.o mbld/util.o mbld/cpufeatures.o mbld/libs.o mbld/syssel.o mbld/config.o mbld/opts.o mbld/subtest.o mbld/types.o mbld/test.o mbld/install.o mbld/parse.o mbld/build.o -Llib/thread -lthread -Llib/bio -lbio -Llib/regex -lregex -Llib/std -lstd -Llib/sys -lsys
true
diff --git a/mk/bootstrap/bootstrap+NetBSD-amd64.sh b/mk/bootstrap/bootstrap+NetBSD-amd64.sh
index 5440a84..54d79c4 100755
--- a/mk/bootstrap/bootstrap+NetBSD-amd64.sh
+++ b/mk/bootstrap/bootstrap+NetBSD-amd64.sh
@@ -4,6 +4,7 @@
pwd=`pwd`
set -x
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/config.myr
+ as -g -o mbld/cpufeatures.o mbld/cpufeatures+x64.s
as -g -o lib/thread/atomic-impl.o lib/thread/atomic-impl+x64.s
as -g -o lib/std/getbp.o lib/std/getbp+posixy-x64.s
$pwd/6/6m -I . -I lib/sys lib/std/option.myr
@@ -139,5 +140,5 @@ set -x
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/test.myr
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/deps.myr
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/main.myr
- ld -o mbld/mbld $pwd/rt/_myrrt.o mbld/deps.o mbld/main.o mbld/util.o mbld/libs.o mbld/syssel.o mbld/config.o mbld/opts.o mbld/subtest.o mbld/types.o mbld/test.o mbld/install.o mbld/parse.o mbld/build.o -Llib/thread -lthread -Llib/bio -lbio -Llib/regex -lregex -Llib/std -lstd -Llib/sys -lsys
+ ld -o mbld/mbld $pwd/rt/_myrrt.o mbld/deps.o mbld/main.o mbld/util.o mbld/cpufeatures.o mbld/libs.o mbld/syssel.o mbld/config.o mbld/opts.o mbld/subtest.o mbld/types.o mbld/test.o mbld/install.o mbld/parse.o mbld/build.o -Llib/thread -lthread -Llib/bio -lbio -Llib/regex -lregex -Llib/std -lstd -Llib/sys -lsys
true
diff --git a/mk/bootstrap/bootstrap+OpenBSD-amd64.sh b/mk/bootstrap/bootstrap+OpenBSD-amd64.sh
index 5ac4a07..ecda364 100755
--- a/mk/bootstrap/bootstrap+OpenBSD-amd64.sh
+++ b/mk/bootstrap/bootstrap+OpenBSD-amd64.sh
@@ -4,6 +4,7 @@
pwd=`pwd`
set -x
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/config.myr
+ as -g -o mbld/cpufeatures.o mbld/cpufeatures+x64.s
as -g -o lib/thread/exit.o lib/thread/exit+openbsd-x64.s
as -g -o lib/thread/atomic-impl.o lib/thread/atomic-impl+x64.s
as -g -o lib/std/getbp.o lib/std/getbp+posixy-x64.s
@@ -141,5 +142,5 @@ set -x
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/test.myr
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/deps.myr
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/main.myr
- ld -nopie --gc-sections -o mbld/mbld $pwd/rt/_myrrt.o mbld/deps.o mbld/main.o mbld/util.o mbld/libs.o mbld/syssel.o mbld/config.o mbld/opts.o mbld/subtest.o mbld/types.o mbld/test.o mbld/install.o mbld/parse.o mbld/build.o -Llib/thread -lthread -Llib/bio -lbio -Llib/regex -lregex -Llib/std -lstd -Llib/sys -lsys
+ ld -nopie --gc-sections -o mbld/mbld $pwd/rt/_myrrt.o mbld/deps.o mbld/main.o mbld/util.o mbld/cpufeatures+x64.s mbld/libs.o mbld/syssel.o mbld/config.o mbld/opts.o mbld/subtest.o mbld/types.o mbld/test.o mbld/install.o mbld/parse.o mbld/build.o -Llib/thread -lthread -Llib/bio -lbio -Llib/regex -lregex -Llib/std -lstd -Llib/sys -lsys
true
diff --git a/mk/bootstrap/bootstrap+Plan9-amd64.sh b/mk/bootstrap/bootstrap+Plan9-amd64.sh
index 4da0e61..8b45e53 100755
--- a/mk/bootstrap/bootstrap+Plan9-amd64.sh
+++ b/mk/bootstrap/bootstrap+Plan9-amd64.sh
@@ -4,6 +4,7 @@
pwd=`pwd`
set -x
$pwd/6/6.out -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/config+plan9-x64.myr
+ 6a -o mbld/cpufeatures.6 mbld/cpufeatures+x64.s
6a -o lib/thread/atomic-impl.6 lib/thread/atomic-impl+plan9-x64.s
6a -o lib/std/getbp.6 lib/std/getbp+plan9-x64.s
$pwd/6/6.out -I lib/sys lib/std/errno+plan9.myr
@@ -138,5 +139,5 @@ set -x
$pwd/6/6.out -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/test.myr
$pwd/6/6.out -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/deps.myr
$pwd/6/6.out -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/main.myr
- 6l -l -o mbld/mbld $pwd/rt/_myrrt.6 mbld/deps.6 mbld/main.6 mbld/util.6 mbld/libs.6 mbld/syssel.6 mbld/config.6 mbld/opts.6 mbld/subtest.6 mbld/types.6 mbld/test.6 mbld/install.6 mbld/parse.6 mbld/build.6 lib/thread/libthread.a lib/bio/libbio.a lib/regex/libregex.a lib/std/libstd.a lib/sys/libsys.a
+ 6l -l -o mbld/mbld $pwd/rt/_myrrt.6 mbld/deps.6 mbld/main.6 mbld/util.6 mbld/cpufeatures.6 mbld/libs.6 mbld/syssel.6 mbld/config.6 mbld/opts.6 mbld/subtest.6 mbld/types.6 mbld/test.6 mbld/install.6 mbld/parse.6 mbld/build.6 lib/thread/libthread.a lib/bio/libbio.a lib/regex/libregex.a lib/std/libstd.a lib/sys/libsys.a
true