mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-06 14:48:21 +00:00
Merge pull request #6442 from Yawning/feature/disable-target-feature
src: Support clang-style `+`/`-` prefixes in target features
This commit is contained in:
@@ -3,6 +3,18 @@ package rand
|
||||
import "base:intrinsics"
|
||||
import "base:runtime"
|
||||
|
||||
when ODIN_ARCH == .amd64 || ODIN_ARCH == .i386 {
|
||||
// LLVM thinks that using SIMD for read_u64 is good,
|
||||
// when it causes a ~3x performance regression. As
|
||||
// far as I can tell, this behavior is limited to
|
||||
// Intel.
|
||||
@(private = "file")
|
||||
TARGET_FEATURES :: "-sse,-avx,-avx2"
|
||||
} else {
|
||||
@(private = "file")
|
||||
TARGET_FEATURES :: ""
|
||||
}
|
||||
|
||||
/*
|
||||
The state for a xoshiro256** pseudorandom generator.
|
||||
*/
|
||||
@@ -10,8 +22,9 @@ Xoshiro256_Random_State :: struct {
|
||||
s: [4]u64,
|
||||
}
|
||||
|
||||
@(enable_target_feature = TARGET_FEATURES)
|
||||
xoshiro256_random_generator_proc :: proc(data: rawptr, mode: runtime.Random_Generator_Mode, p: []byte) {
|
||||
@(require_results)
|
||||
@(require_results, enable_target_feature = TARGET_FEATURES)
|
||||
read_u64 :: proc "contextless" (r: ^Xoshiro256_Random_State) -> u64 {
|
||||
// xoshiro256** output function and state transition
|
||||
|
||||
@@ -27,7 +40,7 @@ xoshiro256_random_generator_proc :: proc(data: rawptr, mode: runtime.Random_Gene
|
||||
|
||||
return result
|
||||
|
||||
rotate_left64 :: proc "contextless" (x: u64, k: int) -> u64 {
|
||||
rotate_left64 :: #force_inline proc "contextless" (x: u64, k: int) -> u64 {
|
||||
n :: 64
|
||||
s := uint(k) & (n-1)
|
||||
return x << s | x >> (n-s)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user