// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef BASE_NUMERICS_SAFE_CONVERSIONS_ARM_IMPL_H_ #define BASE_NUMERICS_SAFE_CONVERSIONS_ARM_IMPL_H_ // IWYU pragma: private, include "base/numerics/safe_conversions.h" #include #include #include #include #include "base/numerics/safe_conversions_impl.h" namespace base { namespace internal { // Fast saturation to a destination type. template struct SaturateFastAsmOp { static constexpr bool is_supported = kEnableAsmCode && std::signed_integral && std::integral && kIntegerBitsPlusSign <= kIntegerBitsPlusSign && kIntegerBitsPlusSign <= kIntegerBitsPlusSign && !kIsTypeInRangeForNumericType; __attribute__((always_inline)) static Dst Do(Src value) { int32_t src = value; if constexpr (std::is_signed_v) { int32_t result; asm("ssat %[dst], %[shift], %[src]" : [dst] "=r"(result) : [src] "r"(src), [shift] "n"( std::min(kIntegerBitsPlusSign, 32))); return static_cast(result); } else { uint32_t result; asm("usat %[dst], %[shift], %[src]" : [dst] "=r"(result) : [src] "r"(src), [shift] "n"( std::min(kIntegerBitsPlusSign, 31))); return static_cast(result); } } }; } // namespace internal } // namespace base #endif // BASE_NUMERICS_SAFE_CONVERSIONS_ARM_IMPL_H_