5#ifndef CORE_FXCRT_NUMERICS_SAFE_CONVERSIONS_H_
6#define CORE_FXCRT_NUMERICS_SAFE_CONVERSIONS_H_
14#include "core/fxcrt/numerics/safe_conversions_impl.h"
16#if defined(__ARMEL__) && !defined(__native_client__)
17#include "core/fxcrt/numerics/safe_conversions_arm_impl.h"
18#define BASE_HAS_OPTIMIZED_SAFE_CONVERSIONS (1
)
20#define BASE_HAS_OPTIMIZED_SAFE_CONVERSIONS (0
)
27template <
typename Dst,
typename Src>
30 static constexpr Dst
Do(Src) {
36#undef BASE_HAS_OPTIMIZED_SAFE_CONVERSIONS
40template <
typename Dst,
typename Src,
typename Enable =
void>
43 static constexpr bool Do(Src value) {
50template <
typename Dst,
typename Src>
68template <
typename Dst,
typename Src>
87template <
typename Dst,
typename Src>
90 return internal::IsValueInRangeFastOp<Dst, SrcType>::is_supported
91 ? internal::IsValueInRangeFastOp<Dst, SrcType>::Do(
92 static_cast<SrcType>(value))
93 : internal::DstRangeRelationToSrcRange<Dst>(
94 static_cast<SrcType>(value))
101template <
typename Dst,
109 ?
static_cast<Dst>(
static_cast<SrcType>(value))
110 : CheckHandler::
template HandleFailure<Dst>();
118 static constexpr T
NaN() {
119 if constexpr (
std::numeric_limits<T>::has_quiet_NaN) {
120 return std::numeric_limits<T>::quiet_NaN();
125 using std::numeric_limits<T>::max;
127 if constexpr (
std::numeric_limits<T>::has_infinity) {
128 return std::numeric_limits<T>::infinity();
130 return std::numeric_limits<T>::max();
133 using std::numeric_limits<T>::lowest;
135 if constexpr (
std::numeric_limits<T>::has_infinity) {
136 return std::numeric_limits<T>::infinity() * -1;
138 return std::numeric_limits<T>::lowest();
143template <
typename Dst,
template <
typename>
class S,
typename Src>
149 : S<Dst>::Underflow())
159template <
typename Dst,
typename Src,
typename Enable =
void>
162 static constexpr Dst
Do(Src value) {
168template <
typename Dst,
typename Src>
181template <
typename Dst,
typename Src>
206template <
typename Dst,
212 std::is_same<SaturationHandler<Dst>,
213 SaturationDefaultLimits<Dst>>::value
214 ? SaturateFastOp<Dst, SrcType>::Do(
static_cast<SrcType>(value))
215 : saturated_cast_impl<Dst, SaturationHandler, SrcType>(
216 static_cast<SrcType>(value),
217 DstRangeRelationToSrcRange<Dst, SaturationHandler, SrcType>(
218 static_cast<SrcType>(value)));
224template <
typename Dst,
typename Src>
227 static_assert(
UnderlyingType<Src>::is_numeric,
"Argument must be numeric.");
228 static_assert(
std::is_arithmetic<Dst>::value,
"Result must be numeric.");
236 static_assert(StaticDstRangeRelationToSrcRange<Dst, SrcType>::value ==
237 NUMERIC_RANGE_CONTAINED,
238 "The source type is out of range for the destination type. "
239 "Please see strict_cast<> comments for more information.");
241 return static_cast<Dst>(
static_cast<SrcType>(value));
245template <
typename Dst,
typename Src,
class Enable =
void>
247 static constexpr bool value =
false;
250template <
typename Dst,
typename Src>
279 template <
typename Src>
281 : value_(strict_cast<T>(rhs.value_)) {}
291 template <
typename Src>
307 template <
typename Dst,
308 typename std::enable_if<
309 IsNumericRangeContained<Dst, T>::value>::type* =
nullptr>
311 return static_cast<
typename ArithmeticOrUnderlyingEnum<Dst>::type>(value_);
326#define BASE_NUMERIC_COMPARISON_OPERATORS(CLASS, NAME, OP)
327 template <typename L, typename R,
328 typename std::enable_if<
329 internal::Is##CLASS##Op<L, R>::value>::type* = nullptr>
330 constexpr bool operator
OP(const L lhs, const R rhs) {
331 return SafeCompare<NAME, typename UnderlyingType<L>::type,
332 typename UnderlyingType<R>::type>(lhs, rhs);
347using internal::IsTypeInRangeForNumericType;
348using internal::IsValueInRangeForNumericType;
362template <
typename Dst =
int,
367 return saturated_cast<Dst>(
std::floor(value));
369template <
typename Dst =
int,
374 return saturated_cast<Dst>(
std::ceil(value));
376template <
typename Dst =
int,
382 (value >= 0.0f) ?
std::floor(value + 0.5f) :
std::ceil(value - 0.5f);
383 return saturated_cast<Dst>(rounded);
#define FXCRT_BYTESWAPS_CONSTEXPR
constexpr bool IsOverflowFlagSet() const
constexpr bool IsUnderflowFlagSet() const
constexpr StrictNumeric(Src value)
constexpr StrictNumeric()
constexpr StrictNumeric(T value)
constexpr operator Dst() const
constexpr StrictNumeric(const StrictNumeric< Src > &rhs)
constexpr span(T(&array)[N]) noexcept
constexpr reverse_iterator rend() const noexcept
constexpr reverse_iterator rbegin() const noexcept
constexpr const_reverse_iterator crend() const noexcept
std::reverse_iterator< iterator > reverse_iterator
const span first(size_t count) const
typename std::remove_cv< T >::type value_type
span & operator=(const span &other) noexcept
constexpr const_iterator cbegin() const noexcept
constexpr const_iterator cend() const noexcept
constexpr const_reverse_iterator crbegin() const noexcept
const span last(size_t count) const
constexpr bool empty() const noexcept
constexpr size_t size() const noexcept
constexpr span(Container &container)
friend constexpr span< U > make_span(U *data, size_t size) noexcept
std::reverse_iterator< const_iterator > const_reverse_iterator
const span subspan(size_t pos, size_t count=dynamic_extent) const
constexpr iterator begin() const noexcept
constexpr size_t size_bytes() const noexcept
constexpr span() noexcept=default
span(const Container &container)
constexpr span(std::array< T, N > &array) noexcept
constexpr T & back() const noexcept
constexpr span(const std::array< std::remove_cv_t< T >, N > &array) noexcept
constexpr T * data() const noexcept
constexpr T & front() const noexcept
constexpr span(const span &other) noexcept=default
UNSAFE_BUFFER_USAGE constexpr span(T *data, size_t size) noexcept
constexpr span(const span< U, M, R > &other)
T & operator[](size_t index) const noexcept
constexpr iterator end() const noexcept
#define UNSAFE_BUFFERS(...)
#define UNSAFE_BUFFER_USAGE
void CRYPT_MD5Finish(CRYPT_md5_context *context, pdfium::span< uint8_t, 16 > digest)
#define P(a, b, c, d, k, s, t)
void CRYPT_MD5Generate(pdfium::span< const uint8_t > data, pdfium::span< uint8_t, 16 > digest)
void CRYPT_ArcFourCryptBlock(pdfium::span< uint8_t > data, pdfium::span< const uint8_t > key)
void CRYPT_ArcFourSetup(CRYPT_rc4_context *context, pdfium::span< const uint8_t > key)
void CRYPT_MD5Update(CRYPT_md5_context *context, pdfium::span< const uint8_t > data)
void CRYPT_ArcFourCrypt(CRYPT_rc4_context *context, pdfium::span< uint8_t > data)
CRYPT_md5_context CRYPT_MD5Start()
void CRYPT_AESEncrypt(CRYPT_aes_context *ctx, pdfium::span< uint8_t > dest, pdfium::span< const uint8_t > src)
void CRYPT_AESSetIV(CRYPT_aes_context *ctx, const uint8_t *iv)
void CRYPT_AESDecrypt(CRYPT_aes_context *ctx, uint8_t *dest, const uint8_t *src, uint32_t size)
void CRYPT_AESSetKey(CRYPT_aes_context *ctx, const uint8_t *key, uint32_t keylen)
void CRYPT_SHA512Update(CRYPT_sha2_context *context, pdfium::span< const uint8_t > data)
void CRYPT_SHA384Update(CRYPT_sha2_context *context, pdfium::span< const uint8_t > data)
DataVector< uint8_t > CRYPT_SHA256Generate(pdfium::span< const uint8_t > data)
void CRYPT_SHA1Finish(CRYPT_sha1_context *context, pdfium::span< uint8_t, 20 > digest)
void CRYPT_SHA1Update(CRYPT_sha1_context *context, pdfium::span< const uint8_t > data)
void CRYPT_SHA512Finish(CRYPT_sha2_context *context, pdfium::span< uint8_t, 64 > digest)
DataVector< uint8_t > CRYPT_SHA384Generate(pdfium::span< const uint8_t > data)
void CRYPT_SHA384Start(CRYPT_sha2_context *context)
void CRYPT_SHA384Finish(CRYPT_sha2_context *context, pdfium::span< uint8_t, 48 > digest)
void CRYPT_SHA512Start(CRYPT_sha2_context *context)
DataVector< uint8_t > CRYPT_SHA1Generate(pdfium::span< const uint8_t > data)
void CRYPT_SHA256Start(CRYPT_sha2_context *context)
DataVector< uint8_t > CRYPT_SHA512Generate(pdfium::span< const uint8_t > data)
void CRYPT_SHA1Start(CRYPT_sha1_context *context)
void CRYPT_SHA256Finish(CRYPT_sha2_context *context, pdfium::span< uint8_t, 32 > digest)
void CRYPT_SHA256Update(CRYPT_sha2_context *context, pdfium::span< const uint8_t > data)
NOINLINE void FX_OutOfMemoryTerminate(size_t size)
void * FX_AlignedAlloc(size_t size, size_t alignment)
void FXMEM_DefaultFree(void *pointer)
void * FXMEM_DefaultAlloc(size_t byte_size)
void * FXMEM_DefaultCalloc(size_t num_elems, size_t byte_size)
void * FXMEM_DefaultRealloc(void *pointer, size_t new_size)
void * FX_ArrayBufferAllocate(size_t length)
void FX_DestroyMemoryAllocators()
void FX_InitializeMemoryAllocators()
void FX_ArrayBufferFree(void *data)
void * FX_ArrayBufferAllocateUninitialized(size_t length)
FXCRT_BYTESWAPS_CONSTEXPR uint16_t ByteSwap(uint16_t x)
FXCRT_BYTESWAPS_CONSTEXPR uint32_t ByteSwap(uint32_t x)
uint32_t FromBE32(uint32_t x)
constexpr std::array< U, N > ToArrayImpl(const T(&data)[N], std::index_sequence< I... >)
uint16_t GetUInt16LSBFirst(pdfium::span< const uint8_t, 2 > span)
void PutUInt32MSBFirst(uint32_t value, pdfium::span< uint8_t, 4 > span)
ResultType CollectionSize(const Collection &collection)
FakeUniquePtr< T > MakeFakeUniquePtr(T *arg)
void PutUInt16LSBFirst(uint16_t value, pdfium::span< uint8_t, 2 > span)
uint16_t FromBE16(uint16_t x)
void PutUInt32LSBFirst(uint32_t value, pdfium::span< uint8_t, 4 > span)
uint16_t GetUInt16MSBFirst(pdfium::span< const uint8_t, 2 > span)
constexpr std::array< U, N > ToArray(const U(&data)[N])
uint32_t GetUInt32MSBFirst(pdfium::span< const uint8_t, 4 > span)
bool IndexInBounds(const Collection &collection, IndexType index)
void PutUInt16MSBFirst(uint16_t value, pdfium::span< uint8_t, 2 > span)
void Copy(const T &source_container, U &&dest_container)
void Fill(T &&container, const V &value)
uint32_t FromLE32(uint32_t x)
uint32_t GetUInt32LSBFirst(pdfium::span< const uint8_t, 4 > span)
uint16_t FromLE16(uint16_t x)
void * CallocOrDie2D(size_t w, size_t h, size_t member_size)
void * AllocOrDie2D(size_t w, size_t h, size_t member_size)
constexpr Dst saturated_cast(Src value)
std::is_integral< decltype(std::declval< Container >().size())> ContainerHasIntegralSize
void * StringAllocOrDie(size_t num_members, size_t member_size)
void * Alloc(size_t num_members, size_t member_size)
IsSpanImpl< typename std::decay< T >::type > IsSpan
void * StringAlloc(size_t num_members, size_t member_size)
void * ReallocOrDie(void *ptr, size_t num_members, size_t member_size)
std::is_convertible< From *, To * > IsLegalSpanConversion
void * Realloc(void *ptr, size_t num_members, size_t member_size)
IsStdArrayImpl< typename std::decay< T >::type > IsStdArray
void StringDealloc(void *ptr)
constexpr bool IsValueInRangeForNumericType(Src value)
void * AllocOrDie(size_t num_members, size_t member_size)
constexpr Dst checked_cast(Src value)
void * Alloc2D(size_t w, size_t h, size_t member_size)
void * Calloc(size_t num_members, size_t member_size)
constexpr Dst strict_cast(Src value)
constexpr StrictNumeric< typename UnderlyingType< T >::type > MakeStrictNum(const T value)
void * CallocOrDie(size_t num_members, size_t member_size)
constexpr Dst saturated_cast_impl(Src value, RangeCheck constraint)
constexpr span< T > make_span(T(&array)[N]) noexcept
span< char > as_writable_chars(span< T, N, P > s) noexcept
span< const uint8_t > as_bytes(span< T, N, P > s) noexcept
constexpr size_t dynamic_extent
static constexpr span< T > span_from_ref(T &single_object) noexcept
static constexpr span< const uint8_t > byte_span_from_ref(const T &single_object) noexcept
Dst ClampRound(Src value)
UNSAFE_BUFFER_USAGE constexpr span< T > make_span(T *data, size_t size) noexcept
span< const uint8_t > as_byte_span(T &&arg)
span< const char > as_chars(span< T, N, P > s) noexcept
span< const uint8_t > as_byte_span(const T &arg)
UNOWNED_PTR_EXCLUSION T * DefaultSpanInternalPtr
span< uint8_t > as_writable_bytes(span< T, N, P > s) noexcept
constexpr span< T > make_span(std::array< T, N > &array) noexcept
constexpr span< T > make_span(Container &container)
constexpr span< uint8_t > as_writable_byte_span(T &&arg)
IMMEDIATE_CRASH_ALWAYS_INLINE void ImmediateCrash()
static constexpr span< uint8_t > byte_span_from_ref(T &single_object) noexcept
Dst ClampFloor(Src value)
constexpr span< T > make_span(const Container &container)
#define __has_attribute(x)
#define BASE_HAS_OPTIMIZED_SAFE_CONVERSIONS
#define BASE_NUMERIC_COMPARISON_OPERATORS(CLASS, NAME, OP)
#define BASE_NUMERICS_LIKELY(x)
#define IsConstantEvaluated()
std::array< uint32_t, kMaxNb > iv
std::array< uint32_t, kSchedSize > invkeysched
static constexpr int kMaxNr
static constexpr int kSchedSize
static constexpr int kMaxNb
std::array< uint32_t, kSchedSize > keysched
std::array< uint32_t, 4 > state
std::array< uint32_t, 2 > total
std::array< int32_t, kPermutationLength > m
static constexpr int32_t kPermutationLength
std::array< uint32_t, 5 > h
std::array< uint8_t, 64 > block
std::array< uint64_t, 8 > state
void operator()(void *ptr) const
FxPartitionAllocAllocator< U, Alloc, Free > other
pointer allocate(size_type n, const void *hint=0)
void deallocate(pointer p, size_type n)
const_pointer address(const_reference x) const noexcept
FxPartitionAllocAllocator() noexcept=default
size_type max_size() const noexcept
~FxPartitionAllocAllocator()=default
pointer address(reference x) const noexcept
FxPartitionAllocAllocator(const FxPartitionAllocAllocator< U, Alloc, Free > &other) noexcept
bool operator!=(const FxPartitionAllocAllocator &that)
void construct(U *p, Args &&... args)
const T & const_reference
bool operator==(const FxPartitionAllocAllocator &that)
FxPartitionAllocAllocator(const FxPartitionAllocAllocator &other) noexcept=default
static constexpr bool value
static constexpr bool is_supported
static constexpr bool Do(Src value)
static constexpr Dst Do(Src)
static constexpr bool is_supported
static constexpr bool is_supported
static constexpr Dst Do(Src value)
static constexpr T Overflow()
static constexpr T Underflow()
#define UNOWNED_PTR_EXCLUSION