Skip to content

Commit 435c1c1

Browse files
authored
Add CPU feature helper function (#50402)
1 parent fcb3110 commit 435c1c1

File tree

6 files changed

+21
-0
lines changed

6 files changed

+21
-0
lines changed

src/jl_exported_funcs.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@
212212
XX(jl_get_binding_or_error) \
213213
XX(jl_get_binding_wr) \
214214
XX(jl_get_cpu_name) \
215+
XX(jl_get_cpu_features) \
215216
XX(jl_get_current_task) \
216217
XX(jl_get_default_sysimg_path) \
217218
XX(jl_get_excstack) \

src/processor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ jl_image_t jl_init_processor_pkgimg(void *hdl);
221221

222222
// Return the name of the host CPU as a julia string.
223223
JL_DLLEXPORT jl_value_t *jl_get_cpu_name(void);
224+
// Return the features of the host CPU as a julia string.
225+
JL_DLLEXPORT jl_value_t *jl_get_cpu_features(void);
224226
// Dump the name and feature set of the host CPU
225227
// For debugging only
226228
JL_DLLEXPORT void jl_dump_host_cpu(void);

src/processor_arm.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,6 +1802,11 @@ JL_DLLEXPORT jl_value_t *jl_get_cpu_name(void)
18021802
return jl_cstr_to_string(host_cpu_name().c_str());
18031803
}
18041804

1805+
JL_DLLEXPORT jl_value_t *jl_get_cpu_features(void)
1806+
{
1807+
return jl_cstr_to_string(jl_get_cpu_features_llvm().c_str());
1808+
}
1809+
18051810
jl_image_t jl_init_processor_sysimg(void *hdl)
18061811
{
18071812
if (!jit_targets.empty())

src/processor_fallback.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ JL_DLLEXPORT jl_value_t *jl_get_cpu_name(void)
164164
return jl_cstr_to_string(host_cpu_name().c_str());
165165
}
166166

167+
JL_DLLEXPORT jl_value_t *jl_get_cpu_features(void)
168+
{
169+
return jl_cstr_to_string(jl_get_cpu_features_llvm().c_str());
170+
}
171+
167172
JL_DLLEXPORT void jl_dump_host_cpu(void)
168173
{
169174
jl_safe_printf("CPU: %s\n", host_cpu_name().c_str());

src/processor_x86.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,11 @@ JL_DLLEXPORT jl_value_t *jl_get_cpu_name(void)
10421042
return jl_cstr_to_string(host_cpu_name().c_str());
10431043
}
10441044

1045+
JL_DLLEXPORT jl_value_t *jl_get_cpu_features(void)
1046+
{
1047+
return jl_cstr_to_string(jl_get_cpu_features_llvm().c_str());
1048+
}
1049+
10451050
jl_image_t jl_init_processor_sysimg(void *hdl)
10461051
{
10471052
if (!jit_targets.empty())

test/sysinfo.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Base.Sys.loadavg()
1010
@test Base.libllvm_path() isa Symbol
1111
@test contains(String(Base.libllvm_path()), "LLVM")
1212

13+
@test length(ccall(:jl_get_cpu_name, String, ())) != 0
14+
@test length(ccall(:jl_get_cpu_features, String, ())) >= 0
15+
1316
if Sys.isunix()
1417
mktempdir() do tempdir
1518
firstdir = joinpath(tempdir, "first")

0 commit comments

Comments
 (0)