46 #if defined(__ARM_ARCH_ISA_A64) || defined(__ARM_NEON) || \
47 defined(__ARM_ARCH) || defined(__aarch64__)
59 const std::vector<int> &vec2,
60 std::vector<int> &result) {
61 const size_t size = vec1.size();
62 const int *data1 = vec1.data();
63 const int *data2 = vec2.data();
64 int *result_data = result.data();
68 for (
size_t i = 0; i < size; i += 4) {
70 int32x4_t a = vld1q_s32(data1 + i);
71 int32x4_t b = vld1q_s32(data2 + i);
74 int32x4_t c = vaddq_s32(a, b);
77 vst1q_s32(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<int> &vec2,
90 std::vector<int> &result) {
91 const int vecSize = vec1.size();
92 const int remainder = vecSize % 8;
93 const int vecSizeAligned = vecSize - remainder;
95 for (
int i = 0; i < vecSizeAligned; i += 8) {
96 int32x4_t vec1Data1 = vld1q_s32(&vec1[i]);
97 int32x4_t vec1Data2 = vld1q_s32(&vec1[i + 4]);
98 int32x4_t vec2Data1 = vld1q_s32(&vec2[i]);
99 int32x4_t vec2Data2 = vld1q_s32(&vec2[i + 4]);
101 int32x4_t sub1 = vsubq_s32(vec1Data1, vec2Data1);
102 int32x4_t sub2 = vsubq_s32(vec1Data2, vec2Data2);
104 vst1q_s32(&result[i], sub1);
105 vst1q_s32(&result[i + 4], sub2);
108 for (
int i = vecSizeAligned; i < vecSize; ++i) {
109 result[i] = vec1[i] - vec2[i];
116 std::vector<int> &result) {
117 const size_t size = vec.size();
118 const int32_t *data = vec.data();
119 int32_t *result_data = result.data();
122 int32x4_t scalar_vec = vdupq_n_s32(scalar);
124 for (; i < size - 3; i += 4) {
126 int32x4_t a = vld1q_s32(data + i);
129 int32x4_t c = vmulq_s32(a, scalar_vec);
132 vst1q_s32(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<int> &vec2) {
149 const size_t size = vec1.size();
150 const int32_t *data1 = vec1.data();
151 const int32_t *data2 = vec2.data();
155 int32x4_t sum_vec = vdupq_n_s32(0);
157 for (; i < size - 3; i += 4) {
159 int32x4_t a = vld1q_s32(data1 + i);
160 int32x4_t b = vld1q_s32(data2 + i);
162 int32x4_t mul = vmulq_s32(a, b);
165 sum_vec = vaddq_s32(sum_vec, mul);
170 vst1q_s32(temp, sum_vec);
171 result = temp[0] + temp[1] + temp[2] + temp[3];
174 for (; i < size; ++i) {
175 result += data1[i] * data2[i];
180 for (
size_t i = 0; i < size; ++i) {
181 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.