46 #if defined(__ARM_ARCH_ISA_A64) || defined(__ARM_NEON) || \
47 defined(__ARM_ARCH) || defined(__aarch64__)
59 const std::vector<double> &vec2,
60 std::vector<double> &result) {
61 const size_t size = vec1.size();
62 const double *data1 = vec1.data();
63 const double *data2 = vec2.data();
64 double *result_data = result.data();
68 for (
size_t i = 0; i < size; i += 2) {
70 float64x2_t a = vld1q_f64(data1 + i);
71 float64x2_t b = vld1q_f64(data2 + i);
74 float64x2_t c = vaddq_f64(a, b);
77 vst1q_f64(result_data + i, c);
81 for (
size_t i = 0; i < size; ++i) {
82 result_data[i] = data1[i] + data2[i];
89 const std::vector<double> &vec2,
90 std::vector<double> &result) {
91 const int vecSize = vec1.size();
92 const int remainder = vecSize % 4;
93 const int vecSizeAligned = vecSize - remainder;
95 for (
int i = 0; i < vecSizeAligned; i += 4) {
96 float64x2_t vec1Data1 = vld1q_f64(&vec1[i]);
97 float64x2_t vec1Data2 = vld1q_f64(&vec1[i + 2]);
98 float64x2_t vec2Data1 = vld1q_f64(&vec2[i]);
99 float64x2_t vec2Data2 = vld1q_f64(&vec2[i + 2]);
101 float64x2_t sub1 = vsubq_f64(vec1Data1, vec2Data1);
102 float64x2_t sub2 = vsubq_f64(vec1Data2, vec2Data2);
104 vst1q_f64(&result[i], sub1);
105 vst1q_f64(&result[i + 2], sub2);
108 for (
int i = vecSizeAligned; i < vecSize; ++i) {
109 result[i] = vec1[i] - vec2[i];
116 std::vector<double> &result) {
117 const size_t size = vec.size();
118 const double *data = vec.data();
119 double *result_data = result.data();
122 float64x2_t scalar_vec = vdupq_n_f64(scalar);
124 for (; i < size - 1; i += 2) {
126 float64x2_t a = vld1q_f64(data + i);
129 float64x2_t c = vmulq_f64(a, scalar_vec);
132 vst1q_f64(result_data + i, c);
136 for (; i < size; ++i) {
137 result_data[i] = data[i] * scalar;
140 for (
size_t i = 0; i < size; ++i) {
141 result_data[i] = data[i] * scalar;
148 const std::vector<double> &vec2) {
149 const size_t size = vec1.size();
150 const double *data1 = vec1.data();
151 const double *data2 = vec2.data();
155 float64x2_t sum_vec = vdupq_n_f64(0.0);
157 for (; i < size - 1; i += 2) {
159 float64x2_t a = vld1q_f64(data1 + i);
160 float64x2_t b = vld1q_f64(data2 + i);
163 float64x2_t mul = vmulq_f64(a, b);
166 sum_vec = vaddq_f64(sum_vec, mul);
171 vst1q_f64(temp, sum_vec);
172 result = temp[0] + temp[1];
175 for (; i < size; ++i) {
176 result += data1[i] * data2[i];
179 for (
size_t i = 0; i < size; ++i) {
180 result += data1[i] * data2[i];
int dot_product(const std::vector< int8_t > &vec1, const std::vector< int8_t > &vec2)
Computes the dot product for vectors of signed 8-bit integers.
void vector_sub(const std::vector< int8_t > &vec1, const std::vector< int8_t > &vec2, std::vector< int8_t > &result)
Performs vector subtraction for vectors of signed 8-bit integers.
void scalar_mult(const std::vector< int8_t > &vec1, int scalar, std::vector< int8_t > &result)
Performs scalar multiplication for vectors of signed 8-bit integers.
void vector_add(const std::vector< int8_t > &vec1, const std::vector< int8_t > &vec2, std::vector< int8_t > &result)
Performs vector addition for vectors of signed 8-bit integers.