From 3c900765bc634991db9d8604c0c7589159104b40 Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Thu, 9 Mar 2023 02:25:01 +0300 Subject: [PATCH] AK: Move taint_for_optimizer to StdLibExtras.h Additionally, split it into two versions (for IsIntegral -- asking to place value into register and for !IsIntegral -- asking to place value into memory with memory clobber), so that Clang is no more completely confused about `taint_for_optimizer(AK::StringView&)`. --- AK/BigIntBase.h | 11 ----------- AK/StdLibExtras.h | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/AK/BigIntBase.h b/AK/BigIntBase.h index 4ddff627263..ab17104950a 100644 --- a/AK/BigIntBase.h +++ b/AK/BigIntBase.h @@ -154,17 +154,6 @@ constexpr StaticStorage> get_storage_of(T value) } // ===== Utilities ===== -template -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 c5c7b1a7f9f..57c986c67cc 100644 --- a/AK/StdLibExtras.h +++ b/AK/StdLibExtras.h @@ -166,6 +166,28 @@ constexpr bool is_constant_evaluated() #endif } +template +ALWAYS_INLINE constexpr void taint_for_optimizer(T& value) +requires(IsIntegral) +{ + if (!is_constant_evaluated()) { + asm volatile("" + : "+r"(value)); + } +} + +template +ALWAYS_INLINE constexpr void taint_for_optimizer(T& value) +requires(!IsIntegral) +{ + 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) \