5#ifndef CORE_FXCRT_NUMERICS_SAFE_MATH_CLANG_GCC_IMPL_H_
6#define CORE_FXCRT_NUMERICS_SAFE_MATH_CLANG_GCC_IMPL_H_
12#include "core/fxcrt/numerics/safe_conversions.h"
14#if !defined(__native_client__) && (defined(__ARMEL__) || defined(__arch64__))
15#include "core/fxcrt/numerics/safe_math_arm_impl.h"
16#define BASE_HAS_ASSEMBLER_SAFE_MATH (1
)
18#define BASE_HAS_ASSEMBLER_SAFE_MATH (0
)
27template <
typename T,
typename U>
31 static constexpr bool Do(T, U, V*) {
37template <
typename T,
typename U>
41 static constexpr V
Do(T, U) {
47template <
typename T,
typename U>
51 static constexpr V
Do(T, U) {
57template <
typename T,
typename U>
61 static constexpr V
Do(T, U) {
67#undef BASE_HAS_ASSEMBLER_SAFE_MATH
69template <
typename T,
typename U>
70struct CheckedAddFastOp {
71 static const bool is_supported =
true;
73 __attribute__((always_inline))
static constexpr bool Do(T x, U
y, V*
result) {
74 return !__builtin_add_overflow(x,
y,
result);
78template <
typename T,
typename U>
79struct CheckedSubFastOp {
80 static const bool is_supported =
true;
82 __attribute__((always_inline))
static constexpr bool Do(T x, U
y, V*
result) {
83 return !__builtin_sub_overflow(x,
y,
result);
87template <
typename T,
typename U>
88struct CheckedMulFastOp {
94 static const bool is_supported =
100 static const bool is_supported =
true;
102 template <
typename V>
103 __attribute__((always_inline))
static constexpr bool Do(T x, U
y, V*
result) {
106 : !__builtin_mul_overflow(x,
y,
result);
110template <
typename T,
typename U>
111struct ClampedAddFastOp {
113 template <
typename V>
114 __attribute__((always_inline))
static V
Do(T x, U
y) {
119template <
typename T,
typename U>
120struct ClampedSubFastOp {
122 template <
typename V>
123 __attribute__((always_inline))
static V
Do(T x, U
y) {
128template <
typename T,
typename U>
129struct ClampedMulFastOp {
131 template <
typename V>
132 __attribute__((always_inline))
static V
Do(T x, U
y) {
138struct ClampedNegFastOp {
139 static const bool is_supported =
std::is_signed<T>::value;
140 __attribute__((always_inline))
static T
Do(T value) {
144 return !__builtin_sub_overflow(T(0), value, &result)
146 :
std::numeric_limits<T>::max();
150 return ClampedSubFastOp<T, T>::
template Do<T>(T(0), value);
#define BASE_HAS_ASSEMBLER_SAFE_MATH
__attribute__((always_inline)) static const expr bool Do(T x
static const bool is_supported
static constexpr bool Do(T x, U y, V *result)
__attribute__((always_inline)) static const expr bool Do(T x
__attribute__((always_inline)) static const expr bool Do(T x
static const bool is_supported
__attribute__((always_inline)) static V Do(T x
__attribute__((always_inline)) static V Do(T x
__attribute__((always_inline)) static V Do(T x
static const bool is_supported
__attribute__((always_inline)) static V Do(T x
__attribute__((always_inline)) static T Do(T value)
__attribute__((always_inline)) static V Do(T x
static const bool is_supported
__attribute__((always_inline)) static V Do(T x