Skip to content

Commit 8a20457

Browse files
authored
Merge pull request #4358 from pleroy/CPUId
Add support for querying the CPU flags from C#
2 parents b32e806 + a7f75c7 commit 8a20457

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

ksp_plugin/interface.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,14 @@ int __cdecl principia__GetStderrLogging() {
667667
return m.Return(FLAGS_stderrthreshold);
668668
}
669669

670+
void __cdecl principia__GetCPUIDFeatureFlags(bool* const has_avx,
671+
bool* const has_fma) {
672+
journal::Method<journal::GetCPUIDFeatureFlags> m({has_avx, has_fma});
673+
*has_avx = CPUIDFeatureFlag::AVX.IsSet();
674+
*has_fma = CPUIDFeatureFlag::FMA.IsSet();
675+
return m.Return();
676+
}
677+
670678
int __cdecl principia__GetSuppressedLogging() {
671679
journal::Method<journal::GetSuppressedLogging> m;
672680
return m.Return(FLAGS_minloglevel);

ksp_plugin_adapter/loader.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,18 @@ internal static string LoadPrincipiaDllAndInitGoogleLogging() {
9696
Interface.LoadSymbols();
9797
loaded_principia_dll = true;
9898
Log.InitGoogleLogging();
99-
return null;
99+
Interface.GetCPUIDFeatureFlags(out bool has_avx, out bool has_fma);
100+
Log.Info("Processor " +
101+
(has_avx ? "has" : "does not have") +
102+
" AVX support and " +
103+
(has_fma ? "has" : "does not have") +
104+
" FMA support.");
105+
if (has_fma && !has_avx) {
106+
return "Principia does not run on processors with FMA support but no " +
107+
"AVX support.";
108+
} else {
109+
return null;
110+
}
100111
} catch (Exception e) {
101112
UnityEngine.Debug.LogException(e);
102113
if (non_ascii_path_error != null) {

serialization/journal.proto

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,17 @@ message GetBufferedLogging {
13271327
optional Return return = 3;
13281328
}
13291329

1330+
message GetCPUIDFeatureFlags {
1331+
extend Method {
1332+
optional GetCPUIDFeatureFlags extension = 5198;
1333+
}
1334+
message Out {
1335+
required bool has_avx = 1;
1336+
required bool has_fma = 2;
1337+
}
1338+
optional Out out = 2;
1339+
}
1340+
13301341
message GetStderrLogging {
13311342
extend Method {
13321343
optional GetStderrLogging extension = 5007;

0 commit comments

Comments
 (0)