2016-02-04 10:36:36 -08:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
|
|
|
|
// for linear algebra.
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2016 Pedro Gonnet (pedro.gonnet@gmail.com)
|
|
|
|
|
//
|
|
|
|
|
// This Source Code Form is subject to the terms of the Mozilla
|
|
|
|
|
// Public License v. 2.0. If a copy of the MPL was not distributed
|
|
|
|
|
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
|
|
#ifndef THIRD_PARTY_EIGEN3_EIGEN_SRC_CORE_ARCH_AVX512_MATHFUNCTIONS_H_
|
|
|
|
|
#define THIRD_PARTY_EIGEN3_EIGEN_SRC_CORE_ARCH_AVX512_MATHFUNCTIONS_H_
|
|
|
|
|
|
2023-08-21 16:25:22 +00:00
|
|
|
// IWYU pragma: private
|
2021-09-10 19:12:26 +00:00
|
|
|
#include "../../InternalHeaderCheck.h"
|
|
|
|
|
|
2016-02-04 10:36:36 -08:00
|
|
|
namespace Eigen {
|
|
|
|
|
|
|
|
|
|
namespace internal {
|
2023-03-10 22:02:23 +00:00
|
|
|
EIGEN_INSTANTIATE_GENERIC_MATH_FUNCS_FLOAT(Packet16f)
|
|
|
|
|
EIGEN_INSTANTIATE_GENERIC_MATH_FUNCS_DOUBLE(Packet8d)
|
2019-11-15 17:09:46 -08:00
|
|
|
|
2021-01-20 19:00:09 -08:00
|
|
|
template <>
|
|
|
|
|
EIGEN_STRONG_INLINE Packet16h pfrexp(const Packet16h& a, Packet16h& exponent) {
|
|
|
|
|
Packet16f fexponent;
|
|
|
|
|
const Packet16h out = float2half(pfrexp<Packet16f>(half2float(a), fexponent));
|
|
|
|
|
exponent = float2half(fexponent);
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
|
EIGEN_STRONG_INLINE Packet16h pldexp(const Packet16h& a, const Packet16h& exponent) {
|
|
|
|
|
return float2half(pldexp<Packet16f>(half2float(a), half2float(exponent)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
|
EIGEN_STRONG_INLINE Packet16bf pfrexp(const Packet16bf& a, Packet16bf& exponent) {
|
|
|
|
|
Packet16f fexponent;
|
|
|
|
|
const Packet16bf out = F32ToBf16(pfrexp<Packet16f>(Bf16ToF32(a), fexponent));
|
|
|
|
|
exponent = F32ToBf16(fexponent);
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
|
EIGEN_STRONG_INLINE Packet16bf pldexp(const Packet16bf& a, const Packet16bf& exponent) {
|
|
|
|
|
return F32ToBf16(pldexp<Packet16f>(Bf16ToF32(a), Bf16ToF32(exponent)));
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-04 10:36:36 -08:00
|
|
|
#if EIGEN_FAST_MATH
|
|
|
|
|
template <>
|
2025-03-19 19:55:26 +00:00
|
|
|
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet16f psqrt<Packet16f>(const Packet16f& x) {
|
|
|
|
|
return generic_sqrt_newton_step<Packet16f>::run(x, _mm512_rsqrt14_ps(x));
|
2016-02-04 10:36:36 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <>
|
2025-03-19 19:55:26 +00:00
|
|
|
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet8d psqrt<Packet8d>(const Packet8d& x) {
|
2023-02-23 23:16:41 +00:00
|
|
|
#ifdef EIGEN_VECTORIZE_AVX512ER
|
2025-03-19 19:55:26 +00:00
|
|
|
return generic_sqrt_newton_step<Packet8d, /*Steps=*/1>::run(x, _mm512_rsqrt28_pd(x));
|
2023-02-23 23:16:41 +00:00
|
|
|
#else
|
2025-03-19 19:55:26 +00:00
|
|
|
return generic_sqrt_newton_step<Packet8d, /*Steps=*/2>::run(x, _mm512_rsqrt14_pd(x));
|
2023-02-23 23:16:41 +00:00
|
|
|
#endif
|
2016-02-04 10:36:36 -08:00
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
template <>
|
|
|
|
|
EIGEN_STRONG_INLINE Packet16f psqrt<Packet16f>(const Packet16f& x) {
|
|
|
|
|
return _mm512_sqrt_ps(x);
|
|
|
|
|
}
|
2020-06-20 19:16:24 +00:00
|
|
|
|
2016-02-04 10:36:36 -08:00
|
|
|
template <>
|
|
|
|
|
EIGEN_STRONG_INLINE Packet8d psqrt<Packet8d>(const Packet8d& x) {
|
|
|
|
|
return _mm512_sqrt_pd(x);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-11-15 17:09:46 -08:00
|
|
|
// prsqrt for float.
|
|
|
|
|
#if defined(EIGEN_VECTORIZE_AVX512ER)
|
|
|
|
|
template <>
|
|
|
|
|
EIGEN_STRONG_INLINE Packet16f prsqrt<Packet16f>(const Packet16f& x) {
|
|
|
|
|
return _mm512_rsqrt28_ps(x);
|
|
|
|
|
}
|
|
|
|
|
#elif EIGEN_FAST_MATH
|
|
|
|
|
|
2016-02-04 10:36:36 -08:00
|
|
|
template <>
|
2025-03-19 19:55:26 +00:00
|
|
|
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet16f prsqrt<Packet16f>(const Packet16f& x) {
|
|
|
|
|
return generic_rsqrt_newton_step<Packet16f, /*Steps=*/1>::run(x, _mm512_rsqrt14_ps(x));
|
2020-06-20 19:16:24 +00:00
|
|
|
}
|
2019-11-15 17:09:46 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// prsqrt for double.
|
|
|
|
|
#if EIGEN_FAST_MATH
|
2016-02-04 10:36:36 -08:00
|
|
|
template <>
|
2025-03-19 19:55:26 +00:00
|
|
|
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet8d prsqrt<Packet8d>(const Packet8d& x) {
|
2022-03-02 17:20:47 +00:00
|
|
|
#ifdef EIGEN_VECTORIZE_AVX512ER
|
2025-03-19 19:55:26 +00:00
|
|
|
return generic_rsqrt_newton_step<Packet8d, /*Steps=*/1>::run(x, _mm512_rsqrt28_pd(x));
|
2022-03-02 17:20:47 +00:00
|
|
|
#else
|
2025-03-19 19:55:26 +00:00
|
|
|
return generic_rsqrt_newton_step<Packet8d, /*Steps=*/2>::run(x, _mm512_rsqrt14_pd(x));
|
2022-03-02 17:20:47 +00:00
|
|
|
#endif
|
2016-02-04 10:36:36 -08:00
|
|
|
}
|
2022-01-21 23:49:18 +00:00
|
|
|
|
|
|
|
|
template <>
|
|
|
|
|
EIGEN_STRONG_INLINE Packet16f preciprocal<Packet16f>(const Packet16f& a) {
|
|
|
|
|
#ifdef EIGEN_VECTORIZE_AVX512ER
|
2022-03-02 17:20:47 +00:00
|
|
|
return _mm512_rcp28_ps(a);
|
2019-11-15 17:09:46 -08:00
|
|
|
#else
|
2022-01-21 23:49:18 +00:00
|
|
|
return generic_reciprocal_newton_step<Packet16f, /*Steps=*/1>::run(a, _mm512_rcp14_ps(a));
|
|
|
|
|
#endif
|
2016-02-04 10:36:36 -08:00
|
|
|
}
|
2023-02-23 23:16:41 +00:00
|
|
|
#endif
|
2022-01-21 23:49:18 +00:00
|
|
|
|
2026-02-22 20:17:43 -08:00
|
|
|
EIGEN_INSTANTIATE_GENERIC_MATH_FUNCS_BF16(Packet16f, Packet16bf)
|
2025-03-19 19:55:26 +00:00
|
|
|
|
|
|
|
|
#ifndef EIGEN_VECTORIZE_AVX512FP16
|
2026-02-22 20:17:43 -08:00
|
|
|
EIGEN_INSTANTIATE_GENERIC_MATH_FUNCS_F16(Packet16f, Packet16h)
|
2025-03-19 19:55:26 +00:00
|
|
|
#endif // EIGEN_VECTORIZE_AVX512FP16
|
2020-11-24 16:28:07 -08:00
|
|
|
|
2016-02-04 10:36:36 -08:00
|
|
|
} // end namespace internal
|
|
|
|
|
|
|
|
|
|
} // end namespace Eigen
|
|
|
|
|
|
|
|
|
|
#endif // THIRD_PARTY_EIGEN3_EIGEN_SRC_CORE_ARCH_AVX512_MATHFUNCTIONS_H_
|