-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/// | ||
/// Langulus::SIMD | ||
/// Copyright (c) 2019 Dimo Markov <[email protected]> | ||
/// Part of the Langulus framework, see https://langulus.com | ||
/// | ||
/// SPDX-License-Identifier: MIT | ||
/// | ||
#include "Common.hpp" | ||
|
||
|
||
template<class LHS, class RHS, class OUT> LANGULUS(INLINED) | ||
void ControlMax(const LHS& lhs, const RHS& rhs, OUT& out) noexcept { | ||
out = lhs > rhs ? lhs : rhs; | ||
} | ||
|
||
template<class LHS, class RHS, size_t C, class OUT> LANGULUS(INLINED) | ||
void ControlMax(const Vector<LHS, C>& lhsArray, const Vector<RHS, C>& rhsArray, Vector<OUT, C>& out) noexcept { | ||
auto r = out.mArray; | ||
auto lhs = lhsArray.mArray; | ||
auto rhs = rhsArray.mArray; | ||
const auto lhsEnd = lhs + C; | ||
while (lhs != lhsEnd) | ||
ControlMax(*lhs++, *rhs++, *r++); | ||
} | ||
|
||
TEMPLATE_TEST_CASE("Max", "[max]" | ||
, NUMBERS_ALL() | ||
, VECTORS_ALL(1) | ||
, VECTORS_ALL(2) | ||
, VECTORS_ALL(3) | ||
, VECTORS_ALL(4) | ||
, VECTORS_ALL(5) | ||
, VECTORS_ALL(8) | ||
, VECTORS_ALL(9) | ||
, VECTORS_ALL(16) | ||
, VECTORS_ALL(17) | ||
, VECTORS_ALL(32) | ||
, VECTORS_ALL(33) | ||
) { | ||
using T = TestType; | ||
|
||
GIVEN("max(x, y) = r") { | ||
T x, y; | ||
T r, rCheck; | ||
|
||
if constexpr (not CT::Vector<T>) { | ||
InitOne(x, 1); | ||
InitOne(y, -5); | ||
} | ||
|
||
WHEN("Max is applied") { | ||
ControlMax(x, y, rCheck); | ||
SIMD::Max(x, y, r); | ||
|
||
REQUIRE(r == rCheck); | ||
|
||
#ifdef LANGULUS_STD_BENCHMARK | ||
BENCHMARK_ADVANCED("Max (control)") (timer meter) { | ||
some<T> nx(meter.runs()); | ||
if constexpr (not CT::Vector<T>) { | ||
for (auto& i : nx) | ||
InitOne(i, 1); | ||
} | ||
|
||
some<T> ny(meter.runs()); | ||
if constexpr (not CT::Vector<T>) { | ||
for (auto& i : ny) | ||
InitOne(i, 1); | ||
} | ||
|
||
some<T> nr(meter.runs()); | ||
meter.measure([&](int i) { | ||
ControlMax(nx[i], ny[i], nr[i]); | ||
}); | ||
}; | ||
|
||
BENCHMARK_ADVANCED("Max (SIMD)") (timer meter) { | ||
some<T> nx(meter.runs()); | ||
if constexpr (not CT::Vector<T>) { | ||
for (auto& i : nx) | ||
InitOne(i, 1); | ||
} | ||
|
||
some<T> ny(meter.runs()); | ||
if constexpr (not CT::Vector<T>) { | ||
for (auto& i : ny) | ||
InitOne(i, 1); | ||
} | ||
|
||
some<T> nr(meter.runs()); | ||
meter.measure([&](int i) { | ||
SIMD::Max(nx[i], ny[i], nr[i]); | ||
}); | ||
}; | ||
#endif | ||
} | ||
|
||
WHEN("Max in reverse") { | ||
ControlMax(y, x, rCheck); | ||
SIMD::Max(y, x, r); | ||
|
||
REQUIRE(r == rCheck); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/// | ||
/// Langulus::SIMD | ||
/// Copyright (c) 2019 Dimo Markov <[email protected]> | ||
/// Part of the Langulus framework, see https://langulus.com | ||
/// | ||
/// SPDX-License-Identifier: MIT | ||
/// | ||
#include "Common.hpp" | ||
|
||
|
||
template<class LHS, class RHS, class OUT> LANGULUS(INLINED) | ||
void ControlMin(const LHS& lhs, const RHS& rhs, OUT& out) noexcept { | ||
out = lhs < rhs ? lhs : rhs; | ||
} | ||
|
||
template<class LHS, class RHS, size_t C, class OUT> LANGULUS(INLINED) | ||
void ControlMin(const Vector<LHS, C>& lhsArray, const Vector<RHS, C>& rhsArray, Vector<OUT, C>& out) noexcept { | ||
auto r = out.mArray; | ||
auto lhs = lhsArray.mArray; | ||
auto rhs = rhsArray.mArray; | ||
const auto lhsEnd = lhs + C; | ||
while (lhs != lhsEnd) | ||
ControlMin(*lhs++, *rhs++, *r++); | ||
} | ||
|
||
TEMPLATE_TEST_CASE("Min", "[min]" | ||
, NUMBERS_ALL() | ||
, VECTORS_ALL(1) | ||
, VECTORS_ALL(2) | ||
, VECTORS_ALL(3) | ||
, VECTORS_ALL(4) | ||
, VECTORS_ALL(5) | ||
, VECTORS_ALL(8) | ||
, VECTORS_ALL(9) | ||
, VECTORS_ALL(16) | ||
, VECTORS_ALL(17) | ||
, VECTORS_ALL(32) | ||
, VECTORS_ALL(33) | ||
) { | ||
using T = TestType; | ||
|
||
GIVEN("min(x, y) = r") { | ||
T x, y; | ||
T r, rCheck; | ||
|
||
if constexpr (not CT::Vector<T>) { | ||
InitOne(x, 1); | ||
InitOne(y, -5); | ||
} | ||
|
||
WHEN("Min is applied") { | ||
ControlMin(x, y, rCheck); | ||
SIMD::Min(x, y, r); | ||
|
||
REQUIRE(r == rCheck); | ||
|
||
#ifdef LANGULUS_STD_BENCHMARK | ||
BENCHMARK_ADVANCED("Min (control)") (timer meter) { | ||
some<T> nx(meter.runs()); | ||
if constexpr (not CT::Vector<T>) { | ||
for (auto& i : nx) | ||
InitOne(i, 1); | ||
} | ||
|
||
some<T> ny(meter.runs()); | ||
if constexpr (not CT::Vector<T>) { | ||
for (auto& i : ny) | ||
InitOne(i, 1); | ||
} | ||
|
||
some<T> nr(meter.runs()); | ||
meter.measure([&](int i) { | ||
ControlMin(nx[i], ny[i], nr[i]); | ||
}); | ||
}; | ||
|
||
BENCHMARK_ADVANCED("Min (SIMD)") (timer meter) { | ||
some<T> nx(meter.runs()); | ||
if constexpr (not CT::Vector<T>) { | ||
for (auto& i : nx) | ||
InitOne(i, 1); | ||
} | ||
|
||
some<T> ny(meter.runs()); | ||
if constexpr (not CT::Vector<T>) { | ||
for (auto& i : ny) | ||
InitOne(i, 1); | ||
} | ||
|
||
some<T> nr(meter.runs()); | ||
meter.measure([&](int i) { | ||
SIMD::Min(nx[i], ny[i], nr[i]); | ||
}); | ||
}; | ||
#endif | ||
} | ||
|
||
WHEN("Min in reverse") { | ||
ControlMin(y, x, rCheck); | ||
SIMD::Min(y, x, r); | ||
|
||
REQUIRE(r == rCheck); | ||
} | ||
} | ||
} |