diff options
author | Diego Lopez Recas <Diego.LopezRecas@arm.com> | 2017-12-04 18:56:10 +0000 |
---|---|---|
committer | Anthony Barbier <anthony.barbier@arm.com> | 2018-11-02 16:45:00 +0000 |
commit | 35ceeb2199c569810a1524a0a21c2df2a3f5f29e (patch) | |
tree | 4a55f8626cb2960843547fabdb2431a70ec1029a /arm_compute/core/utils/misc/utility.h | |
parent | 97cf2497d2b617de3209330893ad51bd0cc126ce (diff) | |
download | ComputeLibrary-35ceeb2199c569810a1524a0a21c2df2a3f5f29e.tar.gz |
IVGCVSW-798 Add Softmax NEON support for QASYMM8
Change-Id: I4f2cca52caf210fdb7d6bb7e9436ac51cb5088b4
Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/112398
Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Tested-by: Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'arm_compute/core/utils/misc/utility.h')
-rw-r--r-- | arm_compute/core/utils/misc/utility.h | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/arm_compute/core/utils/misc/utility.h b/arm_compute/core/utils/misc/utility.h index 45b3b5268e..e8d823b5bc 100644 --- a/arm_compute/core/utils/misc/utility.h +++ b/arm_compute/core/utils/misc/utility.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -25,6 +25,7 @@ #define __ARM_COMPUTE_MISC_UTILITY_H__ #include <array> +#include <limits> namespace arm_compute { @@ -123,6 +124,22 @@ inline auto foldl(F &&func, T &&initial, U &&value, Us &&... values) -> decltype { return foldl(std::forward<F>(func), func(std::forward<T>(initial), std::forward<U>(value)), std::forward<Us>(values)...); } + +/** Type cast with saturation. + * + * @param[in] val Value of type U to cast. + * + * @return Original value clamped to numeric limits of T and converted to type T. + * + * @warning Numeric limits of T must be representable without loss in type U. + */ +template <typename T, typename U> +T saturate_cast(U val) +{ + const auto low = static_cast<U>(std::numeric_limits<T>::lowest()); + const auto high = static_cast<U>(std::numeric_limits<T>::max()); + return static_cast<T>(clamp(val, low, high)); +} } // namespace utility } // namespace arm_compute #endif /* __ARM_COMPUTE_MISC_UTILITY_H__ */ |