src: Allow clang-style +/- for target features

This largely works as expected, except that as far as I can tell,
without explicit annotations added to the caller, (or a
`#force_inline`), the LLVM `target-features` function attribute
gets ignored by the inliner under the rationale of `-sse,-avx,-avx2`
is a subset of `+sse,+avx,+avx2`.

With `#force_no_inline` the correct code does get generated, but in
the regression I am trying to fix, the caller gratuitously also uses
SIMD, leading to horrific performance.
This commit is contained in:
Yawning Angel
2026-03-18 05:13:44 +09:00
parent fdbbcc509c
commit 62d78d61fa
2 changed files with 24 additions and 8 deletions

View File

@@ -2160,8 +2160,15 @@ gb_internal bool check_target_feature_is_valid(String const &feature, TargetArch
String_Iterator it = {feature, 0};
for (;;) {
String str = string_split_iterator(&it, ',');
if (str == "") break;
if (!check_single_target_feature_is_valid(feature_list, str)) {
String feature_str = str;
if (string_starts_with(feature_str, '+') || string_starts_with(feature_str, '-')) {
feature_str = substring(feature_str, 1, feature_str.len);
if (feature_str == "") {
return false;
}
}
if (feature_str == "") break;
if (!check_single_target_feature_is_valid(feature_list, feature_str)) {
if (invalid) *invalid = str;
return false;
}
@@ -2201,20 +2208,26 @@ gb_internal bool check_target_feature_is_enabled(String const &feature, String *
String_Iterator it = {feature, 0};
for (;;) {
String str = string_split_iterator(&it, ',');
if (str == "") break;
String feature_str = str;
bool want_enabled = true;
if (string_starts_with(feature_str, '+') || string_starts_with(feature_str, '-')) {
want_enabled = feature_str[0] == '+';
feature_str = substring(feature_str, 1, feature_str.len);
}
if (feature_str == "") break;
if (!string_set_exists(&build_context.target_features_set, str)) {
String plus_str = concatenate_strings(temporary_allocator(), make_string_c("+"), str);
String plus_str = concatenate_strings(temporary_allocator(), make_string_c("+"), feature_str);
if (!string_set_exists(&build_context.target_features_set, plus_str)) {
if (want_enabled && !string_set_exists(&build_context.target_features_set, plus_str)) {
if (not_enabled) *not_enabled = str;
return false;
}
}
String minus_str = concatenate_strings(temporary_allocator(), make_string_c("-"), str);
String minus_str = concatenate_strings(temporary_allocator(), make_string_c("-"), feature_str);
if (string_set_exists(&build_context.target_features_set, minus_str)) {
if (!want_enabled && !string_set_exists(&build_context.target_features_set, minus_str)) {
if (not_enabled) *not_enabled = str;
return false;
}

View File

@@ -201,12 +201,15 @@ gb_internal lbProcedure *lb_create_procedure(lbModule *m, Entity *entity, bool i
for (;;) {
String str = string_split_iterator(&it, ',');
if (str == "") break;
bool add_prefix = !(string_starts_with(str, '+') || string_starts_with(str, '-'));
if (!first) {
feature_str = gb_string_appendc(feature_str, ",");
}
first = false;
feature_str = gb_string_appendc(feature_str, "+");
if (add_prefix) {
feature_str = gb_string_appendc(feature_str, "+");
}
feature_str = gb_string_append_length(feature_str, str.text, str.len);
}