[libc-commits] [PATCH] D74897: [libc] Add CMake script to check host cpu features

Guillaume Chatelet via Phabricator via libc-commits libc-commits at lists.llvm.org
Thu Feb 20 06:59:13 PST 2020


gchatelet updated this revision to Diff 245649.
gchatelet added a comment.

- make it explicit that these are host's cpu_features


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74897/new/

https://reviews.llvm.org/D74897

Files:
  libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake


Index: libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
===================================================================
--- /dev/null
+++ libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
@@ -0,0 +1,35 @@
+# Sets variables of the form CPU_FEATURES_XXX
+# Where XXX is the uppercase name of the feature.
+#
+# Usage:
+# include(LLVMLibCCheckCpuFeatures)
+# if(${CPU_FEATURES_AVX2})
+#    ...
+# endif()
+function(check_host_cpu_features)
+    if(${CMAKE_HOST_APPLE})
+        execute_process(
+            COMMAND sysctl -a
+            COMMAND grep machdep.cpu.features
+            COMMAND cut -f2 -d:
+            COMMAND tr . _
+            OUTPUT_VARIABLE flags_string
+        )
+    elseif(${CMAKE_HOST_UNIX})
+        execute_process(
+            COMMAND grep -h -m1 \\w*flags\\w* /proc/cpuinfo
+            COMMAND cut -f2 -d:
+            OUTPUT_VARIABLE flags_string
+        )
+    else()
+        message(FATAL "Unsupported system")
+    endif()
+
+    string(REPLACE " " ";" flags "${flags_string}")
+    foreach(flag ${flags})
+        string(TOUPPER ${flag} uppercase_flag)
+        set(CPU_FEATURES_${uppercase_flag} true PARENT_SCOPE)
+    endforeach()
+endfunction()
+
+check_host_cpu_features()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74897.245649.patch
Type: text/x-patch
Size: 1220 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20200220/453778e1/attachment-0001.bin>


More information about the libc-commits mailing list