From 7505783cc76bb45b059413c6eb0cd0e98131d6de Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 14 Mar 2021 19:45:41 -0700 Subject: [PATCH] ircd::math: Add fallback for vectorized hyperbolic tangent. --- include/ircd/math/math.h | 7 +++++++ include/ircd/math/tanh.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 include/ircd/math/tanh.h diff --git a/include/ircd/math/math.h b/include/ircd/math/math.h index 88a423e5b..76bcacda3 100644 --- a/include/ircd/math/math.h +++ b/include/ircd/math/math.h @@ -14,3 +14,10 @@ #include "log2.h" #include "inv.h" #include "mean.h" +#include "tanh.h" + +namespace ircd +{ + using math::mean; + using math::tanh; +} diff --git a/include/ircd/math/tanh.h b/include/ircd/math/tanh.h new file mode 100644 index 000000000..ed921e22c --- /dev/null +++ b/include/ircd/math/tanh.h @@ -0,0 +1,29 @@ +// Matrix Construct +// +// Copyright (C) Matrix Construct Developers, Authors & Contributors +// Copyright (C) 2016-2021 Jason Volk +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice is present in all copies. The +// full license for this software is available in the LICENSE file. + +#pragma once +#define HAVE_IRCD_MATH_TANH_H + +namespace ircd::math +{ + template + typename std::enable_if(), T>::type + tanh(T); +} + +template +inline typename std::enable_if(), T>::type +ircd::math::tanh(T a) +{ + for(uint i(0); i < simd::lanes(); ++i) + a[i] = std::tanh(a[i]); + + return a; +}