diff options
author | S. Gilles <sgilles@math.umd.edu> | 2018-03-13 05:07:24 -0400 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2018-03-20 21:02:00 -0700 |
commit | 65c3b339b547b49d1c1d11c56d86ca81f756e9be (patch) | |
tree | 14d9e0b004daab16e7bc5a73fa491959b689129c /mbld | |
parent | 40503a54ab7d481d67807eb35b2c359379a8415a (diff) | |
download | mc-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.
Diffstat (limited to 'mbld')
-rw-r--r-- | mbld/bld.sub | 1 | ||||
-rw-r--r-- | mbld/cpufeatures+x64.s | 10 | ||||
-rw-r--r-- | mbld/opts.myr | 12 | ||||
-rw-r--r-- | mbld/syssel.myr | 10 |
4 files changed, 29 insertions, 4 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) ;; |