VCTR
Loading...
Searching...
No Matches
Sqrt.h
1/*
2 ==============================================================================
3 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
5 Copyright 2022- by sonible GmbH.
6
7 This file is part of VCTR - Versatile Container Templates Reconceptualized.
8
9 VCTR is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License version 3
11 only, as published by the Free Software Foundation.
12
13 VCTR is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License version 3 for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 version 3 along with VCTR. If not, see <https://www.gnu.org/licenses/>.
20 ==============================================================================
21*/
22
23namespace vctr::expressions
24{
25
26template <size_t extent, class SrcType>
27requires is::realFloatNumber<ValueType<SrcType>> || is::complexFloatNumber<ValueType<SrcType>>
29{
30public:
31 using value_type = ValueType<SrcType>;
32
33 VCTR_COMMON_UNARY_EXPRESSION_MEMBERS (Sqrt, src)
34
35 VCTR_FORCEDINLINE constexpr value_type operator[] (size_t i) const
36 {
37 VCTR_ASSERT (inputValueValid (src[i]));
38 #if VCTR_USE_GCEM
40 {
41 if (std::is_constant_evaluated())
42 return gcem::sqrt (src[i]);
43 }
44 #endif
45
46 return std::sqrt (src[i]);
47 }
48
49 //==============================================================================
50 // Platform Vector Operation Implementation
51 VCTR_FORCEDINLINE const value_type* evalNextVectorOpInExpressionChain (value_type* dst) const
53 {
54 const auto* s = src.evalNextVectorOpInExpressionChain (dst);
55 VCTR_ASSERT (std::all_of (s, s + size(), inputValueValid));
56
57 Expression::Accelerate::sqrt (s, dst, sizeToInt (size()));
58 return dst;
59 }
60
61 VCTR_FORCEDINLINE const value_type* evalNextVectorOpInExpressionChain (value_type* dst) const
63 {
64 const auto* s = src.evalNextVectorOpInExpressionChain (dst);
65 VCTR_ASSERT (std::all_of (s, s + size(), inputValueValid));
66
67 Expression::IPP::sqrt (s, dst, sizeToInt (size()));
68 return dst;
69 }
70
71 //==============================================================================
72 VCTR_FORWARD_PREPARE_SIMD_EVALUATION_UNARY_EXPRESSION_MEMBER_FUNCTIONS
73
74 // AVX Implementation
75 VCTR_FORCEDINLINE VCTR_TARGET ("fma") AVXRegister<value_type> getAVX (size_t i) const
76 requires archX64 && has::getAVX<SrcType> && Expression::CommonElement::isRealFloat
77 {
78 return Expression::AVX::sqrt (src.getAVX (i));
79 }
80
81 // SSE Implementation
82 VCTR_FORCEDINLINE VCTR_TARGET ("sse4.1") SSERegister<value_type> getSSE (size_t i) const
83 requires archX64 && has::getSSE<SrcType> && Expression::CommonElement::isRealFloat
84 {
85 return Expression::SSE::sqrt (src.getSSE (i));
86 }
87
88 // NEON Implementation
89 NeonRegister<value_type> getNeon (size_t i) const
90 requires archARM && has::getNeon<SrcType> && Expression::CommonElement::isRealFloat
91 {
92 return Expression::Neon::sqrt (src.getNeon (i));
93 }
94
95private:
97 static constexpr bool inputValueValid (value_type in)
98 {
99 if constexpr (is::realNumber<value_type>)
100 return in >= value_type (0);
101
102 return true;
103 }
104};
105
106} // namespace vctr::expressions
107
108namespace vctr
109{
110
116
117} // namespace vctr
Definition: Sqrt.h:29
VCTR_FORWARD_PREPARE_SIMD_EVALUATION_UNARY_EXPRESSION_MEMBER_FUNCTIONS VCTR_FORCEDINLINE VCTR_TARGET("fma") AVXRegister< value_type > getAVX(size_t i) const &&has
If the value type is real, this checks if the value is greater or equal zero.
Definition: Sqrt.h:75
Constrains a type to have a member function getNeon (size_t) const.
Definition: ContainerAndExpressionConcepts.h:90
Constrains a type to represent a real valued floating point number.
Definition: NumericTypeConcepts.h:87
A combined concept to check if Apple Accelerate is a suitable option for a real valued floating point...
Definition: ContainerAndExpressionConcepts.h:309
A combined concept to check if Intel IPP is a suitable option for a real or complex valued floating p...
Definition: ContainerAndExpressionConcepts.h:349
constexpr ExpressionChainBuilder< expressions::Sqrt > sqrt
Computes the square root of the source values.
Definition: Sqrt.h:115
The main namespace of the VCTR project.
Definition: Array.h:24
typename detail::ValueType< std::remove_cvref_t< T > >::Type ValueType
If T is an expression template, it equals its return type, if it's a type that defines value_type as ...
Definition: Traits.h:201
int sizeToInt(size_t size)
Casts the size_t argument to an int.
Definition: PlatformVectorOpsHelpers.h:27
Definition: AVXRegister.h:28
An expression chain builder is an object which supplies various operator<< overloads which build chai...
Definition: ExpressionChainBuilder.h:170
The base class to every expression template.
Definition: ExpressionTemplate.h:37
Definition: NeonRegister.h:28
Definition: SSERegister.h:28