Changeset 16274 for trunk/HeuristicLab.ExtLibs/HeuristicLab.NativeInterpreter/0.1/NativeInterpreter-0.1/src/vector_operations.h
- Timestamp:
- 11/04/18 11:05:31 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.ExtLibs/HeuristicLab.NativeInterpreter/0.1/NativeInterpreter-0.1/src/vector_operations.h
r16269 r16274 2 2 #define VECTOR_OPERATIONS_H 3 3 4 #define _USE_MATH_DEFINES 5 #include <cmath> 4 6 #include <cstring> 5 #include <cmath>6 7 7 8 #ifdef USE_VDT … … 27 28 #endif 28 29 29 constexpr int B UFSIZE = 64;30 constexpr int BATCHSIZE = 64; 30 31 31 #define FOR(i) for(int i = 0; i < B UFSIZE; ++i)32 #define FOR(i) for(int i = 0; i < BATCHSIZE; ++i) 32 33 33 34 // When auto-vectorizing without __restrict, … … 36 37 37 38 // vector - vector operations 38 inline void load(double* __restrict a, double* __restrict b) noexcept { std::memcpy(a, b, BUFSIZE * sizeof(double)); } 39 inline void add(double* __restrict a, double* __restrict b) noexcept { FOR(i) a[i] += b[i]; } 40 inline void sub(double* __restrict a, double* __restrict b) noexcept { FOR(i) a[i] -= b[i]; } 41 inline void mul(double* __restrict a, double* __restrict b) noexcept { FOR(i) a[i] *= b[i]; } 42 inline void div(double* __restrict a, double* __restrict b) noexcept { FOR(i) a[i] /= b[i]; } 43 inline void exp(double* __restrict a, double* __restrict b) noexcept { FOR(i) a[i] = hl_exp(b[i]); } 44 inline void log(double* __restrict a, double* __restrict b) noexcept { FOR(i) a[i] = hl_log(b[i]); } 45 inline void sin(double* __restrict a, double* __restrict b) noexcept { FOR(i) a[i] = hl_sin(b[i]); } 46 inline void cos(double* __restrict a, double* __restrict b) noexcept { FOR(i) a[i] = hl_cos(b[i]); } 47 inline void tan(double* __restrict a, double* __restrict b) noexcept { FOR(i) a[i] = hl_tan(b[i]); } 48 inline void sqrt(double* __restrict a, double* __restrict b) noexcept { FOR(i) a[i] = hl_sqrt(b[i]); } 49 inline void pow(double* __restrict a, double* __restrict b) noexcept { FOR(i) a[i] = hl_pow(a[i], hl_round(b[i])); }; 50 inline void root(double* __restrict a, double* __restrict b) noexcept { FOR(i) a[i] = hl_pow(a[i], 1 / hl_round(b[i])); }; 51 inline void square(double* __restrict a, double* __restrict b) noexcept { FOR(i) a[i] = b[i] * b[i]; }; 39 inline void load(double* __restrict a, double const * __restrict b) noexcept { std::memcpy(a, b, BATCHSIZE * sizeof(double)); } 40 inline void add(double* __restrict a, double const * __restrict b) noexcept { FOR(i) a[i] += b[i]; } 41 inline void sub(double* __restrict a, double const * __restrict b) noexcept { FOR(i) a[i] -= b[i]; } 42 inline void mul(double* __restrict a, double const * __restrict b) noexcept { FOR(i) a[i] *= b[i]; } 43 inline void div(double* __restrict a, double const * __restrict b) noexcept { FOR(i) a[i] /= b[i]; } 44 inline void exp(double* __restrict a, double const * __restrict b) noexcept { FOR(i) a[i] = hl_exp(b[i]); } 45 inline void log(double* __restrict a, double const * __restrict b) noexcept { FOR(i) a[i] = hl_log(b[i]); } 46 inline void sin(double* __restrict a, double const * __restrict b) noexcept { FOR(i) a[i] = hl_sin(b[i]); } 47 inline void cos(double* __restrict a, double const * __restrict b) noexcept { FOR(i) a[i] = hl_cos(b[i]); } 48 inline void tan(double* __restrict a, double const * __restrict b) noexcept { FOR(i) a[i] = hl_tan(b[i]); } 49 inline void sqrt(double* __restrict a, double const * __restrict b) noexcept { FOR(i) a[i] = hl_sqrt(b[i]); } 50 inline void pow(double* __restrict a, double const * __restrict b) noexcept { FOR(i) a[i] = hl_pow(a[i], hl_round(b[i])); }; 51 inline void root(double* __restrict a, double const * __restrict b) noexcept { FOR(i) a[i] = hl_pow(a[i], 1. / hl_round(b[i])); }; 52 inline void square(double* __restrict a, double const * __restrict b) noexcept { FOR(i) a[i] = hl_pow(b[i], 2.); }; 53 inline void inv(double* __restrict a, double const * __restrict b) noexcept { FOR(i) a[i] = 1. / b[i]; } 54 inline void neg(double* __restrict a, double const * __restrict b) noexcept { FOR(i) a[i] = -b[i]; } 52 55 53 56 // vector - scalar operations … … 60 63 // vector operations 61 64 inline void neg(double* __restrict a) noexcept { FOR(i) a[i] = -a[i]; } 62 inline void inv(double* __restrict a) noexcept { FOR(i) a[i] = 1 / a[i]; }65 inline void inv(double* __restrict a) noexcept { FOR(i) a[i] = 1. / a[i]; } 63 66 inline void exp(double* __restrict a) noexcept { FOR(i) a[i] = hl_exp(a[i]); } 64 67 inline void log(double* __restrict a) noexcept { FOR(i) a[i] = hl_log(a[i]); } … … 67 70 inline void sqrt(double* __restrict a) noexcept { FOR(i) a[i] = hl_sqrt(a[i]); } 68 71 inline void round(double* __restrict a) noexcept { FOR(i) a[i] = hl_round(a[i]); } 69 inline void square(double* __restrict a) noexcept { FOR(i) a[i] = a[i] * a[i];; }72 inline void square(double* __restrict a) noexcept { FOR(i) a[i] = hl_pow(a[i], 2.); } 70 73 71 74 #undef FOR
Note: See TracChangeset
for help on using the changeset viewer.