VCTR
Loading...
Searching...
No Matches
Square.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>
28{
29public:
30 using value_type = ValueType<SrcType>;
31
32 VCTR_COMMON_UNARY_EXPRESSION_MEMBERS (Square, src)
33
34 VCTR_FORCEDINLINE constexpr value_type operator[] (size_t i) const
35 {
36 const auto s = src[i];
37 return s * s;
38 }
39
40 //==============================================================================
41 // Platform Vector Operation Implementation
42 VCTR_FORCEDINLINE const value_type* evalNextVectorOpInExpressionChain (value_type* dst) const
44 {
45 const auto* s = src.evalNextVectorOpInExpressionChain (dst);
46 Expression::Accelerate::mul (s, s, dst, size());
47 return dst;
48 }
49
50 VCTR_FORCEDINLINE const value_type* evalNextVectorOpInExpressionChain (value_type* dst) const
52 {
53 Expression::Accelerate::square (src.evalNextVectorOpInExpressionChain (dst), dst, size());
54 return dst;
55 }
56
57 VCTR_FORCEDINLINE void evalVectorOpMultiplyAccumulate (value_type* dst) const
59 {
60 Expression::Accelerate::multiplyAdd (src.data(), src.data(), dst, dst, size());
61 }
62
63 VCTR_FORCEDINLINE const value_type* evalNextVectorOpInExpressionChain (value_type* dst) const
65 {
66 const auto* s = src.evalNextVectorOpInExpressionChain (dst);
67 Expression::IPP::mul (s, s, dst, sizeToInt (size()));
68 return dst;
69 }
70
71 VCTR_FORCEDINLINE void evalVectorOpMultiplyAccumulate (value_type* dst) const
73 {
74 Expression::IPP::multiplyAccumulate (src.data(), src.data(), dst, sizeToInt (size()));
75 }
76
77 //==============================================================================
78 VCTR_FORWARD_PREPARE_SIMD_EVALUATION_UNARY_EXPRESSION_MEMBER_FUNCTIONS
79
80 // AVX Implementation
81 VCTR_FORCEDINLINE VCTR_TARGET ("fma") AVXRegister<value_type> getAVX (size_t i) const
82 requires archX64 && has::getAVX<SrcType> && Expression::CommonElement::isRealFloat
83 {
84 auto x = src.getAVX (i);
85 return Expression::AVX::mul (x, x);
86 }
87
88 // SSE Implementation
89 VCTR_FORCEDINLINE VCTR_TARGET ("sse4.1") SSERegister<value_type> getSSE (size_t i) const
90 requires archX64 && has::getSSE<SrcType> && Expression::CommonElement::isRealFloat
91 {
92 auto x = src.getSSE (i);
93 return Expression::SSE::mul (x, x);
94 }
95
96 //==============================================================================
97 // NEON Implementation
98 NeonRegister<value_type> getNeon (size_t i) const
99 requires archARM && has::getNeon<SrcType> && Expression::CommonElement::isRealFloat
100 {
101 auto x = src.getNeon (i);
102 return Expression::Neon::mul (x, x);
103 }
104};
105
106} // namespace vctr::expressions
107
108namespace vctr
109{
110
116
117} // namespace vctr
Definition: Square.h:28
Constrains a type to have a member function getAVX (size_t) const.
Definition: ContainerAndExpressionConcepts.h:92
Constrains a type to have a member function getNeon (size_t) const.
Definition: ContainerAndExpressionConcepts.h:84
Constrains a type to have a member function getSSE (size_t) const.
Definition: ContainerAndExpressionConcepts.h:100
Constrains a type to be any derived instance of VctrBase.
Definition: ContainerAndExpressionConcepts.h:210
A combined concept to check if Apple Accelerate is a suitable option for a complex valued floating po...
Definition: ContainerAndExpressionConcepts.h:264
A combined concept to check if Apple Accelerate is a suitable option for a real valued floating point...
Definition: ContainerAndExpressionConcepts.h:260
A combined concept to check if Apple Accelerate is a suitable option for a real or complex valued flo...
Definition: ContainerAndExpressionConcepts.h:268
A combined concept to check if Intel IPP is a suitable option for a real or complex valued floating p...
Definition: ContainerAndExpressionConcepts.h:296
constexpr ExpressionChainBuilder< expressions::Square > square
Squares the source values.
Definition: Square.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:157
The base class to every expression template.
Definition: ExpressionTemplate.h:37
Definition: NeonRegister.h:28
Definition: SSERegister.h:28