Skip to content

Commit

Permalink
Fix #13 - Implements logical_not
Browse files Browse the repository at this point in the history
  • Loading branch information
jfalcou committed Feb 18, 2019
1 parent 1cbf23e commit d4365d0
Show file tree
Hide file tree
Showing 18 changed files with 392 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/eve/function/logical_not.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
#define EVE_FUNCTION_LOGICAL_NOT_HPP_INCLUDED

#include <eve/function/scalar/logical_not.hpp>
//#include <eve/function/simd/logical_not.hpp>

#include <eve/function/simd/logical_not.hpp>
#endif
16 changes: 16 additions & 0 deletions include/eve/function/simd/logical_not.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//==================================================================================================
/**
EVE - Expressive Vector Engine
Copyright 2019 Jean-Thierry Lapreste
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
**/
//==================================================================================================
#ifndef EVE_FUNCTION_SIMD_LOGICAL_NOT_HPP_INCLUDED
#define EVE_FUNCTION_SIMD_LOGICAL_NOT_HPP_INCLUDED

#include <eve/function/scalar/logical_not.hpp>
#include <eve/module/core/function/simd/logical_not.hpp>

#endif
33 changes: 33 additions & 0 deletions include/eve/module/core/function/scalar/logical_not.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//==================================================================================================
/**
EVE - Expressive Vector Engine
Copyright 2019 Jean-Thierry Lapreste
Copyright 2019 Joel FALCOU
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
**/
//==================================================================================================
#ifndef EVE_MODULE_CORE_FUNCTION_SCALAR_LOGICAL_NOT_HPP_INCLUDED
#define EVE_MODULE_CORE_FUNCTION_SCALAR_LOGICAL_NOT_HPP_INCLUDED

#include <eve/detail/overload.hpp>
#include <eve/detail/meta.hpp>
#include <eve/detail/abi.hpp>
#include <eve/as_logical.hpp>
#include <eve/function/scalar/bitwise_cast.hpp>
#include <type_traits>

namespace eve::detail
{
// -----------------------------------------------------------------------------------------------
// Regular case
template<typename T>
EVE_FORCEINLINE constexpr as_logical_t<T> logical_not_(EVE_SUPPORTS(cpu_)
, T const &a) noexcept
{
return !a;
}
}

#endif
80 changes: 80 additions & 0 deletions include/eve/module/core/function/simd/common/logical_not.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//==================================================================================================
/**
EVE - Expressive Vector Engine
Copyright 2019 Jean-Thierry Lapreste
Copyright 2019 Joel FALCOU
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
**/
//==================================================================================================
#ifndef EVE_MODULE_CORE_FUNCTION_SIMD_COMMON_LOGICAL_NOT_HPP_INCLUDED
#define EVE_MODULE_CORE_FUNCTION_SIMD_COMMON_LOGICAL_NOT_HPP_INCLUDED

#include <eve/detail/overload.hpp>
#include <eve/detail/skeleton.hpp>
#include <eve/detail/meta.hpp>
#include <eve/detail/abi.hpp>
#include <eve/logical.hpp>
#include <eve/function/bitwise_cast.hpp>
#include <eve/function/is_equal.hpp>
#include <eve/function/bitwise_xor.hpp>
#include <eve/constant/zero.hpp>
#include <eve/forward.hpp>
#include <type_traits>

namespace eve::detail
{
// -----------------------------------------------------------------------------------------------
// Basic
template<typename T, typename N, typename ABI>
EVE_FORCEINLINE auto logical_not_(EVE_SUPPORTS(simd_),
wide<T, N, ABI> const &v) noexcept
{
using t_t = wide<T, N, ABI>;
return eve::is_equal(v, eve::Zero<t_t>());
}

// -----------------------------------------------------------------------------------------------
// logical
template<typename T, typename N, typename ABI>
EVE_FORCEINLINE auto logical_not_(EVE_SUPPORTS(simd_),
wide<logical<T>, N, ABI> const &v) noexcept
{
using l_t = wide<eve::logical<T>, N, ABI>;
using t_t = wide<T, N, ABI>;
return eve::bitwise_cast<l_t>(eve::bitwise_not(eve::bitwise_cast<t_t>(v)));
}

// -----------------------------------------------------------------------------------------------
// Aggregation
template<typename T, typename N>
EVE_FORCEINLINE auto logical_not_(EVE_SUPPORTS(simd_),
wide<T, N, aggregated_> const &v) noexcept
{
return aggregate(eve::logical_not, v);
}

// -----------------------------------------------------------------------------------------------
// Emulation with auto-splat inside map for performance purpose
template<typename T, typename N>
EVE_FORCEINLINE auto logical_not_(EVE_SUPPORTS(simd_)
, wide<T, N, emulated_> const &v0) noexcept
{
return map(eve::logical_not, v0);
}

}

