[llvm-branch-commits] [mlir] [libcxx] [clang] [lld] [flang] [compiler-rt] [lldb] [llvm] [builtins][arm64] Implement __init_cpu_features_resolver on Apple platforms (PR #75636)

Jon Roelofs via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Dec 18 16:00:25 PST 2023


================
@@ -0,0 +1,69 @@
+#include <TargetConditionals.h>
+#if TARGET_OS_OSX || TARGET_OS_IPHONE
+#include <dispatch/dispatch.h>
+#include <sys/sysctl.h>
+
+static bool isKnownAndSupported(const char *name) {
+  int32_t val = 0;
+  size_t size = sizeof(val);
+  if (sysctlbyname(name, &val, &size, NULL, 0))
+    return false;
+  return val;
+}
+
+void __init_cpu_features_resolver(void) {
+  // On Darwin platforms, this may be called concurrently by multiple threads
+  // because the resolvers that use it are called lazily at runtime (unlike on
+  // ELF platforms, where IFuncs are resolved serially at load time).  This
+  // function's effect on __aarch64_cpu_features should be idempotent, but even
+  // so we need dispatch_once to resolve the race condition.  Dispatch is
+  // available through libSystem, which we need anyway for the sysctl, so this
+  // does not add a new dependency.
+
+  static dispatch_once_t onceToken = 0;
+  dispatch_once(&onceToken, ^{
+    // https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics
+    static struct {
+      const char *sysctl_name;
+      enum CPUFeatures feature;
+    } features[] = {
----------------
jroelofs wrote:

Sure, I can add entries for those. Looks like I missed them in my manual intersection of the [sysctl docs](https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics) with the `FEAT_*` table.

> Specification is not final yet and open to proposals.

Any word on when FMV might come out of beta?

https://github.com/llvm/llvm-project/pull/75636


More information about the llvm-branch-commits mailing list