aboutsummaryrefslogtreecommitdiff
path: root/support/ToolchainSupport.h
diff options
context:
space:
mode:
Diffstat (limited to 'support/ToolchainSupport.h')
-rw-r--r--support/ToolchainSupport.h76
1 files changed, 47 insertions, 29 deletions
diff --git a/support/ToolchainSupport.h b/support/ToolchainSupport.h
index d8c14411e8..accbb643c2 100644
--- a/support/ToolchainSupport.h
+++ b/support/ToolchainSupport.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2021 Arm Limited.
+ * Copyright (c) 2017-2023 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -21,8 +21,11 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-#ifndef ARM_COMPUTE_SUPPORT_TOOLCHAINSUPPORT
-#define ARM_COMPUTE_SUPPORT_TOOLCHAINSUPPORT
+#ifndef ACL_SUPPORT_TOOLCHAINSUPPORT_H
+#define ACL_SUPPORT_TOOLCHAINSUPPORT_H
+
+#include "support/Bfloat16.h"
+#include "support/Half.h"
#include <cassert>
#include <cmath>
@@ -33,24 +36,21 @@
#include <string>
#include <type_traits>
-#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
-#include <arm_neon.h>
-#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
-
-#include "support/Bfloat16.h"
-#include "support/Half.h"
-
#ifndef M_PI
#define M_PI (3.14159265358979323846)
#endif // M_PI
namespace arm_compute
{
+#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
+typedef __fp16 float16_t;
+#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
+
namespace support
{
namespace cpp11
{
-#if(__ANDROID__ || BARE_METAL)
+#if (__ANDROID__ || BARE_METAL)
template <typename T>
inline T nearbyint(T value)
{
@@ -129,11 +129,12 @@ inline T copysign(T x, T y)
*
* @return Result floating point value equal to (x*y) + z.c
*/
-template < typename T, typename = typename std::enable_if < std::is_floating_point<T>::value
+template <typename T,
+ typename = typename std::enable_if<std::is_floating_point<T>::value
#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
- || std::is_same<T, float16_t>::value
+ || std::is_same<T, float16_t>::value
#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
- >::type >
+ >::type>
inline T fma(T x, T y, T z)
{
return ::fma(x, y, z);
@@ -143,15 +144,15 @@ inline T fma(T x, T y, T z)
* and writes the result to a character string buffer.
*
* @param[in] s Pointer to a character string to write to
- * @param[in] n Up to buf_size - 1 characters may be written, plus the null terminator
- * @param[in] fmt Pointer to a null-terminated multibyte string specifying how to interpret the data.
+ * @param[in] n Up to buf_size - 1 characters may be written, plus the null ending character
+ * @param[in] fmt Pointer to a null-ended multibyte string specifying how to interpret the data.
* @param[in] args Arguments forwarded to snprintf.
*
* @return Number of characters that would have been written for a sufficiently large buffer
- * if successful (not including the terminating null character), or a negative value if an error occurred.
+ * if successful (not including the ending null character), or a negative value if an error occurred.
*/
template <typename... Ts>
-inline int snprintf(char *s, size_t n, const char *fmt, Ts &&... args)
+inline int snprintf(char *s, size_t n, const char *fmt, Ts &&...args)
{
return ::snprintf(s, n, fmt, std::forward<Ts>(args)...);
}
@@ -183,8 +184,7 @@ inline T nearbyint(T value)
template <typename T, typename = typename std::enable_if<std::is_floating_point<T>::value>::type>
inline T round(T value)
{
- //Workaround Valgrind's mismatches: when running from Valgrind the call to std::round(-4.500000) == -4.000000 instead of 5.00000
- return (value < 0.f) ? static_cast<int>(value - 0.5f) : static_cast<int>(value + 0.5f);
+ return std::round(value);
}
/** Round floating-point value with half value rounding away from zero and cast to long
@@ -244,11 +244,12 @@ inline T copysign(T x, T y)
*
* @return Result floating point value equal to (x*y) + z.
*/
-template < typename T, typename = typename std::enable_if < std::is_floating_point<T>::value
+template <typename T,
+ typename = typename std::enable_if<std::is_floating_point<T>::value
#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
- || std::is_same<T, float16_t>::value
+ || std::is_same<T, float16_t>::value
#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
- >::type >
+ >::type>
inline T fma(T x, T y, T z)
{
return std::fma(x, y, z);
@@ -258,15 +259,15 @@ inline T fma(T x, T y, T z)
* and writes the result to a character string buffer.
*
* @param[in] s Pointer to a character string to write to
- * @param[in] n Up to buf_size - 1 characters may be written, plus the null terminator
- * @param[in] fmt Pointer to a null-terminated multibyte string specifying how to interpret the data.
+ * @param[in] n Up to buf_size - 1 characters may be written, plus the null ending character
+ * @param[in] fmt Pointer to a null-ended multibyte string specifying how to interpret the data.
* @param[in] args Arguments forwarded to std::snprintf.
*
* @return Number of characters that would have been written for a sufficiently large buffer
- * if successful (not including the terminating null character), or a negative value if an error occurred.
+ * if successful (not including the ending null character), or a negative value if an error occurred.
*/
template <typename... Ts>
-inline int snprintf(char *s, std::size_t n, const char *fmt, Ts &&... args)
+inline int snprintf(char *s, std::size_t n, const char *fmt, Ts &&...args)
{
return std::snprintf(s, n, fmt, std::forward<Ts>(args)...);
}
@@ -297,7 +298,7 @@ inline bfloat16 lowest<bfloat16>()
template <typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
inline bool isfinite(T value)
{
- return std::isfinite(value);
+ return std::isfinite(static_cast<double>(value));
}
inline bool isfinite(half_float::half value)
@@ -309,7 +310,24 @@ inline bool isfinite(bfloat16 value)
{
return std::isfinite(float(value));
}
+
+// std::signbit
+template <typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
+inline bool signbit(T value)
+{
+ return std::signbit(static_cast<double>(value));
+}
+
+inline bool signbit(half_float::half value)
+{
+ return half_float::signbit(value);
+}
+
+inline bool signbit(bfloat16 value)
+{
+ return std::signbit(float(value));
+}
} // namespace cpp11
} // namespace support
} // namespace arm_compute
-#endif /* ARM_COMPUTE_SUPPORT_TOOLCHAINSUPPORT */
+#endif // ACL_SUPPORT_TOOLCHAINSUPPORT_H