From 019e08f63aa61010db863ebcf15d325884a4050d Mon Sep 17 00:00:00 2001 From: William Moses Date: Wed, 5 Jul 2023 07:32:13 -0400 Subject: [PATCH] Add CPU feature helper function (#50402) (cherry picked from commit 435c1c1a2c9db60be89b82bb9438916ac891a1ff) --- src/jl_exported_funcs.inc | 1 + src/processor.h | 2 ++ src/processor_arm.cpp | 5 +++++ src/processor_fallback.cpp | 5 +++++ src/processor_x86.cpp | 5 +++++ test/sysinfo.jl | 3 +++ 6 files changed, 21 insertions(+) diff --git a/src/jl_exported_funcs.inc b/src/jl_exported_funcs.inc index fd824131bdbda..6875e36d6da6a 100644 --- a/src/jl_exported_funcs.inc +++ b/src/jl_exported_funcs.inc @@ -212,6 +212,7 @@ XX(jl_get_binding_or_error) \ XX(jl_get_binding_wr) \ XX(jl_get_cpu_name) \ + XX(jl_get_cpu_features) \ XX(jl_get_current_task) \ XX(jl_get_default_sysimg_path) \ XX(jl_get_excstack) \ diff --git a/src/processor.h b/src/processor.h index 3e83bbb2247d6..2255cf4c10daa 100644 --- a/src/processor.h +++ b/src/processor.h @@ -221,6 +221,8 @@ jl_image_t jl_init_processor_pkgimg(void *hdl); // Return the name of the host CPU as a julia string. JL_DLLEXPORT jl_value_t *jl_get_cpu_name(void); +// Return the features of the host CPU as a julia string. +JL_DLLEXPORT jl_value_t *jl_get_cpu_features(void); // Dump the name and feature set of the host CPU // For debugging only JL_DLLEXPORT void jl_dump_host_cpu(void); diff --git a/src/processor_arm.cpp b/src/processor_arm.cpp index 0797fa4381f9d..0a8090a8a6d9c 100644 --- a/src/processor_arm.cpp +++ b/src/processor_arm.cpp @@ -1802,6 +1802,11 @@ JL_DLLEXPORT jl_value_t *jl_get_cpu_name(void) return jl_cstr_to_string(host_cpu_name().c_str()); } +JL_DLLEXPORT jl_value_t *jl_get_cpu_features(void) +{ + return jl_cstr_to_string(jl_get_cpu_features_llvm().c_str()); +} + jl_image_t jl_init_processor_sysimg(void *hdl) { if (!jit_targets.empty()) diff --git a/src/processor_fallback.cpp b/src/processor_fallback.cpp index 1aebde6dab90a..d50edc8e9b621 100644 --- a/src/processor_fallback.cpp +++ b/src/processor_fallback.cpp @@ -164,6 +164,11 @@ JL_DLLEXPORT jl_value_t *jl_get_cpu_name(void) return jl_cstr_to_string(host_cpu_name().c_str()); } +JL_DLLEXPORT jl_value_t *jl_get_cpu_features(void) +{ + return jl_cstr_to_string(jl_get_cpu_features_llvm().c_str()); +} + JL_DLLEXPORT void jl_dump_host_cpu(void) { jl_safe_printf("CPU: %s\n", host_cpu_name().c_str()); diff --git a/src/processor_x86.cpp b/src/processor_x86.cpp index e129b1239c7df..b9e7d8c0f0daf 100644 --- a/src/processor_x86.cpp +++ b/src/processor_x86.cpp @@ -1042,6 +1042,11 @@ JL_DLLEXPORT jl_value_t *jl_get_cpu_name(void) return jl_cstr_to_string(host_cpu_name().c_str()); } +JL_DLLEXPORT jl_value_t *jl_get_cpu_features(void) +{ + return jl_cstr_to_string(jl_get_cpu_features_llvm().c_str()); +} + jl_image_t jl_init_processor_sysimg(void *hdl) { if (!jit_targets.empty()) diff --git a/test/sysinfo.jl b/test/sysinfo.jl index 3a16dc73b4f6a..cb943cfd38843 100644 --- a/test/sysinfo.jl +++ b/test/sysinfo.jl @@ -10,6 +10,9 @@ Base.Sys.loadavg() @test Base.libllvm_path() isa Symbol @test contains(String(Base.libllvm_path()), "LLVM") +@test length(ccall(:jl_get_cpu_name, String, ())) != 0 +@test length(ccall(:jl_get_cpu_features, String, ())) >= 0 + if Sys.isunix() mktempdir() do tempdir firstdir = joinpath(tempdir, "first")