[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 245648.
gchatelet added a comment.

- formatting nits


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_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_cpu_features()


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


More information about the libc-commits mailing list