From 35ceeb2199c569810a1524a0a21c2df2a3f5f29e Mon Sep 17 00:00:00 2001 From: Diego Lopez Recas Date: Mon, 4 Dec 2017 18:56:10 +0000 Subject: 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 Tested-by: Jenkins --- arm_compute/core/utils/misc/utility.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'arm_compute/core/utils/misc/utility.h') 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 +#include namespace arm_compute { @@ -123,6 +124,22 @@ inline auto foldl(F &&func, T &&initial, U &&value, Us &&... values) -> decltype { return foldl(std::forward(func), func(std::forward(initial), std::forward(value)), std::forward(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 +T saturate_cast(U val) +{ + const auto low = static_cast(std::numeric_limits::lowest()); + const auto high = static_cast(std::numeric_limits::max()); + return static_cast(clamp(val, low, high)); +} } // namespace utility } // namespace arm_compute #endif /* __ARM_COMPUTE_MISC_UTILITY_H__ */ -- cgit v1.2.1