[pkg-d-commits] [ldc] 09/95: Add DMD-compatible pre-defined versions D_SIMD and D_AVX
Matthias Klumpp
mak at moszumanska.debian.org
Thu Jul 13 20:53:55 UTC 2017
This is an automated email from the git hooks/post-receive script.
mak pushed a commit to annotated tag v1.3.0-beta1
in repository ldc.
commit 627b35d680a7bf0317c717809844ea41a9eb5554
Author: Martin <noone at nowhere.com>
Date: Sun Feb 19 01:16:14 2017 +0100
Add DMD-compatible pre-defined versions D_SIMD and D_AVX
---
driver/main.cpp | 14 +++++++++++++-
gen/ldctraits.cpp | 11 +++--------
gen/ldctraits.d | 17 ++++++-----------
gen/ldctraits.h | 28 ++++++++++++++++++++++++++++
4 files changed, 50 insertions(+), 20 deletions(-)
diff --git a/driver/main.cpp b/driver/main.cpp
index b58014a..e566d03 100644
--- a/driver/main.cpp
+++ b/driver/main.cpp
@@ -29,6 +29,7 @@
#include "driver/targetmachine.h"
#include "gen/cl_helpers.h"
#include "gen/irstate.h"
+#include "gen/ldctraits.h"
#include "gen/linkage.h"
#include "gen/llvm.h"
#include "gen/llvmhelpers.h"
@@ -664,7 +665,9 @@ void registerPredefinedFloatABI(const char *soft, const char *hard,
/// Registers the predefined versions specific to the current target triple
/// and other target specific options with VersionCondition.
void registerPredefinedTargetVersions() {
- switch (global.params.targetTriple->getArch()) {
+ const auto arch = global.params.targetTriple->getArch();
+
+ switch (arch) {
case llvm::Triple::x86:
VersionCondition::addPredefinedGlobalIdent("X86");
if (global.params.useInlineAsm) {
@@ -772,6 +775,15 @@ void registerPredefinedTargetVersions() {
VersionCondition::addPredefinedGlobalIdent("D_PIC");
}
+ if (arch == llvm::Triple::x86 || arch == llvm::Triple::x86_64) {
+ if (traitsTargetHasFeature("sse2")) {
+ VersionCondition::addPredefinedGlobalIdent("D_SIMD");
+ }
+ if (traitsTargetHasFeature("avx")) {
+ VersionCondition::addPredefinedGlobalIdent("D_AVX");
+ }
+ }
+
// parse the OS out of the target triple
// see http://gcc.gnu.org/install/specific.html for details
// also llvm's different SubTargets have useful information
diff --git a/gen/ldctraits.cpp b/gen/ldctraits.cpp
index 701378d..22d3ed1 100644
--- a/gen/ldctraits.cpp
+++ b/gen/ldctraits.cpp
@@ -8,18 +8,13 @@
//===----------------------------------------------------------------------===//
#include "gen/irstate.h"
+#include "gen/ldctraits.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/MC/MCSubtargetInfo.h"
-// TODO: move this to a D interfacing helper file
-struct Dstring {
- const char *ptr;
- size_t len;
-};
-
Dstring traitsGetTargetCPU() {
auto cpu = gTargetMachine->getTargetCPU();
- return {cpu.data(), cpu.size()};
+ return {cpu.size(), cpu.data()};
}
bool traitsTargetHasFeature(Dstring feature) {
@@ -28,7 +23,7 @@ bool traitsTargetHasFeature(Dstring feature) {
// return the safe "feature not enabled".
return false;
#else
- auto feat = llvm::StringRef(feature.ptr, feature.len);
+ auto feat = llvm::StringRef(feature.ptr, feature.length);
// This is a work-around to a missing interface in LLVM to query whether a
// feature is set.
diff --git a/gen/ldctraits.d b/gen/ldctraits.d
index 8cdf76b..21af66a 100644
--- a/gen/ldctraits.d
+++ b/gen/ldctraits.d
@@ -6,10 +6,6 @@
// file for details.
//
//===----------------------------------------------------------------------===//
-//
-//
-//
-//===----------------------------------------------------------------------===//
module gen.ldctraits;
@@ -18,15 +14,14 @@ import ddmd.dscope;
import ddmd.dtemplate;
import ddmd.expression;
import ddmd.errors;
-import ddmd.mtype;
import ddmd.id;
+import ddmd.mtype;
-// TODO: move this to a D interfacing helper file
extern(C++) struct Dstring
{
- const(char)* ptr;
- size_t len;
-};
+ size_t length;
+ const(char)* ptr;
+}
extern(C++) Dstring traitsGetTargetCPU();
extern(C++) bool traitsTargetHasFeature(Dstring feature);
@@ -43,7 +38,7 @@ Expression semanticTraitsLDC(TraitsExp e, Scope* sc)
}
auto cpu = traitsGetTargetCPU();
- auto se = new StringExp(e.loc, cast(void*)cpu.ptr, cpu.len);
+ auto se = new StringExp(e.loc, cast(void*)cpu.ptr, cpu.length);
return se.semantic(sc);
}
if (e.ident == Id.targetHasFeature)
@@ -70,7 +65,7 @@ Expression semanticTraitsLDC(TraitsExp e, Scope* sc)
}
se = se.toUTF8(sc);
- auto featureFound = traitsTargetHasFeature(Dstring(se.toPtr(), se.len));
+ auto featureFound = traitsTargetHasFeature(Dstring(se.len, se.toPtr()));
return new IntegerExp(e.loc, featureFound ? 1 : 0, Type.tbool);
}
return null;
diff --git a/gen/ldctraits.h b/gen/ldctraits.h
new file mode 100644
index 0000000..3bbee6e
--- /dev/null
+++ b/gen/ldctraits.h
@@ -0,0 +1,28 @@
+//===-- gen/ldctraits.h - LDC-specific __traits handling --------*- C++ -*-===//
+//
+// LDC � the LLVM D compiler
+//
+// This file is distributed under the BSD-style LDC license. See the LICENSE
+// file for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LDC_GEN_LDCTRAITS_H
+#define LDC_GEN_LDCTRAITS_H
+
+struct Dstring
+{
+ size_t length = 0;
+ const char *ptr = nullptr;
+
+ Dstring(size_t length, const char *ptr) : length(length), ptr(ptr) {}
+};
+
+Dstring traitsGetTargetCPU();
+bool traitsTargetHasFeature(Dstring feature);
+
+template <int N> bool traitsTargetHasFeature(const char (&feature)[N]) {
+ return traitsTargetHasFeature(Dstring(N - 1, feature));
+}
+
+#endif
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/ldc.git
More information about the pkg-d-commits
mailing list