From f68cc3263988b8db3519806d7d8dd5438569bb00 Mon Sep 17 00:00:00 2001 From: Joel Falcou Date: Tue, 20 Dec 2016 20:52:46 +0100 Subject: [PATCH] Fix some rounding funtions implementation (#348) trunc, floor and ceil has been simplified/optimized --- bench/function/scalar/CMakeLists.txt | 4 +- bench/function/scalar/ceil.regular.cpp | 20 +-- bench/function/scalar/ceil.std.cpp | 19 +-- bench/function/scalar/floor.cpp | 20 --- bench/function/scalar/floor.regular.cpp | 20 +++ bench/function/scalar/floor.std.cpp | 21 ++++ bench/function/scalar/trunc.raw.cpp | 21 ++++ bench/function/scalar/trunc.regular.cpp | 18 +-- bench/function/scalar/trunc.std.cpp | 2 +- bench/function/simd/CMakeLists.txt | 1 + bench/function/simd/ceil.cpp | 22 ++-- bench/function/simd/floor.cpp | 2 +- bench/function/simd/trunc.raw.cpp | 22 ++++ bench/function/simd/trunc.regular.cpp | 20 +-- .../simd/arch/common/scalar/function/ceil.hpp | 59 ++++----- .../arch/common/scalar/function/floor.hpp | 58 +++++---- .../arch/common/scalar/function/trunc.hpp | 68 ++++++---- .../simd/arch/common/simd/function/ceil.hpp | 26 ++-- .../simd/arch/common/simd/function/floor.hpp | 45 ++++--- .../simd/arch/common/simd/function/trunc.hpp | 102 ++++++++++----- .../arch/x86/sse2/simd/function/trunc.hpp | 32 +++++ .../arch/x86/sse4_1/simd/function/trunc.hpp | 17 ++- include/boost/simd/function/simd/trunc.hpp | 3 + test/function/scalar/CMakeLists.txt | 10 +- test/function/scalar/ceil.cpp | 72 ----------- test/function/scalar/ceil.regular.cpp | 77 ++++++++++++ test/function/scalar/ceil.std.cpp | 78 ++++++++++++ test/function/scalar/floor.cpp | 74 ----------- test/function/scalar/floor.regular.cpp | 77 ++++++++++++ test/function/scalar/floor.std.cpp | 84 +++++++++++++ test/function/scalar/trunc.cpp | 81 ------------ test/function/scalar/trunc.raw.cpp | 48 +++++++ test/function/scalar/trunc.regular.cpp | 77 ++++++++++++ test/function/scalar/trunc.std.cpp | 84 +++++++++++++ test/function/simd/CMakeLists.txt | 3 +- test/function/simd/ceil.cpp | 95 +++++++------- test/function/simd/floor.cpp | 118 +++++++----------- test/function/simd/trunc.cpp | 117 ----------------- test/function/simd/trunc.raw.cpp | 48 +++++++ test/function/simd/trunc.regular.cpp | 80 ++++++++++++ 40 files changed, 1151 insertions(+), 694 deletions(-) delete mode 100644 bench/function/scalar/floor.cpp create mode 100644 bench/function/scalar/floor.regular.cpp create mode 100644 bench/function/scalar/floor.std.cpp create mode 100644 bench/function/scalar/trunc.raw.cpp create mode 100644 bench/function/simd/trunc.raw.cpp create mode 100644 include/boost/simd/arch/x86/sse2/simd/function/trunc.hpp delete mode 100644 test/function/scalar/ceil.cpp create mode 100644 test/function/scalar/ceil.regular.cpp create mode 100644 test/function/scalar/ceil.std.cpp delete mode 100644 test/function/scalar/floor.cpp create mode 100644 test/function/scalar/floor.regular.cpp create mode 100644 test/function/scalar/floor.std.cpp delete mode 100644 test/function/scalar/trunc.cpp create mode 100644 test/function/scalar/trunc.raw.cpp create mode 100644 test/function/scalar/trunc.regular.cpp create mode 100644 test/function/scalar/trunc.std.cpp delete mode 100644 test/function/simd/trunc.cpp create mode 100644 test/function/simd/trunc.raw.cpp create mode 100644 test/function/simd/trunc.regular.cpp diff --git a/bench/function/scalar/CMakeLists.txt b/bench/function/scalar/CMakeLists.txt index 8dc6cb1af..52f533624 100644 --- a/bench/function/scalar/CMakeLists.txt +++ b/bench/function/scalar/CMakeLists.txt @@ -122,7 +122,8 @@ set(SOURCES ffs.cpp firstbitset.cpp firstbitunset.cpp - floor.cpp + floor.regular.cpp + floor.std.cpp fma.regular.cpp fma.std.cpp fms.cpp @@ -340,6 +341,7 @@ set(SOURCES toint.saturated.cpp touint.regular.cpp touint.saturated.cpp + trunc.raw.cpp trunc.regular.cpp trunc.std.cpp two_add.cpp diff --git a/bench/function/scalar/ceil.regular.cpp b/bench/function/scalar/ceil.regular.cpp index 4a7b5b5ef..1756d2a0d 100644 --- a/bench/function/scalar/ceil.regular.cpp +++ b/bench/function/scalar/ceil.regular.cpp @@ -1,20 +1,20 @@ -// ------------------------------------------------------------------------------------------------- -// Copyright 2016 - NumScale SAS -// -// Distributed under the Boost Software License, Version 1.0. -// See accompanying file LICENSE.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt -// ------------------------------------------------------------------------------------------------- +//================================================================================================== +/** + Copyright 2016 NumScale SAS + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +**/ +//================================================================================================== +#include #include -#include namespace nsb = ns::bench; namespace bs = boost::simd; -DEFINE_SCALAR_BENCH(scalar_ceil, bs::ceil); +DEFINE_SCALAR_BENCH(scalar_regular_ceil, bs::ceil); DEFINE_BENCH_MAIN() { - nsb::for_each(-10, 10); + nsb::for_each(-10, 10); } diff --git a/bench/function/scalar/ceil.std.cpp b/bench/function/scalar/ceil.std.cpp index 031c6043e..06168d9fe 100644 --- a/bench/function/scalar/ceil.std.cpp +++ b/bench/function/scalar/ceil.std.cpp @@ -1,13 +1,14 @@ -// ------------------------------------------------------------------------------------------------- -// Copyright 2016 - NumScale SAS -// -// Distributed under the Boost Software License, Version 1.0. -// See accompanying file LICENSE.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt -// ------------------------------------------------------------------------------------------------- +//================================================================================================== +/** + Copyright 2016 NumScale SAS + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +**/ +//================================================================================================== +#include +#include #include -#include namespace nsb = ns::bench; namespace bs = boost::simd; @@ -16,5 +17,5 @@ DEFINE_SCALAR_BENCH(scalar_std_ceil, bs::std_(bs::ceil)); DEFINE_BENCH_MAIN() { - nsb::for_each(-10, 10); + nsb::for_each(-10, 10); } diff --git a/bench/function/scalar/floor.cpp b/bench/function/scalar/floor.cpp deleted file mode 100644 index 7d8047243..000000000 --- a/bench/function/scalar/floor.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// ------------------------------------------------------------------------------------------------- -// Copyright 2016 - NumScale SAS -// -// Distributed under the Boost Software License, Version 1.0. -// See accompanying file LICENSE.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt -// ------------------------------------------------------------------------------------------------- - -#include -#include - -namespace nsb = ns::bench; -namespace bs = boost::simd; - -DEFINE_SCALAR_BENCH(scalar_floor, bs::floor); - -DEFINE_BENCH_MAIN() -{ - nsb::for_each(-10, 10); -} diff --git a/bench/function/scalar/floor.regular.cpp b/bench/function/scalar/floor.regular.cpp new file mode 100644 index 000000000..34c74d4e4 --- /dev/null +++ b/bench/function/scalar/floor.regular.cpp @@ -0,0 +1,20 @@ +//================================================================================================== +/** + Copyright 2016 NumScale SAS + + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +**/ +//================================================================================================== +#include +#include + +namespace nsb = ns::bench; +namespace bs = boost::simd; + +DEFINE_SCALAR_BENCH(scalar_regular_floor, bs::floor); + +DEFINE_BENCH_MAIN() +{ + nsb::for_each(-10, 10); +} diff --git a/bench/function/scalar/floor.std.cpp b/bench/function/scalar/floor.std.cpp new file mode 100644 index 000000000..dfbe92980 --- /dev/null +++ b/bench/function/scalar/floor.std.cpp @@ -0,0 +1,21 @@ +//================================================================================================== +/** + Copyright 2016 NumScale SAS + + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +**/ +//================================================================================================== +#include +#include +#include + +namespace nsb = ns::bench; +namespace bs = boost::simd; + +DEFINE_SCALAR_BENCH(scalar_std_floor, bs::std_(bs::floor)); + +DEFINE_BENCH_MAIN() +{ + nsb::for_each(-10, 10); +} diff --git a/bench/function/scalar/trunc.raw.cpp b/bench/function/scalar/trunc.raw.cpp new file mode 100644 index 000000000..05a73bc7c --- /dev/null +++ b/bench/function/scalar/trunc.raw.cpp @@ -0,0 +1,21 @@ +//================================================================================================== +/** + Copyright 2016 NumScale SAS + + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +**/ +//================================================================================================== +#include +#include +#include + +namespace nsb = ns::bench; +namespace bs = boost::simd; + +DEFINE_SCALAR_BENCH(scalar_raw_trunc, bs::raw_(bs::trunc)); + +DEFINE_BENCH_MAIN() +{ + nsb::for_each(-10, 10); +} diff --git a/bench/function/scalar/trunc.regular.cpp b/bench/function/scalar/trunc.regular.cpp index bfd6ea34c..91c10e8a9 100644 --- a/bench/function/scalar/trunc.regular.cpp +++ b/bench/function/scalar/trunc.regular.cpp @@ -1,20 +1,20 @@ -// ------------------------------------------------------------------------------------------------- -// Copyright 2016 - NumScale SAS -// -// Distributed under the Boost Software License, Version 1.0. -// See accompanying file LICENSE.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt -// ------------------------------------------------------------------------------------------------- +//================================================================================================== +/** + Copyright 2016 NumScale SAS + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +**/ +//================================================================================================== #include #include namespace nsb = ns::bench; namespace bs = boost::simd; -DEFINE_SCALAR_BENCH(scalar_trunc, bs::trunc); +DEFINE_SCALAR_BENCH(scalar_regular_trunc, bs::trunc); DEFINE_BENCH_MAIN() { - nsb::for_each(-10, 10); + nsb::for_each(-10, 10); } diff --git a/bench/function/scalar/trunc.std.cpp b/bench/function/scalar/trunc.std.cpp index e68a9f01a..f172091ac 100644 --- a/bench/function/scalar/trunc.std.cpp +++ b/bench/function/scalar/trunc.std.cpp @@ -16,5 +16,5 @@ DEFINE_SCALAR_BENCH(scalar_std_trunc, bs::std_(bs::trunc)); DEFINE_BENCH_MAIN() { - nsb::for_each(-10, 10); + nsb::for_each(-10, 10); } diff --git a/bench/function/simd/CMakeLists.txt b/bench/function/simd/CMakeLists.txt index 02217d505..a83cc1b6b 100644 --- a/bench/function/simd/CMakeLists.txt +++ b/bench/function/simd/CMakeLists.txt @@ -347,6 +347,7 @@ set(SOURCES touint.regular.cpp touint.saturated.cpp trunc.regular.cpp + trunc.raw.cpp two_add.cpp quadrant.cpp twopower.cpp diff --git a/bench/function/simd/ceil.cpp b/bench/function/simd/ceil.cpp index 4440b941f..5ea4f52d3 100644 --- a/bench/function/simd/ceil.cpp +++ b/bench/function/simd/ceil.cpp @@ -1,21 +1,21 @@ -// ------------------------------------------------------------------------------------------------- -// Copyright 2016 - NumScale SAS -// -// Distributed under the Boost Software License, Version 1.0. -// See accompanying file LICENSE.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt -// ------------------------------------------------------------------------------------------------- +//================================================================================================== +/** + Copyright 2016 NumScale SAS -#include -#include + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +**/ +//================================================================================================== +#include #include +#include namespace nsb = ns::bench; namespace bs = boost::simd; -DEFINE_SIMD_BENCH(simd_ceil, bs::ceil); +DEFINE_SIMD_BENCH(simd_regular_ceil, bs::ceil); DEFINE_BENCH_MAIN() { - nsb::for_each(-10, 10); + nsb::for_each(-10, 10); } diff --git a/bench/function/simd/floor.cpp b/bench/function/simd/floor.cpp index 2b8409ee4..40cbabd73 100644 --- a/bench/function/simd/floor.cpp +++ b/bench/function/simd/floor.cpp @@ -17,5 +17,5 @@ DEFINE_SIMD_BENCH(simd_floor, bs::floor); DEFINE_BENCH_MAIN() { - nsb::for_each(-10, 10); + nsb::for_each(-10, 10); } diff --git a/bench/function/simd/trunc.raw.cpp b/bench/function/simd/trunc.raw.cpp new file mode 100644 index 000000000..6daa468b4 --- /dev/null +++ b/bench/function/simd/trunc.raw.cpp @@ -0,0 +1,22 @@ +//================================================================================================== +/** + Copyright 2016 NumScale SAS + + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +**/ +//================================================================================================== +#include +#include +#include +#include + +namespace nsb = ns::bench; +namespace bs = boost::simd; + +DEFINE_SIMD_BENCH(simd_raw_trunc, bs::raw_(bs::trunc)); + +DEFINE_BENCH_MAIN() +{ + nsb::for_each(-10, 10); +} diff --git a/bench/function/simd/trunc.regular.cpp b/bench/function/simd/trunc.regular.cpp index a0cd2e0bf..9546e283d 100644 --- a/bench/function/simd/trunc.regular.cpp +++ b/bench/function/simd/trunc.regular.cpp @@ -1,21 +1,21 @@ -// ------------------------------------------------------------------------------------------------- -// Copyright 2016 - NumScale SAS -// -// Distributed under the Boost Software License, Version 1.0. -// See accompanying file LICENSE.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt -// ------------------------------------------------------------------------------------------------- +//================================================================================================== +/** + Copyright 2016 NumScale SAS -#include + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +**/ +//================================================================================================== #include #include +#include namespace nsb = ns::bench; namespace bs = boost::simd; -DEFINE_SIMD_BENCH(simd_trunc, bs::trunc); +DEFINE_SIMD_BENCH(simd_regular_trunc, bs::trunc); DEFINE_BENCH_MAIN() { - nsb::for_each(-10, 10); + nsb::for_each(-10, 10); } diff --git a/include/boost/simd/arch/common/scalar/function/ceil.hpp b/include/boost/simd/arch/common/scalar/function/ceil.hpp index cc569fbfc..f427e80ab 100644 --- a/include/boost/simd/arch/common/scalar/function/ceil.hpp +++ b/include/boost/simd/arch/common/scalar/function/ceil.hpp @@ -1,19 +1,16 @@ //================================================================================================== -/*! - @file - - @copyright 2016 NumScale SAS +/** + Copyright 2016 NumScale SAS Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) -*/ +**/ //================================================================================================== #ifndef BOOST_SIMD_ARCH_COMMON_SCALAR_FUNCTION_CEIL_HPP_INCLUDED #define BOOST_SIMD_ARCH_COMMON_SCALAR_FUNCTION_CEIL_HPP_INCLUDED -#include -#include #include +#include #include #include @@ -21,52 +18,59 @@ namespace boost { namespace simd { namespace ext { namespace bd = boost::dispatch; namespace bs = boost::simd; + + //------------------------------------------------------------------------------------------------ + // Integer cases are no-op BOOST_DISPATCH_OVERLOAD ( ceil_ , (typename A0) , bd::cpu_ - , bd::scalar_< bd::single_ > + , bd::scalar_< bd::integer_ > ) { - BOOST_FORCEINLINE A0 operator() ( A0 a0) const BOOST_NOEXCEPT + BOOST_FORCEINLINE A0 operator()(A0 a0) const BOOST_NOEXCEPT { - #ifdef BOOST_SIMD_HAS_CEILF - return ::ceilf(a0); - #else - return std::ceil(a0); - #endif + return a0; } }; + BOOST_DISPATCH_OVERLOAD ( ceil_ , (typename A0) , bd::cpu_ - , bd::scalar_< bd::double_ > + , bs::std_tag + , bd::scalar_< bd::integer_ > ) { - BOOST_FORCEINLINE A0 operator() ( A0 a0) const BOOST_NOEXCEPT + BOOST_FORCEINLINE A0 operator()(const std_tag&, A0 a0) const BOOST_NOEXCEPT { - return std::ceil(a0); + return a0; } }; + //------------------------------------------------------------------------------------------------ + // FP cases BOOST_DISPATCH_OVERLOAD ( ceil_ , (typename A0) , bd::cpu_ - , bd::scalar_< bd::integer_ > + , bd::scalar_< bd::single_ > ) { - BOOST_FORCEINLINE A0 operator() ( A0 a0) const BOOST_NOEXCEPT + BOOST_FORCEINLINE A0 operator()(A0 a0) const BOOST_NOEXCEPT { - return a0; + #ifdef BOOST_SIMD_HAS_FLOORF + return ::ceilf(a0); + #else + return std::ceil(a0); + #endif } }; + BOOST_DISPATCH_OVERLOAD ( ceil_ , (typename A0) , bd::cpu_ - , bs::std_tag - , bd::scalar_< bd::floating_ > + , bd::scalar_< bd::double_ > ) { - BOOST_FORCEINLINE A0 operator() (const std_tag &, A0 a0) const BOOST_NOEXCEPT + BOOST_FORCEINLINE A0 operator()(A0 a0) const BOOST_NOEXCEPT { return std::ceil(a0); } @@ -76,17 +80,14 @@ namespace boost { namespace simd { namespace ext , (typename A0) , bd::cpu_ , bs::std_tag - , bd::scalar_< bd::integer_ > + , bd::scalar_< bd::floating_ > ) { - BOOST_FORCEINLINE A0 operator() (const std_tag &, A0 a0) const BOOST_NOEXCEPT + BOOST_FORCEINLINE A0 operator()(const std_tag&, A0 a0) const BOOST_NOEXCEPT { - return a0; + return std::ceil(a0); } }; - } } } - #endif - diff --git a/include/boost/simd/arch/common/scalar/function/floor.hpp b/include/boost/simd/arch/common/scalar/function/floor.hpp index aa3536a74..c2995e3a7 100644 --- a/include/boost/simd/arch/common/scalar/function/floor.hpp +++ b/include/boost/simd/arch/common/scalar/function/floor.hpp @@ -1,19 +1,16 @@ //================================================================================================== -/*! - @file - - @copyright 2016 NumScale SAS +/** + Copyright 2016 NumScale SAS Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) -*/ +**/ //================================================================================================== #ifndef BOOST_SIMD_ARCH_COMMON_SCALAR_FUNCTION_FLOOR_HPP_INCLUDED #define BOOST_SIMD_ARCH_COMMON_SCALAR_FUNCTION_FLOOR_HPP_INCLUDED -#include -#include #include +#include #include #include @@ -21,67 +18,74 @@ namespace boost { namespace simd { namespace ext { namespace bd = boost::dispatch; namespace bs = boost::simd; + + //------------------------------------------------------------------------------------------------ + // Integer cases are no-op BOOST_DISPATCH_OVERLOAD ( floor_ , (typename A0) , bd::cpu_ - , bd::scalar_< bd::single_ > + , bd::scalar_< bd::integer_ > ) { - BOOST_FORCEINLINE A0 operator() ( A0 a0) const BOOST_NOEXCEPT + BOOST_FORCEINLINE A0 operator()(A0 a0) const BOOST_NOEXCEPT { - #ifdef BOOST_SIMD_HAS_FLOORF - return ::floorf(a0); - #else - return std::floor(a0); - #endif + return a0; } }; + BOOST_DISPATCH_OVERLOAD ( floor_ , (typename A0) , bd::cpu_ - , bd::scalar_< bd::double_ > + , bs::std_tag + , bd::scalar_< bd::integer_ > ) { - BOOST_FORCEINLINE A0 operator() ( A0 a0) const BOOST_NOEXCEPT + BOOST_FORCEINLINE A0 operator()(const std_tag&, A0 a0) const BOOST_NOEXCEPT { - return std::floor(a0); + return a0; } }; + + //------------------------------------------------------------------------------------------------ + // FP cases BOOST_DISPATCH_OVERLOAD ( floor_ , (typename A0) , bd::cpu_ - , bs::std_tag - , bd::scalar_< bd::floating_ > + , bd::scalar_< bd::single_ > ) { - BOOST_FORCEINLINE A0 operator() (const std_tag &, A0 a0) const BOOST_NOEXCEPT + BOOST_FORCEINLINE A0 operator()(A0 a0) const BOOST_NOEXCEPT { + #ifdef BOOST_SIMD_HAS_FLOORF + return ::floorf(a0); + #else return std::floor(a0); + #endif } }; BOOST_DISPATCH_OVERLOAD ( floor_ , (typename A0) , bd::cpu_ - , bs::std_tag - , bd::scalar_< bd::arithmetic_ > + , bd::scalar_< bd::double_ > ) { - BOOST_FORCEINLINE A0 operator() (const std_tag &, A0 a0) const BOOST_NOEXCEPT + BOOST_FORCEINLINE A0 operator()(A0 a0) const BOOST_NOEXCEPT { - return a0; + return std::floor(a0); } }; BOOST_DISPATCH_OVERLOAD ( floor_ , (typename A0) , bd::cpu_ - , bd::scalar_< bd::integer_ > + , bs::std_tag + , bd::scalar_< bd::floating_ > ) { - BOOST_FORCEINLINE A0 operator()(A0 a0) const BOOST_NOEXCEPT + BOOST_FORCEINLINE A0 operator()(const std_tag&, A0 a0) const BOOST_NOEXCEPT { - return a0; + return std::floor(a0); } }; } } } diff --git a/include/boost/simd/arch/common/scalar/function/trunc.hpp b/include/boost/simd/arch/common/scalar/function/trunc.hpp index 73e2a6095..11b7480c3 100644 --- a/include/boost/simd/arch/common/scalar/function/trunc.hpp +++ b/include/boost/simd/arch/common/scalar/function/trunc.hpp @@ -1,23 +1,20 @@ //================================================================================================== -/*! - @file - - @copyright 2016 NumScale SAS +/** + Copyright 2016 NumScale SAS Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) -*/ +**/ //================================================================================================== #ifndef BOOST_SIMD_ARCH_COMMON_SCALAR_FUNCTION_TRUNC_HPP_INCLUDED #define BOOST_SIMD_ARCH_COMMON_SCALAR_FUNCTION_TRUNC_HPP_INCLUDED -#include -#include -#include -#include -#include #include #include +#include +#include +#include +#include #include #include @@ -25,28 +22,59 @@ namespace boost { namespace simd { namespace ext { namespace bd = boost::dispatch; namespace bs = boost::simd; + + //------------------------------------------------------------------------------------------------ + // Integer cases are no-op BOOST_DISPATCH_OVERLOAD ( trunc_ , (typename A0) , bd::cpu_ , bd::scalar_< bd::integer_ > ) { + BOOST_FORCEINLINE A0 operator()(A0 a0) const BOOST_NOEXCEPT + { + return a0; + } + }; + BOOST_DISPATCH_OVERLOAD ( trunc_ + , (typename A0) + , bd::cpu_ + , bs::raw_tag + , bd::scalar_< bd::integer_ > + ) + { + BOOST_FORCEINLINE A0 operator() (const raw_tag&, A0 a0) const BOOST_NOEXCEPT + { + return a0; + } + }; - BOOST_FORCEINLINE A0 operator() ( A0 a0) const BOOST_NOEXCEPT + BOOST_DISPATCH_OVERLOAD ( trunc_ + , (typename A0) + , bd::cpu_ + , bs::std_tag + , bd::scalar_< bd::integer_ > + ) + { + BOOST_FORCEINLINE A0 operator()(const std_tag&, A0 a0) const BOOST_NOEXCEPT { return a0; } }; + + //------------------------------------------------------------------------------------------------ + // FP cases BOOST_DISPATCH_OVERLOAD ( trunc_ , (typename A0) , bd::cpu_ + , bs::raw_tag , bd::scalar_< bd::floating_ > ) { - BOOST_FORCEINLINE A0 operator() ( A0 a0) const BOOST_NOEXCEPT + BOOST_FORCEINLINE A0 operator()(const raw_tag&, A0 a0) const BOOST_NOEXCEPT { - return bitwise_or(floor(bs::abs(a0)), bitofsign(a0)); + return static_cast(static_cast>(a0)); } }; @@ -57,27 +85,23 @@ namespace boost { namespace simd { namespace ext , bd::scalar_< bd::floating_ > ) { - BOOST_FORCEINLINE A0 operator() (const std_tag & - , A0 a0) const BOOST_NOEXCEPT + BOOST_FORCEINLINE A0 operator()(const std_tag &, A0 a0) const BOOST_NOEXCEPT { return std::trunc(a0); } }; + BOOST_DISPATCH_OVERLOAD ( trunc_ , (typename A0) , bd::cpu_ - , bs::std_tag - , bd::scalar_< bd::integer_ > + , bd::scalar_< bd::floating_ > ) { - BOOST_FORCEINLINE A0 operator() (const std_tag & - , A0 a0) const BOOST_NOEXCEPT + BOOST_FORCEINLINE A0 operator()(A0 a0) const BOOST_NOEXCEPT { - return a0; + return bs::abs(a0) < Maxflint() ? raw_(trunc)(a0) : a0; } }; - } } } - #endif diff --git a/include/boost/simd/arch/common/simd/function/ceil.hpp b/include/boost/simd/arch/common/simd/function/ceil.hpp index 4fafb45f8..16a1af210 100644 --- a/include/boost/simd/arch/common/simd/function/ceil.hpp +++ b/include/boost/simd/arch/common/simd/function/ceil.hpp @@ -1,28 +1,24 @@ //================================================================================================== -/*! - @file - - @copyright 2016 NumScale SAS +/** + Copyright 2016 NumScale SAS Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) -*/ +**/ //================================================================================================== #ifndef BOOST_SIMD_ARCH_COMMON_SIMD_FUNCTION_CEIL_HPP_INCLUDED #define BOOST_SIMD_ARCH_COMMON_SIMD_FUNCTION_CEIL_HPP_INCLUDED -#include -#include -#include -#include -#include -#include +#include +#include +#include namespace boost { namespace simd { namespace ext { namespace bd = boost::dispatch; namespace bs = boost::simd; - BOOST_DISPATCH_OVERLOAD_IF(ceil_ + + BOOST_DISPATCH_OVERLOAD_IF( ceil_ , (typename A0, typename X) , (detail::is_native) , bd::cpu_ @@ -31,8 +27,8 @@ namespace boost { namespace simd { namespace ext { BOOST_FORCEINLINE A0 operator()( const A0& a0) const BOOST_NOEXCEPT { - const A0 d0 = nearbyint(a0); - return if_plus(is_less(d0,a0),d0,One()); + const A0 d0 = trunc(a0); + return if_inc(d0 - -#include -#include -#include -#include - #include +#include +#include +#include namespace boost { namespace simd { namespace ext { - namespace bd = boost::dispatch; - namespace bs = boost::simd; - BOOST_DISPATCH_OVERLOAD_IF(floor_ - , (typename A0, typename X) - , (detail::is_native) - , bd::cpu_ - , bs::pack_, X> - ) - { - BOOST_FORCEINLINE A0 operator()( const A0& a0) const BOOST_NOEXCEPT - { - const A0 d0 = nearbyint(a0); - return if_minus(is_greater(d0,a0),d0,One()); - } - }; - BOOST_DISPATCH_OVERLOAD ( floor_ + namespace bd = boost::dispatch; + namespace bs = boost::simd; + + BOOST_DISPATCH_OVERLOAD_IF( floor_ + , (typename A0, typename X) + , (detail::is_native) + , bd::cpu_ + , bs::pack_, X> + ) + { + BOOST_FORCEINLINE A0 operator()( const A0& a0) const BOOST_NOEXCEPT + { + const A0 d0 = trunc(a0); + return if_dec(d0>a0,d0); + } + }; + + BOOST_DISPATCH_OVERLOAD ( floor_ , (typename A0) , bd::cpu_ , bd::generic_< bd::integer_ > @@ -50,4 +48,3 @@ namespace boost { namespace simd { namespace ext } } } #endif - diff --git a/include/boost/simd/arch/common/simd/function/trunc.hpp b/include/boost/simd/arch/common/simd/function/trunc.hpp index 671954fb4..0769168b2 100644 --- a/include/boost/simd/arch/common/simd/function/trunc.hpp +++ b/include/boost/simd/arch/common/simd/function/trunc.hpp @@ -1,52 +1,96 @@ //================================================================================================== -/*! - @file - - @copyright 2016 NumScale SAS +/** + Copyright 2016 NumScale SAS Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) -*/ +**/ //================================================================================================== #ifndef BOOST_SIMD_ARCH_COMMON_SIMD_FUNCTION_TRUNC_HPP_INCLUDED #define BOOST_SIMD_ARCH_COMMON_SIMD_FUNCTION_TRUNC_HPP_INCLUDED -#include -#include +#include +#include #include -#include -#include -#include +#include +#include +#include +#include +#include namespace boost { namespace simd { namespace ext { - namespace bd = boost::dispatch; - namespace bs = boost::simd; + namespace bd = boost::dispatch; + namespace bs = boost::simd; + + //------------------------------------------------------------------------------------------------ + // Integer cases are no-op + BOOST_DISPATCH_OVERLOAD ( trunc_ + , (typename A0, typename X) + , bd::cpu_ + , bs::pack_, X> + ) + { + BOOST_FORCEINLINE A0 operator()( const A0& a0) const BOOST_NOEXCEPT + { + return a0; + } + }; - BOOST_DISPATCH_OVERLOAD(trunc_ + BOOST_DISPATCH_OVERLOAD ( trunc_ , (typename A0, typename X) , bd::cpu_ + , bs::raw_tag , bs::pack_, X> ) - { - BOOST_FORCEINLINE A0 operator()( const A0& a0) const BOOST_NOEXCEPT - { - return a0; - } - }; - - BOOST_DISPATCH_OVERLOAD_IF(trunc_ + { + BOOST_FORCEINLINE A0 operator()(bs::raw_tag const&, const A0& a0) const BOOST_NOEXCEPT + { + return a0; + } + }; + + BOOST_DISPATCH_OVERLOAD ( trunc_ , (typename A0, typename X) - , (detail::is_native) , bd::cpu_ - , bs::pack_, X> + , bs::std_tag + , bs::pack_, X> ) - { - BOOST_FORCEINLINE A0 operator()( const A0& a0) const BOOST_NOEXCEPT - { - return bitwise_or(floor(bs::abs(a0)), bitofsign(a0)); - } - }; + { + BOOST_FORCEINLINE A0 operator()(bs::std_tag const&, const A0& a0) const BOOST_NOEXCEPT + { + return a0; + } + }; + + //------------------------------------------------------------------------------------------------ + // FP cases + BOOST_DISPATCH_OVERLOAD_IF( trunc_ + , (typename A0, typename X) + , (detail::is_native) + , bd::cpu_ + , bs::pack_, X> + ) + { + BOOST_FORCEINLINE A0 operator()(const A0& a0) const BOOST_NOEXCEPT + { + return if_else( bs::abs(a0) < Maxflint(), raw_(trunc)(a0) , a0); + } + }; + + BOOST_DISPATCH_OVERLOAD_IF( trunc_ + , (typename A0, typename X) + , (detail::is_native) + , bd::cpu_ + , bs::raw_tag + , bs::pack_, X> + ) + { + BOOST_FORCEINLINE A0 operator()(bs::raw_tag const&, const A0& a0) const BOOST_NOEXCEPT + { + return tofloat(toint(a0)); + } + }; } } } #endif diff --git a/include/boost/simd/arch/x86/sse2/simd/function/trunc.hpp b/include/boost/simd/arch/x86/sse2/simd/function/trunc.hpp new file mode 100644 index 000000000..05d1d2714 --- /dev/null +++ b/include/boost/simd/arch/x86/sse2/simd/function/trunc.hpp @@ -0,0 +1,32 @@ +//================================================================================================== +/** + Copyright 2016 Numscale SAS + + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +**/ +//================================================================================================== +#ifndef BOOST_SIMD_ARCH_X86_SSE2_SIMD_FUNCTION_TRUNC_HPP_INCLUDED +#define BOOST_SIMD_ARCH_X86_SSE2_SIMD_FUNCTION_TRUNC_HPP_INCLUDED + +#include + +namespace boost { namespace simd { namespace ext +{ + namespace bd = boost::dispatch; + namespace bs = boost::simd; + + BOOST_DISPATCH_OVERLOAD ( trunc_ + , (typename A0) + , bs::sse2_ + , bs::pack_, bs::sse_> + ) + { + BOOST_FORCEINLINE A0 operator()(const A0 & a0) const BOOST_NOEXCEPT + { + return A0(bs::trunc(a0[0]), bs::trunc(a0[1])); + } + }; +} } } + +#endif diff --git a/include/boost/simd/arch/x86/sse4_1/simd/function/trunc.hpp b/include/boost/simd/arch/x86/sse4_1/simd/function/trunc.hpp index cfb7f268f..e692aa39e 100644 --- a/include/boost/simd/arch/x86/sse4_1/simd/function/trunc.hpp +++ b/include/boost/simd/arch/x86/sse4_1/simd/function/trunc.hpp @@ -1,22 +1,21 @@ //================================================================================================== -/*! - @file +/** + Copyright 2016 Numscale SAS - @Copyright 2016 Numscale SAS - - Distributed under the Boost Software License, Version 1.0. - (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) -*/ + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +**/ //================================================================================================== #ifndef BOOST_SIMD_ARCH_X86_SSE4_1_SIMD_FUNCTION_TRUNC_HPP_INCLUDED #define BOOST_SIMD_ARCH_X86_SSE4_1_SIMD_FUNCTION_TRUNC_HPP_INCLUDED -#include +#include namespace boost { namespace simd { namespace ext { namespace bd = boost::dispatch; namespace bs = boost::simd; + BOOST_DISPATCH_OVERLOAD ( trunc_ , (typename A0) , bs::sse4_1_ @@ -28,6 +27,7 @@ namespace boost { namespace simd { namespace ext return _mm_round_ps(a0, _MM_FROUND_TO_ZERO); } }; + BOOST_DISPATCH_OVERLOAD ( trunc_ , (typename A0) , bs::sse4_1_ @@ -39,7 +39,6 @@ namespace boost { namespace simd { namespace ext return _mm_round_pd(a0, _MM_FROUND_TO_ZERO); } }; - } } } #endif diff --git a/include/boost/simd/function/simd/trunc.hpp b/include/boost/simd/function/simd/trunc.hpp index db5917ed9..e665753f7 100644 --- a/include/boost/simd/function/simd/trunc.hpp +++ b/include/boost/simd/function/simd/trunc.hpp @@ -15,6 +15,9 @@ #include #if defined(BOOST_HW_SIMD_X86_OR_AMD_AVAILABLE) +# if BOOST_HW_SIMD_X86_OR_AMD >= BOOST_HW_SIMD_X86_SSE2_VERSION +# include +# endif # if BOOST_HW_SIMD_X86_OR_AMD >= BOOST_HW_SIMD_X86_SSE4_1_VERSION # include # endif diff --git a/test/function/scalar/CMakeLists.txt b/test/function/scalar/CMakeLists.txt index 380939b85..a8070961b 100644 --- a/test/function/scalar/CMakeLists.txt +++ b/test/function/scalar/CMakeLists.txt @@ -71,7 +71,8 @@ set ( SOURCES bitwise_xor.cpp broadcast.cpp cbrt.cpp - ceil.cpp + ceil.regular.cpp + ceil.std.cpp clz.cpp compare_equal.cpp compare_greater.cpp @@ -127,7 +128,8 @@ set ( SOURCES ffs.cpp firstbitset.cpp firstbitunset.cpp - floor.cpp + floor.regular.cpp + floor.std.cpp fma.regular.cpp fma.pedantic.cpp fms.cpp @@ -375,7 +377,9 @@ set ( SOURCES toint.saturated.cpp touint.regular.cpp touint.saturated.cpp - trunc.cpp + trunc.raw.cpp + trunc.regular.cpp + trunc.std.cpp two_add.cpp quadrant.cpp twopower.cpp diff --git a/test/function/scalar/ceil.cpp b/test/function/scalar/ceil.cpp deleted file mode 100644 index 44f08d18b..000000000 --- a/test/function/scalar/ceil.cpp +++ /dev/null @@ -1,72 +0,0 @@ -//================================================================================================== -/*! - - Copyright 2016 NumScale SAS - - Distributed under the Boost Software License, Version 1.0. - (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) -*/ -//================================================================================================== -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -STF_CASE_TPL (" ceil real", STF_IEEE_TYPES) -{ - namespace bs = boost::simd; - using bs::ceil; - using r_t = decltype(ceil(T())); - // return type conformity test - STF_EXPR_IS(ceil(T()), T); - - // specific values tests -#ifndef BOOST_SIMD_NO_INVALIDS - STF_EQUAL(ceil(bs::Inf()), bs::Inf()); - STF_EQUAL(ceil(bs::Minf()), bs::Minf()); - STF_IEEE_EQUAL(ceil(bs::Nan()), bs::Nan()); -#endif - STF_EQUAL(ceil(bs::Mone()), bs::Mone()); - STF_EQUAL(ceil(bs::One()), bs::One()); - STF_EQUAL(ceil(bs::Zero()), bs::Zero()); - STF_EQUAL(ceil(bs::Pi()), bs::Four()); - STF_EQUAL(ceil(T(-1.1)), r_t(-1)); - STF_EQUAL(ceil(T(1.1)), r_t(2)); -} // end of test for floating_ - -STF_CASE_TPL (" ceil signed_int", STF_SIGNED_INTEGRAL_TYPES) -{ - namespace bs = boost::simd; - using bs::ceil; - - // return type conformity test - STF_EXPR_IS(ceil(T()), T); - - - // specific values tests - STF_EQUAL(ceil(bs::Mone()), bs::Mone()); - STF_EQUAL(ceil(bs::One()), bs::One()); - STF_EQUAL(ceil(bs::Zero()), bs::Zero()); -} // end of test for signed_int_ - -STF_CASE_TPL (" ceil unsigned_int", STF_UNSIGNED_INTEGRAL_TYPES) -{ - namespace bs = boost::simd; - using bs::ceil; - // return type conformity test - STF_EXPR_IS(ceil(T()), T); - - - // specific values tests - STF_EQUAL(ceil(bs::One()), bs::One()); - STF_EQUAL(ceil(bs::Zero()), bs::Zero()); -} // end of test for unsigned_int_ - - diff --git a/test/function/scalar/ceil.regular.cpp b/test/function/scalar/ceil.regular.cpp new file mode 100644 index 000000000..cad04a1fe --- /dev/null +++ b/test/function/scalar/ceil.regular.cpp @@ -0,0 +1,77 @@ +//================================================================================================== +/** + Copyright 2016 NumScale SAS + + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +**/ +//================================================================================================== +#include +#include +#include +#include +#include +#include +#include + +namespace bs = boost::simd; + +STF_CASE_TPL( "Check return type from ceil", STF_NUMERIC_TYPES) +{ + using bs::ceil; + STF_TYPE_IS(decltype(ceil(T())), T); +} + +STF_CASE_TPL( "Check ceil behavior on IEEE types", STF_IEEE_TYPES) +{ + using bs::ceil; + + STF_EQUAL(ceil(T(2.5)), T(3)); + STF_EQUAL(ceil(T(1.6)), T(2)); + STF_EQUAL(ceil(T(1.5)), T(2)); + STF_EQUAL(ceil(T(1.4)), T(2)); + STF_EQUAL(ceil(T(0)), T(0)); + STF_EQUAL(ceil(T(-1.4)), T(-1)); + STF_EQUAL(ceil(T(-1.5)), T(-1)); + STF_EQUAL(ceil(T(-1.6)), T(-1)); + STF_EQUAL(ceil(T(-2.5)), T(-2)); +} + +STF_CASE_TPL( "Check ceil behavior on limit cases", STF_NUMERIC_TYPES) +{ + using bs::ceil; + using bs::Valmin; + using bs::Valmax; + + STF_EQUAL(ceil(Valmin()), Valmin()); + STF_EQUAL(ceil(Valmax()), Valmax()); +} + +STF_CASE_TPL( "Check ceil behavior on IEEE limit cases", STF_IEEE_TYPES) +{ + using bs::ceil; + using bs::Valmin; + using bs::Valmax; + using bs::Inf; + using bs::Minf; + using bs::Nan; + using bs::Maxflint; + + STF_EQUAL(ceil(Inf()) , Inf()); + STF_EQUAL(ceil(Minf()), Minf()); + STF_IEEE_EQUAL(ceil(Nan()) , Nan()); + STF_EQUAL(ceil(Maxflint()+1) , Maxflint()+1); + STF_EQUAL(ceil(Maxflint() ) , Maxflint() ); + STF_EQUAL(ceil(Maxflint()-1) , Maxflint()-1); +} + +STF_CASE_TPL( "Check ceil behavior on integral types", STF_INTEGRAL_TYPES) +{ + using bs::ceil; + + STF_EQUAL(ceil(T(2)), T(2)); + STF_EQUAL(ceil(T(1)), T(1)); + STF_EQUAL(ceil(T(0)), T(0)); + STF_EQUAL(ceil(T(-1)), T(-1)); + STF_EQUAL(ceil(T(-2)), T(-2)); +} diff --git a/test/function/scalar/ceil.std.cpp b/test/function/scalar/ceil.std.cpp new file mode 100644 index 000000000..73b9cd5df --- /dev/null +++ b/test/function/scalar/ceil.std.cpp @@ -0,0 +1,78 @@ +//================================================================================================== +/** + Copyright 2016 NumScale SAS + + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +**/ +//================================================================================================== +#include +#include +#include +#include +#include +#include +#include +#include + +namespace bs = boost::simd; + +STF_CASE_TPL( "Check return type from std(ceil)", STF_NUMERIC_TYPES) +{ + using bs::ceil; + STF_TYPE_IS(decltype(bs::std_(ceil)(T())), T); +} + +STF_CASE_TPL( "Check std(ceil) behavior on IEEE types", STF_IEEE_TYPES) +{ + using bs::ceil; + + STF_EQUAL(bs::std_(ceil)(T(2.5)), T(3)); + STF_EQUAL(bs::std_(ceil)(T(1.6)), T(2)); + STF_EQUAL(bs::std_(ceil)(T(1.5)), T(2)); + STF_EQUAL(bs::std_(ceil)(T(1.4)), T(2)); + STF_EQUAL(bs::std_(ceil)(T(0)), T(0)); + STF_EQUAL(bs::std_(ceil)(T(-1.4)), T(-1)); + STF_EQUAL(bs::std_(ceil)(T(-1.5)), T(-1)); + STF_EQUAL(bs::std_(ceil)(T(-1.6)), T(-1)); + STF_EQUAL(bs::std_(ceil)(T(-2.5)), T(-2)); +} + +STF_CASE_TPL( "Check std(ceil) behavior on limit cases", STF_NUMERIC_TYPES) +{ + using bs::ceil; + using bs::Valmin; + using bs::Valmax; + + STF_EQUAL(bs::std_(ceil)(Valmin()), Valmin()); + STF_EQUAL(bs::std_(ceil)(Valmax()), Valmax()); +} + +STF_CASE_TPL( "Check std(ceil) behavior on IEEE limit cases", STF_IEEE_TYPES) +{ + using bs::ceil; + using bs::Valmin; + using bs::Valmax; + using bs::Inf; + using bs::Minf; + using bs::Nan; + using bs::Maxflint; + + STF_EQUAL(bs::std_(ceil)(Inf()) , Inf()); + STF_EQUAL(bs::std_(ceil)(Minf()), Minf()); + STF_IEEE_EQUAL(bs::std_(ceil)(Nan()) , Nan()); + STF_EQUAL(bs::std_(ceil)(Maxflint()+1) , Maxflint()+1); + STF_EQUAL(bs::std_(ceil)(Maxflint() ) , Maxflint() ); + STF_EQUAL(bs::std_(ceil)(Maxflint()-1) , Maxflint()-1); +} + +STF_CASE_TPL( "Check std(ceil) behavior on integral types", STF_INTEGRAL_TYPES) +{ + using bs::ceil; + + STF_EQUAL(bs::std_(ceil)(T(2)), T(2)); + STF_EQUAL(bs::std_(ceil)(T(1)), T(1)); + STF_EQUAL(bs::std_(ceil)(T(0)), T(0)); + STF_EQUAL(bs::std_(ceil)(T(-1)), T(-1)); + STF_EQUAL(bs::std_(ceil)(T(-2)), T(-2)); +} diff --git a/test/function/scalar/floor.cpp b/test/function/scalar/floor.cpp deleted file mode 100644 index 9f123f84d..000000000 --- a/test/function/scalar/floor.cpp +++ /dev/null @@ -1,74 +0,0 @@ -//================================================================================================== -/*! - - Copyright 2016 NumScale SAS - - Distributed under the Boost Software License, Version 1.0. - (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) -*/ -//================================================================================================== -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -STF_CASE_TPL (" floor real", STF_IEEE_TYPES) -{ - namespace bs = boost::simd; - - using bs::floor; - using r_t = decltype(floor(T())); - - STF_TYPE_IS(r_t, T); - - // specific values tests -#ifndef BOOST_SIMD_NO_INVALIDS - STF_EQUAL(floor(bs::Inf()), bs::Inf()); - STF_EQUAL(floor(bs::Minf()), bs::Minf()); - STF_IEEE_EQUAL(floor(bs::Nan()), bs::Nan()); -#endif - STF_EQUAL(floor(bs::One()), bs::One()); - STF_EQUAL(floor(bs::Mone()), bs::Mone()); - STF_EQUAL(floor(bs::Zero()), bs::Zero()); - STF_EQUAL(floor(bs::Pi()), bs::Three()); - STF_EQUAL(floor(T(-1.1)), r_t(-2)); - STF_EQUAL(floor(T(1.1)), r_t(1)); -} // end of test for floating_ - -STF_CASE_TPL (" floor unsigned_int", STF_UNSIGNED_INTEGRAL_TYPES) -{ - namespace bs = boost::simd; - using bs::floor; - - // return type conformity test - STF_EXPR_IS(floor(T()), T); - - // specific values tests - STF_EQUAL(floor(bs::One()), bs::One()); - STF_EQUAL(floor(bs::Zero()), bs::Zero()); -} // end of test for unsigned_int_ - -STF_CASE_TPL (" floor signed_int", STF_SIGNED_INTEGRAL_TYPES) -{ - namespace bs = boost::simd; - - using bs::floor; - - // return type conformity test - STF_EXPR_IS(floor(T()), T); - - // specific values tests - STF_EQUAL(floor(bs::Mone()), bs::Mone()); - STF_EQUAL(floor(bs::One()), bs::One()); - STF_EQUAL(floor(bs::Zero()), bs::Zero()); -} // end of test for signed_int_ - - diff --git a/test/function/scalar/floor.regular.cpp b/test/function/scalar/floor.regular.cpp new file mode 100644 index 000000000..23015ee93 --- /dev/null +++ b/test/function/scalar/floor.regular.cpp @@ -0,0 +1,77 @@ +//================================================================================================== +/** + Copyright 2016 NumScale SAS + + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +**/ +//================================================================================================== +#include +#include +#include +#include +#include +#include +#include + +namespace bs = boost::simd; + +STF_CASE_TPL( "Check return type from floor", STF_NUMERIC_TYPES) +{ + using bs::floor; + STF_TYPE_IS(decltype(floor(T())), T); +} + +STF_CASE_TPL( "Check floor behavior on IEEE types", STF_IEEE_TYPES) +{ + using bs::floor; + + STF_EQUAL(floor(T(2.5)), T(2)); + STF_EQUAL(floor(T(1.6)), T(1)); + STF_EQUAL(floor(T(1.5)), T(1)); + STF_EQUAL(floor(T(1.4)), T(1)); + STF_EQUAL(floor(T(0)), T(0)); + STF_EQUAL(floor(T(-0.4)), T(-1)); + STF_EQUAL(floor(T(-0.5)), T(-1)); + STF_EQUAL(floor(T(-0.6)), T(-1)); + STF_EQUAL(floor(T(-1.5)), T(-2)); +} + +STF_CASE_TPL( "Check floor behavior on limit cases", STF_NUMERIC_TYPES) +{ + using bs::floor; + using bs::Valmin; + using bs::Valmax; + + STF_EQUAL(floor(Valmin()), Valmin()); + STF_EQUAL(floor(Valmax()), Valmax()); +} + +STF_CASE_TPL( "Check floor behavior on IEEE limit cases", STF_IEEE_TYPES) +{ + using bs::floor; + using bs::Valmin; + using bs::Valmax; + using bs::Inf; + using bs::Minf; + using bs::Nan; + using bs::Maxflint; + + STF_EQUAL(floor(Inf()) , Inf()); + STF_EQUAL(floor(Minf()), Minf()); + STF_IEEE_EQUAL(floor(Nan()) , Nan()); + STF_EQUAL(floor(Maxflint()+1) , Maxflint()+1); + STF_EQUAL(floor(Maxflint() ) , Maxflint() ); + STF_EQUAL(floor(Maxflint()-1) , Maxflint()-1); +} + +STF_CASE_TPL( "Check floor behavior on integral types", STF_INTEGRAL_TYPES) +{ + using bs::floor; + + STF_EQUAL(floor(T(2)), T(2)); + STF_EQUAL(floor(T(1)), T(1)); + STF_EQUAL(floor(T(0)), T(0)); + STF_EQUAL(floor(T(-1)), T(-1)); + STF_EQUAL(floor(T(-2)), T(-2)); +} diff --git a/test/function/scalar/floor.std.cpp b/test/function/scalar/floor.std.cpp new file mode 100644 index 000000000..63e4179c1 --- /dev/null +++ b/test/function/scalar/floor.std.cpp @@ -0,0 +1,84 @@ +//================================================================================================== +/** + Copyright 2016 NumScale SAS + + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +**/ +//================================================================================================== +#include +#include +#include +#include +#include +#include +#include +#include + +namespace bs = boost::simd; + +STF_CASE_TPL( "Check return type from std_(floor)", STF_NUMERIC_TYPES) +{ + using bs::floor; + using bs::std_; + + STF_TYPE_IS(decltype(std_(floor)(T())), T); +} + +STF_CASE_TPL( "Check std_(floor) behavior on IEEE types", STF_IEEE_TYPES) +{ + using bs::floor; + using bs::std_; + + STF_EQUAL(std_(floor)(T(2.5)), T(2)); + STF_EQUAL(std_(floor)(T(1.6)), T(1)); + STF_EQUAL(std_(floor)(T(1.5)), T(1)); + STF_EQUAL(std_(floor)(T(1.4)), T(1)); + STF_EQUAL(std_(floor)(T(0)), T(0)); + STF_EQUAL(std_(floor)(T(-0.4)), T(-1)); + STF_EQUAL(std_(floor)(T(-0.5)), T(-1)); + STF_EQUAL(std_(floor)(T(-0.6)), T(-1)); + STF_EQUAL(std_(floor)(T(-1.5)), T(-2)); +} + +STF_CASE_TPL( "Check std_(floor) behavior on limit cases", STF_NUMERIC_TYPES) +{ + using bs::floor; + using bs::std_; + using bs::Valmin; + using bs::Valmax; + + STF_EQUAL(std_(floor)(Valmin()), Valmin()); + STF_EQUAL(std_(floor)(Valmax()), Valmax()); +} + +STF_CASE_TPL( "Check std_(floor) behavior on IEEE limit cases", STF_IEEE_TYPES) +{ + using bs::floor; + using bs::std_; + using bs::Valmin; + using bs::Valmax; + using bs::Inf; + using bs::Minf; + using bs::Nan; + using bs::Maxflint; + + STF_EQUAL(std_(floor)(Inf()) , Inf()); + STF_EQUAL(std_(floor)(Minf()), Minf()); + STF_IEEE_EQUAL(std_(floor)(Nan()) , Nan()); + STF_EQUAL(std_(floor)(Maxflint()+1) , Maxflint()+1); + STF_EQUAL(std_(floor)(Maxflint() ) , Maxflint() ); + STF_EQUAL(std_(floor)(Maxflint()-1) , Maxflint()-1); +} + +STF_CASE_TPL( "Check std_(floor) behavior on integral types", STF_INTEGRAL_TYPES) +{ + using bs::floor; + using bs::std_; + + STF_EQUAL(std_(floor)(T(2)), T(2)); + STF_EQUAL(std_(floor)(T(1)), T(1)); + STF_EQUAL(std_(floor)(T(0)), T(0)); + STF_EQUAL(std_(floor)(T(-1)), T(-1)); + STF_EQUAL(std_(floor)(T(-2)), T(-2)); +} diff --git a/test/function/scalar/trunc.cpp b/test/function/scalar/trunc.cpp deleted file mode 100644 index b9501af6e..000000000 --- a/test/function/scalar/trunc.cpp +++ /dev/null @@ -1,81 +0,0 @@ -//================================================================================================== -/*! - - Copyright 2016 NumScale SAS - - Distributed under the Boost Software License, Version 1.0. - (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) -*/ -//================================================================================================== -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -STF_CASE_TPL (" trunc real", STF_IEEE_TYPES) -{ - namespace bs = boost::simd; - namespace bd = boost::dispatch; - using bs::trunc; - using r_t = decltype(trunc(T())); - - STF_TYPE_IS(r_t, T); - - // specific values tests -#ifndef BOOST_SIMD_NO_INVALIDS - STF_EQUAL(trunc(bs::Inf()), bs::Inf()); - STF_EQUAL(trunc(bs::Minf()), bs::Minf()); - STF_IEEE_EQUAL(trunc(bs::Nan()), bs::Nan()); -#endif - STF_EQUAL(trunc(bs::One()), bs::One()); - STF_EQUAL(trunc(bs::Mone()), bs::Mone()); - STF_EQUAL(trunc(bs::Zero()), bs::Zero()); - STF_EQUAL(trunc(bs::Pi()), bs::Three()); - STF_EQUAL(trunc(T(1.4)), T(1)); - STF_EQUAL(trunc(T(1.5)), T(1)); - STF_EQUAL(trunc(T(1.6)), T(1)); - STF_EQUAL(trunc(T(2.5)), T(2)); - STF_EQUAL(trunc(T(-1.4)), T(-1)); - STF_EQUAL(trunc(T(-1.5)), T(-1)); - STF_EQUAL(trunc(T(-1.6)), T(-1)); - STF_EQUAL(trunc(T(-2.5)), T(-2)); -} // end of test for floating_ - -STF_CASE_TPL (" trunc unsigned_int", STF_UNSIGNED_INTEGRAL_TYPES) -{ - namespace bs = boost::simd; - namespace bd = boost::dispatch; - using bs::trunc; - using r_t = decltype(trunc(T())); - - // return type conformity test - STF_TYPE_IS(r_t, T); - - // specific values tests - STF_EQUAL(trunc(bs::One()), bs::One()); - STF_EQUAL(trunc(bs::Zero()), bs::Zero()); -} // end of test for unsigned_int_ - -STF_CASE_TPL (" trunc signed_int", STF_SIGNED_INTEGRAL_TYPES) -{ - namespace bs = boost::simd; - namespace bd = boost::dispatch; - using bs::trunc; - using r_t = decltype(trunc(T())); - - // return type conformity test - STF_TYPE_IS(r_t, T); - - // specific values tests - STF_EQUAL(trunc(bs::Mone()), bs::Mone()); - STF_EQUAL(trunc(bs::One()), bs::One()); - STF_EQUAL(trunc(bs::Zero()), bs::Zero()); -} // end of test for signed_int_ - diff --git a/test/function/scalar/trunc.raw.cpp b/test/function/scalar/trunc.raw.cpp new file mode 100644 index 000000000..669ad9458 --- /dev/null +++ b/test/function/scalar/trunc.raw.cpp @@ -0,0 +1,48 @@ +//================================================================================================== +/** + Copyright 2016 NumScale SAS + + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +**/ +//================================================================================================== +#include +#include +#include + +namespace bs = boost::simd; + +STF_CASE_TPL( "Check return type from raw_(trunc)", STF_NUMERIC_TYPES) +{ + using bs::trunc; + using bs::raw_; + STF_TYPE_IS(decltype(raw_(trunc)(T())), T); +} + +STF_CASE_TPL( "Check raw_(trunc) behavior on IEEE types", STF_IEEE_TYPES) +{ + using bs::trunc; + using bs::raw_; + + STF_EQUAL(raw_(trunc)(T(2.5)), T(2)); + STF_EQUAL(raw_(trunc)(T(1.6)), T(1)); + STF_EQUAL(raw_(trunc)(T(1.5)), T(1)); + STF_EQUAL(raw_(trunc)(T(1.4)), T(1)); + STF_EQUAL(raw_(trunc)(T(0)), T(0)); + STF_EQUAL(raw_(trunc)(T(-1.4)), T(-1)); + STF_EQUAL(raw_(trunc)(T(-1.5)), T(-1)); + STF_EQUAL(raw_(trunc)(T(-1.6)), T(-1)); + STF_EQUAL(raw_(trunc)(T(-2.5)), T(-2)); +} + +STF_CASE_TPL( "Check raw_(trunc) behavior on integral types", STF_INTEGRAL_TYPES) +{ + using bs::trunc; + using bs::raw_; + + STF_EQUAL(raw_(trunc)(T(2)), T(2)); + STF_EQUAL(raw_(trunc)(T(1)), T(1)); + STF_EQUAL(raw_(trunc)(T(0)), T(0)); + STF_EQUAL(raw_(trunc)(T(-1)), T(-1)); + STF_EQUAL(raw_(trunc)(T(-2)), T(-2)); +} diff --git a/test/function/scalar/trunc.regular.cpp b/test/function/scalar/trunc.regular.cpp new file mode 100644 index 000000000..df401089a --- /dev/null +++ b/test/function/scalar/trunc.regular.cpp @@ -0,0 +1,77 @@ +//================================================================================================== +/** + Copyright 2016 NumScale SAS + + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +**/ +//================================================================================================== +#include +#include +#include +#include +#include +#include +#include + +namespace bs = boost::simd; + +STF_CASE_TPL( "Check return type from trunc", STF_NUMERIC_TYPES) +{ + using bs::trunc; + STF_TYPE_IS(decltype(trunc(T())), T); +} + +STF_CASE_TPL( "Check trunc behavior on IEEE types", STF_IEEE_TYPES) +{ + using bs::trunc; + + STF_EQUAL(trunc(T(2.5)), T(2)); + STF_EQUAL(trunc(T(1.6)), T(1)); + STF_EQUAL(trunc(T(1.5)), T(1)); + STF_EQUAL(trunc(T(1.4)), T(1)); + STF_EQUAL(trunc(T(0)), T(0)); + STF_EQUAL(trunc(T(-1.4)), T(-1)); + STF_EQUAL(trunc(T(-1.5)), T(-1)); + STF_EQUAL(trunc(T(-1.6)), T(-1)); + STF_EQUAL(trunc(T(-2.5)), T(-2)); +} + +STF_CASE_TPL( "Check trunc behavior on limit cases", STF_NUMERIC_TYPES) +{ + using bs::trunc; + using bs::Valmin; + using bs::Valmax; + + STF_EQUAL(trunc(Valmin()), Valmin()); + STF_EQUAL(trunc(Valmax()), Valmax()); +} + +STF_CASE_TPL( "Check trunc behavior on IEEE limit cases", STF_IEEE_TYPES) +{ + using bs::trunc; + using bs::Valmin; + using bs::Valmax; + using bs::Inf; + using bs::Minf; + using bs::Nan; + using bs::Maxflint; + + STF_EQUAL(trunc(Inf()) , Inf()); + STF_EQUAL(trunc(Minf()), Minf()); + STF_IEEE_EQUAL(trunc(Nan()) , Nan()); + STF_EQUAL(trunc(Maxflint()+1) , Maxflint()+1); + STF_EQUAL(trunc(Maxflint() ) , Maxflint() ); + STF_EQUAL(trunc(Maxflint()-1) , Maxflint()-1); +} + +STF_CASE_TPL( "Check trunc behavior on integral types", STF_INTEGRAL_TYPES) +{ + using bs::trunc; + + STF_EQUAL(trunc(T(2)), T(2)); + STF_EQUAL(trunc(T(1)), T(1)); + STF_EQUAL(trunc(T(0)), T(0)); + STF_EQUAL(trunc(T(-1)), T(-1)); + STF_EQUAL(trunc(T(-2)), T(-2)); +} diff --git a/test/function/scalar/trunc.std.cpp b/test/function/scalar/trunc.std.cpp new file mode 100644 index 000000000..94549291c --- /dev/null +++ b/test/function/scalar/trunc.std.cpp @@ -0,0 +1,84 @@ +//================================================================================================== +/** + Copyright 2016 NumScale SAS + + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +**/ +//================================================================================================== +#include +#include +#include +#include +#include +#include +#include +#include + +namespace bs = boost::simd; + +STF_CASE_TPL( "Check return type from std_(trunc)", STF_NUMERIC_TYPES) +{ + using bs::trunc; + using bs::std_; + + STF_TYPE_IS(decltype(std_(trunc)(T())), T); +} + +STF_CASE_TPL( "Check std_(trunc) behavior on IEEE types", STF_IEEE_TYPES) +{ + using bs::trunc; + using bs::std_; + + STF_EQUAL(std_(trunc)(T(2.5)), T(2)); + STF_EQUAL(std_(trunc)(T(1.6)), T(1)); + STF_EQUAL(std_(trunc)(T(1.5)), T(1)); + STF_EQUAL(std_(trunc)(T(1.4)), T(1)); + STF_EQUAL(std_(trunc)(T(0)), T(0)); + STF_EQUAL(std_(trunc)(T(-1.4)), T(-1)); + STF_EQUAL(std_(trunc)(T(-1.5)), T(-1)); + STF_EQUAL(std_(trunc)(T(-1.6)), T(-1)); + STF_EQUAL(std_(trunc)(T(-2.5)), T(-2)); +} + +STF_CASE_TPL( "Check std_(trunc) behavior on limit cases", STF_NUMERIC_TYPES) +{ + using bs::trunc; + using bs::std_; + using bs::Valmin; + using bs::Valmax; + + STF_EQUAL(std_(trunc)(Valmin()), Valmin()); + STF_EQUAL(std_(trunc)(Valmax()), Valmax()); +} + +STF_CASE_TPL( "Check std_(trunc) behavior on IEEE limit cases", STF_IEEE_TYPES) +{ + using bs::trunc; + using bs::std_; + using bs::Valmin; + using bs::Valmax; + using bs::Inf; + using bs::Minf; + using bs::Nan; + using bs::Maxflint; + + STF_EQUAL(std_(trunc)(Inf()) , Inf()); + STF_EQUAL(std_(trunc)(Minf()), Minf()); + STF_IEEE_EQUAL(std_(trunc)(Nan()) , Nan()); + STF_EQUAL(std_(trunc)(Maxflint()+1) , Maxflint()+1); + STF_EQUAL(std_(trunc)(Maxflint() ) , Maxflint() ); + STF_EQUAL(std_(trunc)(Maxflint()-1) , Maxflint()-1); +} + +STF_CASE_TPL( "Check std_(trunc) behavior on integral types", STF_INTEGRAL_TYPES) +{ + using bs::trunc; + using bs::std_; + + STF_EQUAL(std_(trunc)(T(2)), T(2)); + STF_EQUAL(std_(trunc)(T(1)), T(1)); + STF_EQUAL(std_(trunc)(T(0)), T(0)); + STF_EQUAL(std_(trunc)(T(-1)), T(-1)); + STF_EQUAL(std_(trunc)(T(-2)), T(-2)); +} diff --git a/test/function/simd/CMakeLists.txt b/test/function/simd/CMakeLists.txt index 61068cbe9..41196c140 100644 --- a/test/function/simd/CMakeLists.txt +++ b/test/function/simd/CMakeLists.txt @@ -373,7 +373,8 @@ set ( SOURCES toint.saturated.cpp touint.regular.cpp touint.saturated.cpp - trunc.cpp + trunc.raw.cpp + trunc.regular.cpp quadrant.cpp two_add.cpp twopower.cpp diff --git a/test/function/simd/ceil.cpp b/test/function/simd/ceil.cpp index c1f34ada6..6a6fad450 100644 --- a/test/function/simd/ceil.cpp +++ b/test/function/simd/ceil.cpp @@ -1,73 +1,80 @@ //================================================================================================== -/*! - @file - +/** Copyright 2016 NumScale SAS Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) -*/ +**/ //================================================================================================== -#include #include -#include -#include -#include -#include +#include +#include #include -#include +#include #include -#include -#include -#include -#include +#include +#include + +namespace bs = boost::simd; template void test(Env& $) { - namespace bs = boost::simd; - namespace bd = boost::dispatch; using p_t = bs::pack; - T a1[N], b[N]; + T a[N], b[N]; + for(int i = 0; i < N; ++i) { - a1[i] = ((i%2) ? T(i*2) : T(-2*i))/T(3); - b[i] = bs::ceil(a1[i]) ; + a[i] = ((i%2) ? T(i*2) : T(-2*i))/T(3); + b[i] = bs::ceil(a[i]) ; } - p_t aa1(&a1[0], &a1[0]+N); - p_t bb (&b[0], &b[0]+N); - STF_IEEE_EQUAL(bs::ceil(aa1), bb); + + p_t aa(&a[0], &a[0]+N); + p_t bb(&b[0], &b[0]+N); + + STF_IEEE_EQUAL(bs::ceil(aa), bb); } -STF_CASE_TPL("Check ceil on pack" , STF_NUMERIC_TYPES) +STF_CASE_TPL("Check ceil behavior on pack" , STF_NUMERIC_TYPES) { - namespace bs = boost::simd; - using p_t = bs::pack; - static const std::size_t N = bs::cardinal_of::value; + static const std::size_t N = bs::pack::static_size; + test($); test($); test($); } -STF_CASE_TPL (" ceil real", STF_IEEE_TYPES) +STF_CASE_TPL( "Check return type from ceil", STF_NUMERIC_TYPES) +{ + using bs::ceil; + STF_TYPE_IS(decltype(ceil(bs::pack())), bs::pack); +} + +STF_CASE_TPL( "Check ceil behavior on limit cases", STF_NUMERIC_TYPES) { - namespace bs = boost::simd; using bs::ceil; - using p_t = bs::pack; - // return type conformity test - STF_EXPR_IS(ceil(p_t()), p_t); + using bs::Valmin; + using bs::Valmax; - // specific values tests -#ifndef BOOST_SIMD_NO_INVALIDS - STF_EQUAL(ceil(bs::Inf()), bs::Inf()); - STF_EQUAL(ceil(bs::Minf()), bs::Minf()); - STF_IEEE_EQUAL(ceil(bs::Nan()), bs::Nan()); -#endif - STF_EQUAL(ceil(bs::Mone()), bs::Mone()); - STF_EQUAL(ceil(bs::One()), bs::One()); - STF_EQUAL(ceil(bs::Zero()), bs::Zero()); - STF_EQUAL(ceil(bs::Pi()), bs::Four()); - STF_EQUAL(ceil(p_t(-1.1)), p_t(-1)); - STF_EQUAL(ceil(p_t(1.1)), p_t(2)); -} // end of test for floating_ + STF_EQUAL(ceil(Valmin>()), Valmin>()); + STF_EQUAL(ceil(Valmax>()), Valmax>()); +} + +STF_CASE_TPL( "Check ceil behavior on IEEE limit cases", STF_IEEE_TYPES) +{ + using bs::ceil; + using bs::Valmin; + using bs::Valmax; + using bs::Inf; + using bs::Minf; + using bs::Nan; + using bs::Maxflint; + + STF_EQUAL(ceil(Inf>()) , Inf>() ); + STF_EQUAL(ceil(Minf>()) , Minf>() ); + STF_IEEE_EQUAL(ceil(Nan>()) , Nan>() ); + STF_EQUAL(ceil(Maxflint>()+1), Maxflint>()+1 ); + STF_EQUAL(ceil(Maxflint>() ), Maxflint>() ); + STF_EQUAL(ceil(Maxflint>()-1), Maxflint>()-1 ); +} diff --git a/test/function/simd/floor.cpp b/test/function/simd/floor.cpp index cf0c57db0..4ff35b6cc 100644 --- a/test/function/simd/floor.cpp +++ b/test/function/simd/floor.cpp @@ -1,110 +1,80 @@ //================================================================================================== -/*! - @file - +/** Copyright 2016 NumScale SAS Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) -*/ +**/ //================================================================================================== -#include #include -#include -#include -#include -#include +#include +#include #include -#include +#include #include -#include -#include -#include -#include +#include +#include +namespace bs = boost::simd; template void test(Env& $) { - namespace bs = boost::simd; - namespace bd = boost::dispatch; using p_t = bs::pack; - T a1[N], b[N]; + T a[N], b[N]; + for(int i = 0; i < N; ++i) { - a1[i] = ((i%2) ? T(i*2) : T(-2*i))/T(3); - b[i] = bs::floor(a1[i]) ; + a[i] = ((i%2) ? T(i*2) : T(-2*i))/T(3); + b[i] = bs::floor(a[i]) ; } - p_t aa1(&a1[0], &a1[0]+N); - p_t bb (&b[0], &b[0]+N); - STF_IEEE_EQUAL(bs::floor(aa1), bb); + + p_t aa(&a[0], &a[0]+N); + p_t bb(&b[0], &b[0]+N); + + STF_IEEE_EQUAL(bs::floor(aa), bb); } -STF_CASE_TPL("Check floor on pack" , STF_NUMERIC_TYPES) +STF_CASE_TPL("Check floor behavior on pack" , STF_NUMERIC_TYPES) { - namespace bs = boost::simd; - using p_t = bs::pack; - static const std::size_t N = bs::cardinal_of::value; + static const std::size_t N = bs::pack::static_size; + test($); test($); test($); } - - -STF_CASE_TPL (" floor real", STF_IEEE_TYPES) +STF_CASE_TPL( "Check return type from floor", STF_NUMERIC_TYPES) { - namespace bs = boost::simd; - using bs::floor; - using p_t = bs::pack; - using r_t = decltype(floor(p_t())); - - STF_TYPE_IS(r_t, p_t); - - // specific values tests -#ifndef BOOST_SIMD_NO_INVALIDS - STF_EQUAL(floor(bs::Inf()), bs::Inf()); - STF_EQUAL(floor(bs::Minf()), bs::Minf()); - STF_IEEE_EQUAL(floor(bs::Nan()), bs::Nan()); -#endif - STF_EQUAL(floor(bs::One()), bs::One()); - STF_EQUAL(floor(bs::Mone()), bs::Mone()); - STF_EQUAL(floor(bs::Zero()), bs::Zero()); - STF_EQUAL(floor(bs::Pi()), bs::Three()); - STF_EQUAL(floor(p_t(-1.1)), r_t(-2)); - STF_EQUAL(floor(p_t(1.1)), r_t(1)); -} // end of test for floating_ + STF_TYPE_IS(decltype(floor(bs::pack())), bs::pack); +} -STF_CASE_TPL (" floor unsigned_int", STF_UNSIGNED_INTEGRAL_TYPES) +STF_CASE_TPL( "Check floor behavior on limit cases", STF_NUMERIC_TYPES) { - namespace bs = boost::simd; using bs::floor; - using p_t = bs::pack; - - // return type conformity test - STF_EXPR_IS(floor(p_t()), p_t); + using bs::Valmin; + using bs::Valmax; - // specific values tests - STF_EQUAL(floor(bs::One()), bs::One()); - STF_EQUAL(floor(bs::Zero()), bs::Zero()); -} // end of test for unsigned_int_ + STF_EQUAL(floor(Valmin>()), Valmin>()); + STF_EQUAL(floor(Valmax>()), Valmax>()); +} -STF_CASE_TPL (" floor signed_int", STF_SIGNED_INTEGRAL_TYPES) +STF_CASE_TPL( "Check floor behavior on IEEE limit cases", STF_IEEE_TYPES) { - namespace bs = boost::simd; - using bs::floor; - using p_t = bs::pack; - - // return type conformity test - STF_EXPR_IS(floor(p_t()), p_t); - - // specific values tests - STF_EQUAL(floor(bs::Mone()), bs::Mone()); - STF_EQUAL(floor(bs::One()), bs::One()); - STF_EQUAL(floor(bs::Zero()), bs::Zero()); -} // end of test for signed_int_ - - + using bs::Valmin; + using bs::Valmax; + using bs::Inf; + using bs::Minf; + using bs::Nan; + using bs::Maxflint; + + STF_EQUAL(floor(Inf>()) , Inf>() ); + STF_EQUAL(floor(Minf>()) , Minf>() ); + STF_IEEE_EQUAL(floor(Nan>()) , Nan>() ); + STF_EQUAL(floor(Maxflint>()+1), Maxflint>()+1 ); + STF_EQUAL(floor(Maxflint>() ), Maxflint>() ); + STF_EQUAL(floor(Maxflint>()-1), Maxflint>()-1 ); +} diff --git a/test/function/simd/trunc.cpp b/test/function/simd/trunc.cpp deleted file mode 100644 index 01609ae82..000000000 --- a/test/function/simd/trunc.cpp +++ /dev/null @@ -1,117 +0,0 @@ -//================================================================================================== -/*! - @file - - Copyright 2016 NumScale SAS - - Distributed under the Boost Software License, Version 1.0. - (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) -*/ -//================================================================================================== -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -template -void test(Env& $) -{ - namespace bs = boost::simd; - namespace bd = boost::dispatch; - using p_t = bs::pack; - - T a1[N], b[N]; - for(int i = 0; i < N; ++i) - { - a1[i] = ((i%2) ? T(i*2) : T(-2*i))/T(3); - b[i] = bs::trunc(a1[i]) ; - } - p_t aa1(&a1[0], &a1[0]+N); - p_t bb (&b[0], &b[0]+N); - STF_IEEE_EQUAL(bs::trunc(aa1), bb); -} - -STF_CASE_TPL("Check trunc on pack" , STF_NUMERIC_TYPES) -{ - namespace bs = boost::simd; - using p_t = bs::pack; - static const std::size_t N = bs::cardinal_of::value; - test($); - test($); - test($); -} - - - -STF_CASE_TPL (" trunc real", STF_IEEE_TYPES) -{ - namespace bs = boost::simd; - namespace bd = boost::dispatch; - using bs::trunc; - using p_t = bs::pack; - using r_t = decltype(trunc(p_t())); - - STF_TYPE_IS(r_t, p_t); - - // specific values tests -#ifndef BOOST_SIMD_NO_INVALIDS - STF_EQUAL(trunc(bs::Inf()), bs::Inf()); - STF_EQUAL(trunc(bs::Minf()), bs::Minf()); - STF_IEEE_EQUAL(trunc(bs::Nan()), bs::Nan()); -#endif - STF_EQUAL(trunc(bs::One()), bs::One()); - STF_EQUAL(trunc(bs::Mone()), bs::Mone()); - STF_EQUAL(trunc(bs::Zero()), bs::Zero()); - STF_EQUAL(trunc(bs::Pi()), bs::Three()); - STF_EQUAL(trunc(p_t(1.4)), p_t(1)); - STF_EQUAL(trunc(p_t(1.5)), p_t(1)); - STF_EQUAL(trunc(p_t(1.6)), p_t(1)); - STF_EQUAL(trunc(p_t(2.5)), p_t(2)); - STF_EQUAL(trunc(p_t(-1.4)), p_t(-1)); - STF_EQUAL(trunc(p_t(-1.5)), p_t(-1)); - STF_EQUAL(trunc(p_t(-1.6)), p_t(-1)); - STF_EQUAL(trunc(p_t(-2.5)), p_t(-2)); -} // end of test for floating_ - -STF_CASE_TPL (" trunc unsigned_int", STF_UNSIGNED_INTEGRAL_TYPES) -{ - namespace bs = boost::simd; - namespace bd = boost::dispatch; - using bs::trunc; - using p_t = bs::pack; - using r_t = decltype(trunc(p_t())); - - // return type conformity test - STF_TYPE_IS(r_t, p_t); - - // specific values tests - STF_EQUAL(trunc(bs::One()), bs::One()); - STF_EQUAL(trunc(bs::Zero()), bs::Zero()); -} // end of test for unsigned_int_ - -STF_CASE_TPL (" trunc signed_int", STF_SIGNED_INTEGRAL_TYPES) -{ - namespace bs = boost::simd; - namespace bd = boost::dispatch; - using bs::trunc; - using p_t = bs::pack; - using r_t = decltype(trunc(p_t())); - - // return type conformity test - STF_TYPE_IS(r_t, p_t); - - // specific values tests - STF_EQUAL(trunc(bs::Mone()), bs::Mone()); - STF_EQUAL(trunc(bs::One()), bs::One()); - STF_EQUAL(trunc(bs::Zero()), bs::Zero()); -} // end of test for signed_int_ - diff --git a/test/function/simd/trunc.raw.cpp b/test/function/simd/trunc.raw.cpp new file mode 100644 index 000000000..feb60ca72 --- /dev/null +++ b/test/function/simd/trunc.raw.cpp @@ -0,0 +1,48 @@ +//================================================================================================== +/** + Copyright 2016 NumScale SAS + + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +**/ +//================================================================================================== +#include +#include +#include +#include + +namespace bs = boost::simd; + +template +void test(Env& $) +{ + using p_t = bs::pack; + + T a[N], b[N]; + + for(int i = 0; i < N; ++i) + { + a[i] = ((i%2) ? T(i*2) : T(-2*i))/T(3); + b[i] = bs::raw_(bs::trunc)(a[i]) ; + } + + p_t aa(&a[0], &a[0]+N); + p_t bb(&b[0], &b[0]+N); + + STF_IEEE_EQUAL(bs::raw_(bs::trunc)(aa), bb); +} + +STF_CASE_TPL("Check raw(trunc) behavior on pack" , STF_NUMERIC_TYPES) +{ + static const std::size_t N = bs::pack::static_size; + + test($); + test($); + test($); +} + +STF_CASE_TPL( "Check return type from raw(trunc)", STF_NUMERIC_TYPES) +{ + using bs::trunc; + STF_TYPE_IS(decltype(bs::raw_(bs::trunc)(bs::pack())), bs::pack); +} diff --git a/test/function/simd/trunc.regular.cpp b/test/function/simd/trunc.regular.cpp new file mode 100644 index 000000000..d609724d1 --- /dev/null +++ b/test/function/simd/trunc.regular.cpp @@ -0,0 +1,80 @@ +//================================================================================================== +/** + Copyright 2016 NumScale SAS + + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +**/ +//================================================================================================== +#include +#include +#include +#include +#include +#include +#include +#include + +namespace bs = boost::simd; + +template +void test(Env& $) +{ + using p_t = bs::pack; + + T a[N], b[N]; + + for(int i = 0; i < N; ++i) + { + a[i] = ((i%2) ? T(i*2) : T(-2*i))/T(3); + b[i] = bs::trunc(a[i]) ; + } + + p_t aa(&a[0], &a[0]+N); + p_t bb(&b[0], &b[0]+N); + + STF_IEEE_EQUAL(bs::trunc(aa), bb); +} + +STF_CASE_TPL("Check trunc behavior on pack" , STF_NUMERIC_TYPES) +{ + static const std::size_t N = bs::pack::static_size; + + test($); + test($); + test($); +} + +STF_CASE_TPL( "Check return type from trunc", STF_NUMERIC_TYPES) +{ + using bs::trunc; + STF_TYPE_IS(decltype(trunc(bs::pack())), bs::pack); +} + +STF_CASE_TPL( "Check trunc behavior on limit cases", STF_NUMERIC_TYPES) +{ + using bs::trunc; + using bs::Valmin; + using bs::Valmax; + + STF_EQUAL(trunc(Valmin>()), Valmin>()); + STF_EQUAL(trunc(Valmax>()), Valmax>()); +} + +STF_CASE_TPL( "Check trunc behavior on IEEE limit cases", STF_IEEE_TYPES) +{ + using bs::trunc; + using bs::Valmin; + using bs::Valmax; + using bs::Inf; + using bs::Minf; + using bs::Nan; + using bs::Maxflint; + + STF_EQUAL(trunc(Inf>()) , Inf>() ); + STF_EQUAL(trunc(Minf>()) , Minf>() ); + STF_IEEE_EQUAL(trunc(Nan>()) , Nan>() ); + STF_EQUAL(trunc(Maxflint>()+1), Maxflint>()+1 ); + STF_EQUAL(trunc(Maxflint>() ), Maxflint>() ); + STF_EQUAL(trunc(Maxflint>()-1), Maxflint>()-1 ); +}