// -------------------------------------------------------------------------------------------------
// Infix operator support
namespace eve
{
template<typename T, typename N, typename ABI>
EVE_FORCEINLINE auto operator!(wide<T, N, ABI> const &v) noexcept
{
return eve::logical_not(v);
}
}

#endif
17 changes: 17 additions & 0 deletions include/eve/module/core/function/simd/logical_not.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//==================================================================================================
/**
EVE - Expressive Vector Engine
Copyright 2019 Jean-Thierry Lapreste
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
**/
//==================================================================================================
#ifndef EVE_MODULE_CORE_FUNCTION_SIMD_LOGICAL_NOT_HPP_INCLUDED
#define EVE_MODULE_CORE_FUNCTION_SIMD_LOGICAL_NOT_HPP_INCLUDED

#include <eve/arch.hpp>
#include <eve/module/core/function/simd/common/logical_not.hpp>

#endif

2 changes: 2 additions & 0 deletions test/unit/module/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ add_unit_test( "core" scalar/unary_plus.cpp )
add_unit_test( "core" scalar/unary_minus.cpp )
add_unit_test( "core" scalar/is_equal.cpp )
add_unit_test( "core" scalar/extract.cpp )
add_unit_test( "core" scalar/logical_not.cpp )

list_tests("scalar/sub" "core" ${all_types})
list_tests("scalar/add" "core" ${all_types})
Expand Down Expand Up @@ -50,3 +51,4 @@ list_tests("simd/unary_plus" "core" ${all_types})
list_tests("simd/unary_minus" "core" ${all_types})
list_tests("simd/is_equal" "core" ${all_types})
list_tests("simd/extract" "core" ${all_types})
list_tests("simd/logical_not" "core" ${all_types})
71 changes: 71 additions & 0 deletions test/unit/module/core/scalar/logical_not.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//==================================================================================================
/**
EVE - Expressive Vector Engine
Copyright 2019 Jean-Thierry Lapreste
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
**/
//==================================================================================================

#include <eve/function/scalar/logical_not.hpp>
#include <eve/logical.hpp>
#include <eve/constant/true.hpp>
#include <eve/constant/false.hpp>
#include <tts/tts.hpp>
#include <tts/tests/relation.hpp>
#include <tts/tests/types.hpp>
#include <cstddef>

TTS_CASE("Check logical_not return type")
{
using eve::logical;
using eve::True;
using eve::False;

TTS_EXPR_IS(eve::logical_not(0.f), logical<float>);
TTS_EXPR_IS(eve::logical_not(0.), logical<double>);

TTS_EXPR_IS(eve::logical_not(std::int8_t()), logical<std::int8_t>);
TTS_EXPR_IS(eve::logical_not(std::int16_t()), logical<std::int16_t>);
TTS_EXPR_IS(eve::logical_not(std::int32_t()), logical<std::int32_t>);
TTS_EXPR_IS(eve::logical_not(std::int64_t()), logical<std::int64_t>);

TTS_EXPR_IS(eve::logical_not(std::uint8_t()), logical<std::uint8_t>);
TTS_EXPR_IS(eve::logical_not(std::uint16_t()), logical<std::uint16_t>);
TTS_EXPR_IS(eve::logical_not(std::uint32_t()), logical<std::uint32_t>);
TTS_EXPR_IS(eve::logical_not(std::uint64_t()), logical<std::uint64_t>);
}

TTS_CASE("Check logical_not behavior")
{
using eve::logical;
using eve::True;
using eve::False;

TTS_EQUAL(eve::logical_not(std::uint8_t(0)), True<logical<std::uint8_t>>());
TTS_EQUAL(eve::logical_not(std::uint16_t(0)), True<logical<std::uint16_t>>());
TTS_EQUAL(eve::logical_not(std::uint32_t(0)), True<logical<std::uint32_t>>());
TTS_EQUAL(eve::logical_not(std::uint64_t(0)), True<logical<std::uint64_t>>());
TTS_EQUAL(eve::logical_not(std::int8_t(0)), True<logical<std::int8_t>>());
TTS_EQUAL(eve::logical_not(std::int16_t(0)), True<logical<std::int16_t>>());
TTS_EQUAL(eve::logical_not(std::int32_t(0)), True<logical<std::int32_t>>());
TTS_EQUAL(eve::logical_not(std::int64_t(0)), True<logical<std::int64_t>>());
TTS_EQUAL(eve::logical_not(double(0)), True<logical<double>>());
TTS_EQUAL(eve::logical_not(float(0)), True<logical<float>>());
TTS_EQUAL(eve::logical_not(-double(0)), True<logical<double>>());
TTS_EQUAL(eve::logical_not(-float(0)), True<logical<float>>());

TTS_EQUAL(eve::logical_not(std::uint8_t(1)), False<logical<std::uint8_t>>());
TTS_EQUAL(eve::logical_not(std::uint16_t(1)), False<logical<std::uint16_t>>());
TTS_EQUAL(eve::logical_not(std::uint32_t(1)), False<logical<std::uint32_t>>());
TTS_EQUAL(eve::logical_not(std::uint64_t(1)), False<logical<std::uint64_t>>());
TTS_EQUAL(eve::logical_not(std::int8_t(1)), False<logical<std::int8_t>>());
TTS_EQUAL(eve::logical_not(std::int16_t(1)), False<logical<std::int16_t>>());
TTS_EQUAL(eve::logical_not(std::int32_t(1)), False<logical<std::int32_t>>());
TTS_EQUAL(eve::logical_not(std::int64_t(1)), False<logical<std::int64_t>>());
TTS_EQUAL(eve::logical_not(double(1)), False<logical<double>>());
TTS_EQUAL(eve::logical_not(float(1)), False<logical<float>>());


}
12 changes: 12 additions & 0 deletions test/unit/module/core/simd/logical_not/double.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//==================================================================================================
/**
EVE - Expressive Vector Engine
Copyright 2019 Jean-Thierry Lapreste
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
**/
//==================================================================================================

