summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Klishch <danilklishch@gmail.com>2023-03-09 02:25:01 +0300
committerAndreas Kling <kling@serenityos.org>2023-04-30 06:05:54 +0200
commit3c900765bc634991db9d8604c0c7589159104b40 (patch)
tree9184bb97f93534f60c1f91d36dcfcced30e15a71
parenta9d192e88241abc91792c2fbb275719762e95c01 (diff)
downloadserenity-3c900765bc634991db9d8604c0c7589159104b40.zip
AK: Move taint_for_optimizer to StdLibExtras.h
Additionally, split it into two versions (for IsIntegral<T> -- asking to place value into register and for !IsIntegral<T> -- asking to place value into memory with memory clobber), so that Clang is no more completely confused about `taint_for_optimizer(AK::StringView&)`.
-rw-r--r--AK/BigIntBase.h11
-rw-r--r--AK/StdLibExtras.h22
2 files changed, 22 insertions, 11 deletions
diff --git a/AK/BigIntBase.h b/AK/BigIntBase.h
index 4ddff62726..ab17104950 100644
--- a/AK/BigIntBase.h
+++ b/AK/BigIntBase.h
@@ -154,17 +154,6 @@ constexpr StaticStorage<false, bit_width<T>> get_storage_of(T value)
}
// ===== Utilities =====
-template<typename T>
-ALWAYS_INLINE constexpr void taint_for_optimizer(T& value)
-{
- if (!is_constant_evaluated()) {
- asm volatile(""
- : "+rm"(value)
- :
- : "memory");
- }
-}
-
ALWAYS_INLINE constexpr NativeWord extend_sign(bool sign)
{
return sign ? max_word : 0;
diff --git a/AK/StdLibExtras.h b/AK/StdLibExtras.h
index c5c7b1a7f9..57c986c67c 100644
--- a/AK/StdLibExtras.h
+++ b/AK/StdLibExtras.h
@@ -166,6 +166,28 @@ constexpr bool is_constant_evaluated()
#endif
}
+template<typename T>
+ALWAYS_INLINE constexpr void taint_for_optimizer(T& value)
+requires(IsIntegral<T>)
+{
+ if (!is_constant_evaluated()) {
+ asm volatile(""
+ : "+r"(value));
+ }
+}
+
+template<typename T>
+ALWAYS_INLINE constexpr void taint_for_optimizer(T& value)
+requires(!IsIntegral<T>)
+{
+ if (!is_constant_evaluated()) {
+ asm volatile(""
+ :
+ : "m"(value)
+ : "memory");
+ }
+}
+
// These can't be exported into the global namespace as they would clash with the C standard library.
#define __DEFINE_GENERIC_ABS(type, zero, intrinsic) \