From 921e8234ff65bd23c0b94ed568ec1fb68e47655b Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 16 Nov 2017 14:28:28 +0200 Subject: [PATCH] Add FPU specification to Architecture and GnuCompiler --- source/architecture.cpp | 22 +++++++++++++++++++++- source/architecture.h | 2 ++ source/gnucompiler.cpp | 15 +++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/source/architecture.cpp b/source/architecture.cpp index fe00338..627ba66 100644 --- a/source/architecture.cpp +++ b/source/architecture.cpp @@ -42,6 +42,15 @@ const char *cpus[] = 0 }; +const char *fpus[] = +{ + "387", "x86", + "sse", "x86", + "vfpv3", "arm", + "neon", "arm", + 0 +}; + const char *systems[] = { "linux", @@ -116,6 +125,8 @@ Architecture::Architecture(Builder &b, const string &spec): name = type; if(!cpu.empty()) name += format("-%s", cpu); + if(!fpu.empty()) + name += format("-%s", fpu); name += format("-%d-%s", bits, system); if(system=="windows") @@ -149,7 +160,7 @@ bool Architecture::match_name(const string &pattern) const { if((*i=="32" && bits==32) || (*i=="64" && bits==64)) ; - else if(*i!=type && *i!=cpu && *i!=system) + else if(*i!=type && *i!=cpu && *i!=fpu && *i!=system) return negate; } return !negate; @@ -236,6 +247,15 @@ void Architecture::parse_specification(const string &spec) ok = true; } + for(unsigned j=0; (!ok && fpus[j]); j+=2) + if(*i==fpus[j]) + { + if(fpus[j+1]!=type) + throw invalid_argument("Conflicting FPU specification"); + fpu = *i; + ok = true; + } + for(unsigned j=0; (!ok && systems[j]); ++j) if(*i==systems[j]) { diff --git a/source/architecture.h b/source/architecture.h index 69a6ec9..1532302 100644 --- a/source/architecture.h +++ b/source/architecture.h @@ -26,6 +26,7 @@ private: Builder &builder; std::string type; std::string cpu; + std::string fpu; std::string system; unsigned bits; std::string name; @@ -43,6 +44,7 @@ public: const std::string &get_system() const { return system; } unsigned get_bits() const { return bits; } const std::string &get_cpu() const { return cpu; } + const std::string &get_fpu() const { return fpu; } bool match_name(const std::string &) const; std::string best_match(const std::list &) const; bool is_native() const { return native; } diff --git a/source/gnucompiler.cpp b/source/gnucompiler.cpp index 884776a..816a9a3 100644 --- a/source/gnucompiler.cpp +++ b/source/gnucompiler.cpp @@ -190,6 +190,21 @@ Task *GnuCompiler::run(const Target &target) const argv.push_back("-march="+cpu); } + if(!architecture->get_fpu().empty()) + { + if(architecture->get_type()=="x86") + { + argv.push_back("-mfpmath="+architecture->get_fpu()); + if(architecture->get_fpu()=="sse") + argv.push_back("-msse2"); + } + else if(architecture->get_type()=="arm") + { + argv.push_back("-mfpu="+architecture->get_fpu()); + argv.push_back("-mfloat-abi=softfp"); + } + } + FS::Path obj_path = object.get_path(); FS::Path src_path = object.get_source().get_path(); FS::Path work_dir = object.get_component()->get_package().get_source_directory(); -- 2.45.2