summaryrefslogtreecommitdiff
path: root/support/ToolchainSupport.h
diff options
context:
space:
mode:
authorJenkins <bsgcomp@arm.com>2018-08-29 15:32:11 +0000
committerMichele Di Giorgio <michele.digiorgio@arm.com>2018-08-30 17:15:09 +0100
commit52ba29e936b8e711e8acdfe819e36f884d4f3fe1 (patch)
tree23a8e15208ad7fcf07a37ed9119979cde01dcdc8 /support/ToolchainSupport.h
parente2542c9f35ca427286822cd0c9296f49914f78b0 (diff)
downloadarmcl-52ba29e936b8e711e8acdfe819e36f884d4f3fe1.tar.gz
armcl-52ba29e936b8e711e8acdfe819e36f884d4f3fe1.tar.bz2
armcl-52ba29e936b8e711e8acdfe819e36f884d4f3fe1.zip
arm_compute v18.08
Diffstat (limited to 'support/ToolchainSupport.h')
-rw-r--r--support/ToolchainSupport.h101
1 files changed, 49 insertions, 52 deletions
diff --git a/support/ToolchainSupport.h b/support/ToolchainSupport.h
index 88c17009c..7d02e67ec 100644
--- a/support/ToolchainSupport.h
+++ b/support/ToolchainSupport.h
@@ -25,6 +25,7 @@
#define ARM_COMPUTE_TEST_TOOLCHAINSUPPORT
#include <algorithm>
+#include <cassert>
#include <cmath>
#include <cstddef>
#include <limits>
@@ -42,38 +43,29 @@ namespace support
{
namespace cpp11
{
-#if(__ANDROID__ || BARE_METAL)
-/** Convert integer and float values to string.
- *
- * @note This function implements the same behaviour as std::to_string. The
- * latter is missing in some Android toolchains.
- *
- * @param[in] value Value to be converted to string.
- *
- * @return String representation of @p value.
- */
-template <typename T, typename std::enable_if<std::is_arithmetic<typename std::decay<T>::type>::value, int>::type = 0>
-inline std::string to_string(T && value)
+enum class NumericBase
{
- std::stringstream stream;
- stream << std::forward<T>(value);
- return stream.str();
-}
+ BASE_10,
+ BASE_16
+};
/** Convert string values to integer.
*
* @note This function implements the same behaviour as std::stoi. The latter
* is missing in some Android toolchains.
*
- * @param[in] str String to be converted to int.
+ * @param[in] str String to be converted to int.
+ * @param[in] pos If idx is not a null pointer, the function sets the value of pos to the position of the first character in str after the number.
+ * @param[in] base Numeric base used to interpret the string.
*
* @return Integer representation of @p str.
*/
-inline int stoi(const std::string &str, std::size_t *pos = 0, int base = 10)
+inline int stoi(const std::string &str, std::size_t *pos = 0, NumericBase base = NumericBase::BASE_10)
{
+ assert(base == NumericBase::BASE_10 || base == NumericBase::BASE_16);
unsigned int x;
std::stringstream ss;
- if(base == 16)
+ if(base == NumericBase::BASE_16)
{
ss << std::hex;
}
@@ -87,15 +79,18 @@ inline int stoi(const std::string &str, std::size_t *pos = 0, int base = 10)
* @note This function implements the same behaviour as std::stoul. The latter
* is missing in some Android toolchains.
*
- * @param[in] str String to be converted to unsigned long.
+ * @param[in] str String to be converted to unsigned long.
+ * @param[in] pos If idx is not a null pointer, the function sets the value of pos to the position of the first character in str after the number.
+ * @param[in] base Numeric base used to interpret the string.
*
* @return Unsigned long representation of @p str.
*/
-inline unsigned long stoul(const std::string &str, std::size_t *pos = 0, int base = 10)
+inline unsigned long stoul(const std::string &str, std::size_t *pos = 0, NumericBase base = NumericBase::BASE_10)
{
+ assert(base == NumericBase::BASE_10 || base == NumericBase::BASE_16);
std::stringstream stream;
unsigned long value = 0;
- if(base == 16)
+ if(base == NumericBase::BASE_16)
{
stream << std::hex;
}
@@ -104,6 +99,24 @@ inline unsigned long stoul(const std::string &str, std::size_t *pos = 0, int bas
return value;
}
+#if(__ANDROID__ || BARE_METAL)
+/** Convert integer and float values to string.
+ *
+ * @note This function implements the same behaviour as std::to_string. The
+ * latter is missing in some Android toolchains.
+ *
+ * @param[in] value Value to be converted to string.
+ *
+ * @return String representation of @p value.
+ */
+template <typename T, typename std::enable_if<std::is_arithmetic<typename std::decay<T>::type>::value, int>::type = 0>
+inline std::string to_string(T && value)
+{
+ std::stringstream stream;
+ stream << std::forward<T>(value);
+ return stream.str();
+}
+
/** Convert string values to float.
*
* @note This function implements the same behaviour as std::stof. The latter
@@ -199,36 +212,6 @@ inline std::string to_string(T &&value)
return ::std::to_string(std::forward<T>(value));
}
-/** Convert string values to integer.
- *
- * @note This function acts as a convenience wrapper around std::stoi. The
- * latter is missing in some Android toolchains.
- *
- * @param[in] args Arguments forwarded to std::stoi.
- *
- * @return Integer representation of input string.
- */
-template <typename... Ts>
-int stoi(Ts &&... args)
-{
- return ::std::stoi(std::forward<Ts>(args)...);
-}
-
-/** Convert string values to unsigned long.
- *
- * @note This function acts as a convenience wrapper around std::stoul. The
- * latter is missing in some Android toolchains.
- *
- * @param[in] args Arguments forwarded to std::stoul.
- *
- * @return Unsigned long representation of input string.
- */
-template <typename... Ts>
-int stoul(Ts &&... args)
-{
- return ::std::stoul(std::forward<Ts>(args)...);
-}
-
/** Convert string values to float.
*
* @note This function acts as a convenience wrapper around std::stof. The
@@ -332,6 +315,20 @@ inline void *align(std::size_t alignment, std::size_t size, void *&ptr, std::siz
return ptr = reinterpret_cast<void *>(aligned);
}
+// std::numeric_limits<T>::lowest
+template <typename T>
+inline T lowest()
+{
+ return std::numeric_limits<T>::lowest();
+}
+
+#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
+template <>
+inline __fp16 lowest<__fp16>()
+{
+ return std::numeric_limits<half_float::half>::lowest();
+}
+#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
// std::isfinite
template <typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>