Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 129 additions & 10 deletions VectorisationWrappers/Accelerate/AccelerateTrigonometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,72 @@

namespace Vectorised::Trigonometry
{
template <typename T>
static void hardClipVectorised(const T* InputBuffer, T* OutputBuffer, const int BufferSize, const T* ClipLowerLimit, const T* ClipUpperLimit)
{
if constexpr (std::is_same_v<T, float>)
vDSP_vclip(InputBuffer, 1, ClipLowerLimit, ClipUpperLimit, OutputBuffer, 1, BufferSize);
else if constexpr (std::is_same_v<T, double>)
vDSP_vclipD(InputBuffer, 1, ClipLowerLimit, ClipUpperLimit, OutputBuffer, 1, BufferSize);
else
static_assert (sizeof(T) == 0, "Unsupported type for hard clipping");
}

template <typename T>
static void inverseSinhVectorised (const T* WorkBuffer, T* OutputBuffer, const int BufferSize)
{
if constexpr (std::is_same_v<T, float>)
vvasinhf (OutputBuffer, WorkBuffer, &BufferSize);
else if constexpr (std::is_same_v<T, double>)
vvasinh (OutputBuffer, WorkBuffer, &BufferSize);
else
static_assert (sizeof(T) == 0, "Unsupported type for tanh");
}

template <typename T>
static void inverseCoshVectorised (const T* WorkBuffer, T* OutputBuffer, const int BufferSize)
{
if constexpr (std::is_same_v<T, float>)
vvacoshf (OutputBuffer, WorkBuffer, &BufferSize);
else if constexpr (std::is_same_v<T, double>)
vvacosh (OutputBuffer, WorkBuffer, &BufferSize);
else
static_assert (sizeof(T) == 0, "Unsupported type for tanh");
}

template <typename T>
static void inverseTanhVectorised (const T* WorkBuffer, T* OutputBuffer, const int BufferSize)
{
if constexpr (std::is_same_v<T, float>)
vvatanhf (OutputBuffer, WorkBuffer, &BufferSize);
else if constexpr (std::is_same_v<T, double>)
vvatanh (OutputBuffer, WorkBuffer, &BufferSize);
else
static_assert (sizeof(T) == 0, "Unsupported type for tanh");
}

template <typename T>
static void sinhVectorised (const T* WorkBuffer, T* OutputBuffer, const int BufferSize)
{
if constexpr (std::is_same_v<T, float>)
vvsinhf (OutputBuffer, WorkBuffer, &BufferSize);
else if constexpr (std::is_same_v<T, double>)
vvsinh (OutputBuffer, WorkBuffer, &BufferSize);
else
static_assert (sizeof(T) == 0, "Unsupported type for tanh");
}

template <typename T>
static void coshVectorised (const T* WorkBuffer, T* OutputBuffer, const int BufferSize)
{
if constexpr (std::is_same_v<T, float>)
vvcoshf (OutputBuffer, WorkBuffer, &BufferSize);
else if constexpr (std::is_same_v<T, double>)
vvcosh (OutputBuffer, WorkBuffer, &BufferSize);
else
static_assert (sizeof(T) == 0, "Unsupported type for tanh");
}

template <typename T>
static void tanhVectorised (const T* WorkBuffer, T* OutputBuffer, const int BufferSize)
{
Expand All @@ -13,26 +79,79 @@ namespace Vectorised::Trigonometry
static_assert (sizeof(T) == 0, "Unsupported type for tanh");
}

// Vectorised tanh function for hard clipping
template <typename T>
static void hardClipVectorised(const T* InputBuffer, T* OutputBuffer, const int BufferSize, const T* ClipLowerLimit, const T* ClipUpperLimit)
static void sineVectorised (const T* InputBuffer, T* OutputBuffer,const int BufferSize)
{
if constexpr (std::is_same_v<T, float>)
vDSP_vclip(InputBuffer, 1, ClipLowerLimit, ClipUpperLimit, OutputBuffer, 1, BufferSize);
else if constexpr (std::is_same_v<T, double>)
vDSP_vclipD(InputBuffer, 1, ClipLowerLimit, ClipUpperLimit, OutputBuffer, 1, BufferSize);
vvsinf (OutputBuffer, InputBuffer, &BufferSize);
else if constexpr (std::is_same_v<T, double>)
vvsin (OutputBuffer, InputBuffer, &BufferSize);
else
static_assert (sizeof(T) == 0, "Unsupported type for hard clipping");
static_assert (sizeof(T) == 0, "Unsupported type for sine");
}

template <typename T>
static void cosVectorised (const T* InputBuffer, T* OutputBuffer, const int BufferSize)
{
if constexpr (std::is_same_v<T, float>)
vvcosf (OutputBuffer, InputBuffer, &BufferSize);
else if constexpr (std::is_same_v<T, double>)
vvcos (OutputBuffer, InputBuffer, &BufferSize);
else
static_assert (sizeof(T) == 0, "Unsupported type for sine");
}

template <typename T>
static void tanVectorised (const T* InputBuffer, T* OutputBuffer, const int BufferSize)
{
if constexpr (std::is_same_v<T, float>)
vvtanf (OutputBuffer, InputBuffer, &BufferSize);
else if constexpr (std::is_same_v<T, double>)
vvtan (OutputBuffer, InputBuffer, &BufferSize);
else
static_assert (sizeof(T) == 0, "Unsupported type for sine");
}

template <typename T>
static void arcSinVectorised (const T* InputBuffer, T* OutputBuffer, const int BufferSize)
{
if constexpr (std::is_same_v<T, float>)
vvasinf (OutputBuffer, InputBuffer, &BufferSize);
else if constexpr (std::is_same_v<T, double>)
vvasin (OutputBuffer, InputBuffer, &BufferSize);
else
static_assert (sizeof(T) == 0, "Unsupported type for sine");
}

template <typename T>
static void arcCosVectorised (const T* InputBuffer, T* OutputBuffer, const int BufferSize)
{
if constexpr (std::is_same_v<T, float>)
vvacosf (OutputBuffer, InputBuffer, &BufferSize);
else if constexpr (std::is_same_v<T, double>)
vvacos (OutputBuffer, InputBuffer, &BufferSize);
else
static_assert (sizeof(T) == 0, "Unsupported type for sine");
}

template <typename T>
static void arcTanVectorised (const T* InputBuffer, T* OutputBuffer, const int BufferSize)
{
if constexpr (std::is_same_v<T, float>)
vvatanf (OutputBuffer, InputBuffer, &BufferSize);
else if constexpr (std::is_same_v<T, double>)
vvatan (OutputBuffer, InputBuffer, &BufferSize);
else
static_assert (sizeof(T) == 0, "Unsupported type for sine");
}

// Vectorised tanh function for sine
template <typename T>
static void sineVectorised (T* InputBuffer, const int BufferSize)
static void arcTanXYVectorised (const T* XBuffer, const T* YBuffer, T* OutputBuffer, const int BufferSize)
{
if constexpr (std::is_same_v<T, float>)
vvsinf (InputBuffer, InputBuffer, &BufferSize);
vvatan2f (OutputBuffer, YBuffer, XBuffer, &BufferSize);
else if constexpr (std::is_same_v<T, double>)
vvsin (InputBuffer, InputBuffer, &BufferSize);
vvatan2 (OutputBuffer, YBuffer, XBuffer, &BufferSize);
else
static_assert (sizeof(T) == 0, "Unsupported type for sine");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,98 @@ TEMPLATE_TEST_CASE("Accelerate Trigonometry Unit Testing", "[Accelerate Trigonom
{
auto sinValue = static_cast<T> (std::sin (1.f));

Vectorised::Trigonometry::sineVectorised (workingBuffer.data(), bufferSize);
Vectorised::Trigonometry::sineVectorised (workingBuffer.data(), workingBuffer.data(), bufferSize);

for (const auto& value : workingBuffer)
{
REQUIRE (value == Catch::Approx (sinValue));
}
}

SECTION ("Cos Function Tests")
{
auto cosValue = static_cast<T> (std::cos (1.f));

Vectorised::Trigonometry::cosVectorised (workingBuffer.data(), workingBuffer.data(), bufferSize);

for (const auto& value : workingBuffer)
{
REQUIRE (value == Catch::Approx (cosValue));
}
}

SECTION ("Tan Function Tests")
{
auto tanValue = static_cast<T> (std::tan (1.f));

Vectorised::Trigonometry::tanVectorised (workingBuffer.data(), workingBuffer.data(), bufferSize);

for (const auto& value : workingBuffer)
{
REQUIRE (value == Catch::Approx (tanValue));
}
}

SECTION ("Arcsin Function Tests")
{
auto asinValue = static_cast<T> (std::asin (1.f));

Vectorised::Trigonometry::arcSinVectorised (workingBuffer.data(), workingBuffer.data(), bufferSize);

for (const auto& value : workingBuffer)
{
REQUIRE (value == Catch::Approx (asinValue));
}
}

SECTION ("Arccos Function Tests")
{
auto aCosValue = static_cast<T> (std::acos (1.f));

Vectorised::Trigonometry::arcCosVectorised (workingBuffer.data(), workingBuffer.data(), bufferSize);

for (const auto& value : workingBuffer)
{
REQUIRE (value == Catch::Approx (aCosValue));
}
}

SECTION ("ArcTan Function Tests")
{
auto aTanValue = static_cast<T> (std::atan (1.f));

Vectorised::Trigonometry::arcTanVectorised (workingBuffer.data(), workingBuffer.data(), bufferSize);

for (const auto& value : workingBuffer)
{
REQUIRE (value == Catch::Approx (aTanValue));
}
}

SECTION ("Sinh Function Tests")
{
const auto sinhValue = static_cast<T> (std::sinh (1.f));

Vectorised::Trigonometry::sinhVectorised (workingBuffer.data(), workingBuffer.data(), bufferSize);

for (const auto& value : workingBuffer)
{
REQUIRE (value == Catch::Approx (sinhValue));
}
}

SECTION ("Cosh Function Tests")
{
const auto coshValue = static_cast<T> (std::cosh (1.f));

Vectorised::Trigonometry::coshVectorised (workingBuffer.data(), workingBuffer.data(), bufferSize);

for (const auto& value : workingBuffer)
{
REQUIRE (value == Catch::Approx (coshValue));
}
}

SECTION ("Tanh Function Tests")
{
workingBuffer.assign (bufferSize, static_cast<T> (10));
Expand All @@ -38,7 +122,46 @@ TEMPLATE_TEST_CASE("Accelerate Trigonometry Unit Testing", "[Accelerate Trigonom
}
}

SECTION ("Sigmud Function Tests")
SECTION ("Inverse Hyperbolic Cosine Function Tests")
{
workingBuffer.assign (bufferSize, static_cast<T> (2));
const auto compareValue = static_cast<T> (std::asinh (2));

Vectorised::Trigonometry::inverseSinhVectorised (workingBuffer.data(), workingBuffer.data(), bufferSize);

for (const auto& value : workingBuffer)
{
REQUIRE (value == Catch::Approx (compareValue));
}
}

SECTION ("Inverse Hyperbolic Cosine Function Tests")
{
workingBuffer.assign (bufferSize, static_cast<T> (2));
const auto compareValue = static_cast<T> (std::acosh (2));

Vectorised::Trigonometry::inverseCoshVectorised (workingBuffer.data(), workingBuffer.data(), bufferSize);

for (const auto& value : workingBuffer)
{
REQUIRE (value == Catch::Approx (compareValue));
}
}

SECTION ("Inverse Hyperbolic Tangent Function Tests")
{
workingBuffer.assign (bufferSize, static_cast<T> (0.8));
const auto compareValue = static_cast<T> (std::atanh (0.8));

Vectorised::Trigonometry::inverseTanhVectorised (workingBuffer.data(), workingBuffer.data(), bufferSize);

for (const auto& value : workingBuffer)
{
REQUIRE (value == Catch::Approx (compareValue));
}
}

SECTION ("Sigmoid Function Tests")
{
const auto minValue = static_cast<T>(-1);
const auto maxValue = static_cast<T>(1);
Expand All @@ -59,4 +182,16 @@ TEMPLATE_TEST_CASE("Accelerate Trigonometry Unit Testing", "[Accelerate Trigonom
REQUIRE (value == Catch::Approx (maxValue));
}
}

SECTION ("Arc tangent of X Y Function Tests")
{
auto normalValue = static_cast<T> (std::atan2 (1.f, 1.f));

Vectorised::Trigonometry::arcTanXYVectorised (workingBuffer.data(), workingBuffer.data(), workingBuffer.data(), bufferSize);

for (const auto& value : workingBuffer)
{
REQUIRE (value == Catch::Approx (normalValue));
}
}
}