memcpy: hide some memory latencies
[nova-simd.git] / README
blobb021def1020ea43beed086bced93b4299a621269
1 nova simd
3 nova simd provides a framework of simdfied vector functions, designed
4 mainly for computer music applications.
5 it currently supports the following instruction sets:
6 - sse/sse2 family
7 - ppc/altivec
8 - avx
9 - arm/neon
12 vec class:
13 the simd functionality is built around a templated vec class. it usually maps
14 to a simd vector. the vec class can be used to compose more specific algorithms,
15 hiding different implementations under a common API.
17 template <typename FloatType>
18 class vec
20 public:
21     typedef FloatType float_type;
23     static const int size; // number of samples per vector
24     static const int objects_per_cacheline; // typical number of objects per cacheline
26     /* constructors */
27     vec(void);
28     vec(double f);
29     vec(float f);
30     vec(vec const & rhs);
32     /* element access */
33     FloatType get (int index) const;
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);
41     /* load and store */
42     void load(const WrappedType * src);
43     void load_first(const WrappedType * src);
44     void load_aligned(const WrappedType * data);
46     void store(WrappedType * dest) const;
47     void store_aligned(WrappedType * dest) const;
48     void store_aligned_stream(WrappedType * dest) const;
50     void clear(void);
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
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)
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
69     friend vec madd(vec const & arg1, vec const & arg2, vec const & arg3);
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);
78     friend vec tanh(vec const & arg);
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);
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);
91     friend vec signed_sqrt(vec const & arg);
92     friend vec signed_pow(vec const & lhs, vec const & rhs);
94     friend vec min_(vec const & lhs, vec const & rhs);
95     friend vec max_(vec const & lhs, vec const & rhs);
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);
105 vector functions:
107 this vec class has been used as building block for a number of vector functions,
108 which provides a traditional c++-style interface to perform a specific operation
109 on buffers.
110 (for details consult the simd_*.hpp files)
112 for an unary operation `foo', the following functions must be:
114 /* arbitrary number of iterations */
115 template <typename float_type>
116 inline void foo_vec(float_type * out, const float_type * in, unsigned int n);
118 /* number of iterations must be a multiple of
119  * unroll_constraints<float_type>::samples_per_loop
120  */
121 template <typename float_type>
122 inline void foo_vec_simd(float_type * out, const float_type * in, unsigned int n);
124 /* number of iterations must be a multiple of
125  * unroll_constraints<float_type>::samples_per_loop
126  */
127 template <int n,
128           typename FloatType
129          >
130 inline void foo_vec_simd(FloatType * out, const FloatType * in);
133 for binary and ternary operations, instances are provided for mixed
134 vector and scalar arguments. using the suffix _simd provides versions for compile-time
135 and run-time unrolled code:
137 template <typename float_type,
138           typename Arg1,
139           typename Arg2
140          >
141 inline void foo_vec(float_type * out, Arg1 arg1, Arg2 arg2, unsigned int n);
143 template <typename float_type,
144           typename Arg1,
145           typename Arg2
146          >
147 inline void foo_vec_simd(float_type * out, Arg1 arg1, Arg2 arg2, unsigned int n);
149 template <unsigned int n,
150           typename float_type,
151           typename Arg1,
152           typename Arg2
153          >
154 inline void foo_vec_simd(float_type * out, Arg1 arg1, Arg2 arg2);
157 for scalar arguments, an extension is provided to support ramping by
158 adding a slope to the scalar after each iteration. for binary functions,
159 c++ function overloading is used. compile-time unrolled versions of these
160 functions are also provided.
163 argument wrapper:
164 to support different kinds of arguments with a generic interface, nova-simd provides
165 argument wrappers. these can be generated with the following functions:
167 /* wrap a scalar argument */
168 template <typename FloatType>
169 /unspecified/ nova::wrap_arguments(FloatType f);
171 /* wrap a vector argument */
172 template <typename FloatType>
173 /unspecified/ nova::wrap_arguments(const FloatType * f);
175 /* wrap a ramp argument */
176 template <typename FloatType>
177 /unspecified/ nova::wrap_arguments(FloatType base, FloatType slope);
180 building and testing:
182 nova simd is a header-only library, so it cannot be compiled as
183 standalone libray. however some benchmark and test programs are
184 provided, using a cmake build system.