diff options
author | Moritz Pflanzer <moritz.pflanzer@arm.com> | 2017-09-01 20:41:12 +0100 |
---|---|---|
committer | Anthony Barbier <anthony.barbier@arm.com> | 2018-11-02 16:35:24 +0000 |
commit | a09de0c8b2ed0f1481502d3b023375609362d9e3 (patch) | |
tree | e34b56d9ca69b025d7d9b943cc4df59cd458f6cb /tests/validation/FixedPoint.h | |
parent | 5280071b336d53aff94ca3a6c70ebbe6bf03f4c3 (diff) | |
download | ComputeLibrary-a09de0c8b2ed0f1481502d3b023375609362d9e3.tar.gz |
COMPMID-415: Rename and move tests
The boost validation is now "standalone" in validation_old and builds as
arm_compute_validation_old. The new validation builds now as
arm_compute_validation.
Change-Id: Ib93ba848a25680ac60afb92b461d574a0757150d
Reviewed-on: http://mpd-gerrit.cambridge.arm.com/86187
Tested-by: Kaizen <jeremy.johnson+kaizengerrit@arm.com>
Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Diffstat (limited to 'tests/validation/FixedPoint.h')
-rw-r--r-- | tests/validation/FixedPoint.h | 86 |
1 files changed, 42 insertions, 44 deletions
diff --git a/tests/validation/FixedPoint.h b/tests/validation/FixedPoint.h index 12ffcdfc3d..9691e2a037 100644 --- a/tests/validation/FixedPoint.h +++ b/tests/validation/FixedPoint.h @@ -24,8 +24,8 @@ #ifndef __ARM_COMPUTE_TEST_VALIDATION_FIXEDPOINT_H__ #define __ARM_COMPUTE_TEST_VALIDATION_FIXEDPOINT_H__ -#include "Utils.h" #include "support/ToolchainSupport.h" +#include "tests/Utils.h" #include <cassert> #include <cstdint> @@ -63,6 +63,8 @@ template <> struct promote<uint32_t> { using type = uint64_t; }; template <> struct promote<int32_t> { using type = int64_t; }; template <> struct promote<uint64_t> { using type = uint64_t; }; template <> struct promote<int64_t> { using type = int64_t; }; +template <typename T> +using promote_t = typename promote<T>::type; // clang-format on // *INDENT-ON* } @@ -88,10 +90,6 @@ public: // Static Checks static_assert(std::is_integral<T>::value, "Type is not an integer"); - // Friends - friend struct detail::functions; - friend struct detail::constant_expr<T>; - /** Constructor (from different fixed point type) * * @param[in] val Fixed point @@ -387,7 +385,7 @@ struct functions template <typename T> static bool signbit(fixed_point<T> x) { - return ((x._value >> std::numeric_limits<T>::digits) != 0); + return ((x.raw() >> std::numeric_limits<T>::digits) != 0); } /** Checks if two fixed point numbers are equal * @@ -399,10 +397,10 @@ struct functions template <typename T> static bool isequal(fixed_point<T> x, fixed_point<T> y) { - uint8_t p = std::min(x._fixed_point_position, y._fixed_point_position); + uint8_t p = std::min(x.precision(), y.precision()); x.rescale(p); y.rescale(p); - return (x._value == y._value); + return (x.raw() == y.raw()); } /** Checks if two fixed point number are not equal * @@ -426,10 +424,10 @@ struct functions template <typename T> static bool isgreater(fixed_point<T> x, fixed_point<T> y) { - uint8_t p = std::min(x._fixed_point_position, y._fixed_point_position); + uint8_t p = std::min(x.precision(), y.precision()); x.rescale(p); y.rescale(p); - return (x._value > y._value); + return (x.raw() > y.raw()); } /** Checks if one fixed point is greater or equal than the other * @@ -441,10 +439,10 @@ struct functions template <typename T> static bool isgreaterequal(fixed_point<T> x, fixed_point<T> y) { - uint8_t p = std::min(x._fixed_point_position, y._fixed_point_position); + uint8_t p = std::min(x.precision(), y.precision()); x.rescale(p); y.rescale(p); - return (x._value >= y._value); + return (x.raw() >= y.raw()); } /** Checks if one fixed point is less than the other * @@ -456,10 +454,10 @@ struct functions template <typename T> static bool isless(fixed_point<T> x, fixed_point<T> y) { - uint8_t p = std::min(x._fixed_point_position, y._fixed_point_position); + uint8_t p = std::min(x.precision(), y.precision()); x.rescale(p); y.rescale(p); - return (x._value < y._value); + return (x.raw() < y.raw()); } /** Checks if one fixed point is less or equal than the other * @@ -471,10 +469,10 @@ struct functions template <typename T> static bool islessequal(fixed_point<T> x, fixed_point<T> y) { - uint8_t p = std::min(x._fixed_point_position, y._fixed_point_position); + uint8_t p = std::min(x.precision(), y.precision()); x.rescale(p); y.rescale(p); - return (x._value <= y._value); + return (x.raw() <= y.raw()); } /** Checks if one fixed point is less or greater than the other * @@ -499,7 +497,7 @@ struct functions template <typename T> static fixed_point<T> clamp(fixed_point<T> x, T min, T max) { - return fixed_point<T>(constant_expr<T>::clamp(x._value, min, max), x._fixed_point_position, true); + return fixed_point<T>(constant_expr<T>::clamp(x.raw(), min, max), x.precision(), true); } /** Negate number * @@ -511,12 +509,12 @@ struct functions static fixed_point<T> negate(fixed_point<T> x) { using promoted_T = typename traits::promote<T>::type; - promoted_T val = -x._value; + promoted_T val = -x.raw(); if(OP == OverflowPolicy::SATURATE) { val = constant_expr<T>::saturate_cast(val); } - return fixed_point<T>(static_cast<T>(val), x._fixed_point_position, true); + return fixed_point<T>(static_cast<T>(val), x.precision(), true); } /** Perform addition among two fixed point numbers * @@ -528,19 +526,19 @@ struct functions template <OverflowPolicy OP = OverflowPolicy::SATURATE, typename T> static fixed_point<T> add(fixed_point<T> x, fixed_point<T> y) { - uint8_t p = std::min(x._fixed_point_position, y._fixed_point_position); + uint8_t p = std::min(x.precision(), y.precision()); x.rescale(p); y.rescale(p); if(OP == OverflowPolicy::SATURATE) { using type = typename traits::promote<T>::type; - type val = static_cast<type>(x._value) + static_cast<type>(y._value); + type val = static_cast<type>(x.raw()) + static_cast<type>(y.raw()); val = constant_expr<T>::saturate_cast(val); return fixed_point<T>(static_cast<T>(val), p, true); } else { - return fixed_point<T>(x._value + y._value, p, true); + return fixed_point<T>(x.raw() + y.raw(), p, true); } } /** Perform subtraction among two fixed point numbers @@ -553,19 +551,19 @@ struct functions template <OverflowPolicy OP = OverflowPolicy::SATURATE, typename T> static fixed_point<T> sub(fixed_point<T> x, fixed_point<T> y) { - uint8_t p = std::min(x._fixed_point_position, y._fixed_point_position); + uint8_t p = std::min(x.precision(), y.precision()); x.rescale(p); y.rescale(p); if(OP == OverflowPolicy::SATURATE) { using type = typename traits::promote<T>::type; - type val = static_cast<type>(x._value) - static_cast<type>(y._value); + type val = static_cast<type>(x.raw()) - static_cast<type>(y.raw()); val = constant_expr<T>::saturate_cast(val); return fixed_point<T>(static_cast<T>(val), p, true); } else { - return fixed_point<T>(x._value - y._value, p, true); + return fixed_point<T>(x.raw() - y.raw(), p, true); } } /** Perform multiplication among two fixed point numbers @@ -579,10 +577,10 @@ struct functions static fixed_point<T> mul(fixed_point<T> x, fixed_point<T> y) { using promoted_T = typename traits::promote<T>::type; - uint8_t p_min = std::min(x._fixed_point_position, y._fixed_point_position); - uint8_t p_max = std::max(x._fixed_point_position, y._fixed_point_position); + uint8_t p_min = std::min(x.precision(), y.precision()); + uint8_t p_max = std::max(x.precision(), y.precision()); promoted_T round_factor = (1 << (p_max - 1)); - promoted_T val = ((static_cast<promoted_T>(x._value) * static_cast<promoted_T>(y._value)) + round_factor) >> p_max; + promoted_T val = ((static_cast<promoted_T>(x.raw()) * static_cast<promoted_T>(y.raw())) + round_factor) >> p_max; if(OP == OverflowPolicy::SATURATE) { val = constant_expr<T>::saturate_cast(val); @@ -600,11 +598,11 @@ struct functions static fixed_point<T> div(fixed_point<T> x, fixed_point<T> y) { using promoted_T = typename traits::promote<T>::type; - uint8_t p = std::min(x._fixed_point_position, y._fixed_point_position); - promoted_T denom = static_cast<promoted_T>(y._value); + uint8_t p = std::min(x.precision(), y.precision()); + promoted_T denom = static_cast<promoted_T>(y.raw()); if(denom != 0) { - promoted_T val = (static_cast<promoted_T>(x._value) << std::max(x._fixed_point_position, y._fixed_point_position)) / denom; + promoted_T val = (static_cast<promoted_T>(x.raw()) << std::max(x.precision(), y.precision())) / denom; if(OP == OverflowPolicy::SATURATE) { val = constant_expr<T>::saturate_cast(val); @@ -613,7 +611,7 @@ struct functions } else { - T val = (x._value < 0) ? std::numeric_limits<T>::min() : std::numeric_limits<T>::max(); + T val = (x.raw() < 0) ? std::numeric_limits<T>::min() : std::numeric_limits<T>::max(); return fixed_point<T>(val, p, true); } } @@ -628,12 +626,12 @@ struct functions static fixed_point<T> shift_left(fixed_point<T> x, size_t shift) { using promoted_T = typename traits::promote<T>::type; - promoted_T val = static_cast<promoted_T>(x._value) << shift; + promoted_T val = static_cast<promoted_T>(x.raw()) << shift; if(OP == OverflowPolicy::SATURATE) { val = constant_expr<T>::saturate_cast(val); } - return fixed_point<T>(static_cast<T>(val), x._fixed_point_position, true); + return fixed_point<T>(static_cast<T>(val), x.precision(), true); } /** Shift right * @@ -645,7 +643,7 @@ struct functions template <typename T> static fixed_point<T> shift_right(fixed_point<T> x, size_t shift) { - return fixed_point<T>(x._value >> shift, x._fixed_point_position, true); + return fixed_point<T>(x.raw() >> shift, x.precision(), true); } /** Calculate absolute value * @@ -657,8 +655,8 @@ struct functions static fixed_point<T> abs(fixed_point<T> x) { using promoted_T = typename traits::promote<T>::type; - T val = (x._value < 0) ? constant_expr<T>::saturate_cast(-static_cast<promoted_T>(x._value)) : x._value; - return fixed_point<T>(val, x._fixed_point_position, true); + T val = (x.raw() < 0) ? constant_expr<T>::saturate_cast(-static_cast<promoted_T>(x.raw())) : x.raw(); + return fixed_point<T>(val, x.precision(), true); } /** Calculate the logarithm of a fixed point number * @@ -669,7 +667,7 @@ struct functions template <typename T> static fixed_point<T> log(fixed_point<T> x) { - uint8_t p = x._fixed_point_position; + uint8_t p = x.precision(); auto const_one = fixed_point<T>(static_cast<T>(1), p); // Logarithm of 1 is zero and logarithm of negative values is not defined in R, so return 0. @@ -684,7 +682,7 @@ struct functions } // Remove even powers of 2 - T shift_val = 31 - __builtin_clz(x._value >> p); + T shift_val = 31 - __builtin_clz(x.raw() >> p); x = shift_right(x, shift_val); x = sub(x, const_one); @@ -716,7 +714,7 @@ struct functions template <typename T> static fixed_point<T> exp(fixed_point<T> x) { - uint8_t p = x._fixed_point_position; + uint8_t p = x.precision(); // Constants auto const_one = fixed_point<T>(1, p); auto ln2 = fixed_point<T>(0.6931471, p); @@ -726,7 +724,7 @@ struct functions auto C = fixed_point<T>(0.1763723, p); auto D = fixed_point<T>(0.0435108, p); - T scaled_int_part = detail::constant_expr<T>::to_int(mul(x, inv_ln2)._value, p); + T scaled_int_part = detail::constant_expr<T>::to_int(mul(x, inv_ln2).raw(), p); // Polynomial expansion auto frac_part = sub(x, mul(ln2, fixed_point<T>(scaled_int_part, p))); @@ -753,8 +751,8 @@ struct functions template <typename T> static fixed_point<T> inv_sqrt(fixed_point<T> x) { - const uint8_t p = x._fixed_point_position; - int8_t shift = std::numeric_limits<T>::digits - (p + detail::clz(x._value)); + const uint8_t p = x.precision(); + int8_t shift = std::numeric_limits<T>::digits - (p + detail::clz(x.raw())); shift += std::numeric_limits<T>::is_signed ? 1 : 0; @@ -784,7 +782,7 @@ struct functions template <typename T> static fixed_point<T> tanh(fixed_point<T> x) { - uint8_t p = x._fixed_point_position; + uint8_t p = x.precision(); // Constants auto const_one = fixed_point<T>(1, p); auto const_two = fixed_point<T>(2, p); |