1nova simd
2
3nova simd provides a framework of simdfied vector functions, designed
4mainly for computer music applications.
5it currently supports the following instruction sets:
6- sse/sse2 family
7- ppc/altivec
8- avx
9- arm/neon
10
11
12vec class:
13the simd functionality is built around a templated vec class. it usually maps
14to a simd vector. the vec class can be used to compose more specific algorithms,
15hiding different implementations under a common API.
16
17template <typename FloatType>
18class vec
19{
20public:
21 typedef FloatType float_type;
22
23 static const int size; // number of samples per vector
24 static const int objects_per_cacheline; // typical number of objects per cacheline
25
26 /* constructors */
27 vec(void);
28 vec(double f);
29 vec(float f);
30 vec(vec const & rhs);
31
32 /* element access */
33 FloatType get (int index) const;
34
35 /* set vector */
36 void set (int index, FloatType arg);
37 void set_vec (FloatType value);
38 FloatType set_slope(FloatType start, FloatType slope);
39 FloatType set_exp(FloatType start, FloatType curve);
40
41 /* load and store */
42 void load(const WrappedType * src);
43 void load_first(const WrappedType * src);
44 void load_aligned(const WrappedType * data);
45
46 void store(WrappedType * dest) const;
47 void store_aligned(WrappedType * dest) const;
48 void store_aligned_stream(WrappedType * dest) const;
49
50 void clear(void);
51
52 vec_base operator+(vec_base const & rhs) const
53 vec_base operator-(vec_base const & rhs) const
54 vec_base operator*(vec_base const & rhs) const
55 vec_base operator/(vec_base const & rhs) const
56
57 vec_base & operator+=(vec_base const & rhs)
58 vec_base & operator-=(vec_base const & rhs)
59 vec_base & operator*=(vec_base const & rhs)
60 vec_base & operator/=(vec_base const & rhs)
61
62 vec_base operator<(vec_base const & rhs) const
63 vec_base operator<=(vec_base const & rhs) const
64 vec_base operator==(vec_base const & rhs) const
65 vec_base operator!=(vec_base const & rhs) const
66 vec_base operator>(vec_base const & rhs) const
67 vec_base operator>=(vec_base const & rhs) const
68
69 friend vec madd(vec const & arg1, vec const & arg2, vec const & arg3);
70
71 friend vec sin(vec const & arg);
72 friend vec cos(vec const & arg);
73 friend vec tan(vec const & arg);
74 friend vec asin(vec const & arg);
75 friend vec acos(vec const & arg);
76 friend vec atan(vec const & arg);
77
78 friend vec tanh(vec const & arg);
79
80 friend vec log(vec const & arg);
81 friend vec log2(vec const & arg);
82 friend vec log10(vec const & arg);
83 friend vec exp(vec const & arg);
84 friend vec pow(vec const & lhs, vec const & rhs);
85
86 friend vec abs(vec const & arg);
87 friend vec sign(vec const & arg);
88 friend vec square(vec const & arg);
89 friend vec cube(vec const & arg);
90
91 friend vec signed_sqrt(vec const & arg);
92 friend vec signed_pow(vec const & lhs, vec const & rhs);
93
94 friend vec min_(vec const & lhs, vec const & rhs);
95 friend vec max_(vec const & lhs, vec const & rhs);
96
97 friend vec round(vec const & arg);
98 friend vec ceil(vec const & arg);
99 friend vec floor(vec const & arg);
100 friend vec frac(vec const & arg);
101 friend vec trunc(vec const & arg);
102};
103
104
105vector functions:
106
107this vec class has been used as building block for a number of vector functions,
108which provides a traditional c++-style interface to perform a specific operation
109on buffers.
110(for details consult the simd_*.hpp files)
111
112for an unary operation `foo', the following functions must be:
113
114/* arbitrary number of iterations */
115template <typename float_type>
116inline void foo_vec(float_type * out, const float_type * in, unsigned int n);
117
118/* number of iterations must be a multiple of
119 * unroll_constraints<float_type>::samples_per_loop
120 */
121template <typename float_type>
122inline void foo_vec_simd(float_type * out, const float_type * in, unsigned int n);
123
124/* number of iterations must be a multiple of
125 * unroll_constraints<float_type>::samples_per_loop
126 */
127template <int n,
128 typename FloatType
129 >
130inline void foo_vec_simd(FloatType * out, const FloatType * in);
131
132
133for binary and ternary operations, instances are provided for mixed
134vector and scalar arguments. using the suffix _simd provides versions for compile-time
135and run-time unrolled code:
136
137template <typename float_type,
138 typename Arg1,
139 typename Arg2
140 >
141inline void foo_vec(float_type * out, Arg1 arg1, Arg2 arg2, unsigned int n);
142
143template <typename float_type,
144 typename Arg1,
145 typename Arg2
146 >
147inline void foo_vec_simd(float_type * out, Arg1 arg1, Arg2 arg2, unsigned int n);
148
149template <unsigned int n,
150 typename float_type,
151 typename Arg1,
152 typename Arg2
153 >
154inline void foo_vec_simd(float_type * out, Arg1 arg1, Arg2 arg2);
155
156
157for scalar arguments, an extension is provided to support ramping by
158adding a slope to the scalar after each iteration. for binary functions,
159c++ function overloading is used. compile-time unrolled versions of these
160functions are also provided.
161
162
163argument wrapper:
164to support different kinds of arguments with a generic interface, nova-simd provides
165argument wrappers. these can be generated with the following functions:
166
167/* wrap a scalar argument */
168template <typename FloatType>
169/unspecified/ nova::wrap_arguments(FloatType f);
170
171/* wrap a vector argument */
172template <typename FloatType>
173/unspecified/ nova::wrap_arguments(const FloatType * f);
174
175/* wrap a ramp argument */
176template <typename FloatType>
177/unspecified/ nova::wrap_arguments(FloatType base, FloatType slope);
178
179
180building and testing:
181
182nova simd is a header-only library, so it cannot be compiled as
183standalone libray. however some benchmark and test programs are
184provided, using a cmake build system.
185