using Type = double;
#include "logical_not.hpp"
12 changes: 12 additions & 0 deletions test/unit/module/core/simd/logical_not/float.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//==================================================================================================
/**
EVE - Expressive Vector Engine
Copyright 2019 Jean-Thierry Lapreste
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
**/
//==================================================================================================

using Type = float;
#include "logical_not.hpp"
13 changes: 13 additions & 0 deletions test/unit/module/core/simd/logical_not/int16.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//==================================================================================================
/**
EVE - Expressive Vector Engine
Copyright 2019 Jean-Thierry Lapreste
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
**/
//==================================================================================================

#include <cstdint>
using Type = std::int16_t;
#include "logical_not.hpp"
13 changes: 13 additions & 0 deletions test/unit/module/core/simd/logical_not/int32.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//==================================================================================================
/**
EVE - Expressive Vector Engine
Copyright 2019 Jean-Thierry Lapreste
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
**/
//==================================================================================================

#include <cstdint>
using Type = std::int32_t;
#include "logical_not.hpp"
13 changes: 13 additions & 0 deletions test/unit/module/core/simd/logical_not/int64.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//==================================================================================================
/**
EVE - Expressive Vector Engine
Copyright 2019 Jean-Thierry Lapreste
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
**/
//==================================================================================================

#include <cstdint>
using Type = std::int64_t;
#include "logical_not.hpp"
13 changes: 13 additions & 0 deletions test/unit/module/core/simd/logical_not/int8.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//==================================================================================================
/**
EVE - Expressive Vector Engine
Copyright 2019 Jean-Thierry Lapreste
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
**/
//==================================================================================================

#include <cstdint>
using Type = std::int8_t;
#include "logical_not.hpp"
43 changes: 43 additions & 0 deletions test/unit/module/core/simd/logical_not/logical_not.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//==================================================================================================
/**
EVE - Expressive Vector Engine
Copyright 2019 Jean-Thierry Lapreste
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
**/
//==================================================================================================
#ifndef LOGICAL_NOT_HPP
#define LOGICAL_NOT_HPP

#include "test.hpp"
#include <tts/tests/relation.hpp>
#include <eve/logical.hpp>
#include <eve/function/simd/logical_not.hpp>
#include <eve/wide.hpp>

using eve::fixed;

TTS_CASE_TPL("Check logical_not behavior on wide",
fixed<1>,
fixed<2>,
fixed<4>,
fixed<8>,
fixed<16>,
fixed<32>,
fixed<64>)
{
using eve::wide;

TTS_SETUP("A correctly initialized wide")
{
wide<Type, T> lhs([](int i, int) { return i%2; });

wide < eve::logical < Type >, T> ref([](int i, int) { return eve::logical_not(Type(i%2)); });

TTS_SECTION("supports eve::logical_not") { TTS_EQUAL(ref, eve::logical_not(lhs)); }
TTS_SECTION("supports operator!") { TTS_EQUAL(ref, !lhs); }
}
}

#endif
13 changes: 13 additions & 0 deletions test/unit/module/core/simd/logical_not/uint16.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//==================================================================================================
/**
EVE - Expressive Vector Engine
Copyright 2019 Jean-Thierry Lapreste
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
**/
//==================================================================================================

#include <cstdint>
using Type = std::uint16_t;
#include "logical_not.hpp"
13 changes: 13 additions & 0 deletions test/unit/module/core/simd/logical_not/uint32.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//==================================================================================================
/**
EVE - Expressive Vector Engine
Copyright 2019 Jean-Thierry Lapreste
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
**/
//==================================================================================================

#include <cstdint>
using Type = std::uint32_t;
#include "logical_not.hpp"

0 comments on commit d4365d0

Please sign in to comment.