vma
Perform multiply-add operations on real-number vectors.
The function interface declaration is as follows:
Operations on numbers of the float type:
void (vsip_vma_f)(const vsip_vview_f *a, const vsip_vview_f *b, const vsip_vview_f *c, const vsip_vview_f *r);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
a |
Pointer to the source vector |
The value cannot be NULL. |
Input |
b |
Pointer to the source vector |
The value cannot be NULL. |
Input |
c |
Pointer to the source vector |
The value cannot be NULL. |
Input |
r |
Pointer to the destination vector |
The value cannot be NULL. |
Output |
Abnormal Input
When a null pointer is input, the function directly returns a result.
Example
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "kvsip.h"
#include "vsip.h"
#include "vsip_type.h"
#define BUFFER_SIZE_T 10
void VmaExample()
{
float src1[BUFFER_SIZE_T] = {1.64f, 1.63f, -1.09f, 0.71f, -3.20f, -0.43f, 0.41f, -4.83f, 5.36f, -4.40f};
float src2[BUFFER_SIZE_T] = {-0.23f, 3.15f, -7.11f, 5.94f, 4.38f, 6.51f, -7.28f, -3.27f, 1.08f, 3.28f};
float src3[BUFFER_SIZE_T] = {0.1f, 2.2f, -1.31f, 4.23f, 0.38f, 1.31f, -2.57f, -5.13f, 0.03f, 1.94f};
float dst[BUFFER_SIZE_T];
int64_t stride = 1;
uint64_t offset = 0;
vsip_block_f *block_a = vsip_blockbind_f(src1, BUFFER_SIZE_T, VSIP_MEM_NONE);
vsip_block_f *block_b = vsip_blockbind_f(src2, BUFFER_SIZE_T, VSIP_MEM_NONE);
vsip_block_f *block_c = vsip_blockbind_f(src3, BUFFER_SIZE_T, VSIP_MEM_NONE);
vsip_block_f *block_r = vsip_blockbind_f(dst, BUFFER_SIZE_T, VSIP_MEM_NONE);
vsip_vview_f *a = vsip_vbind_f(block_a, offset, stride, BUFFER_SIZE_T);
vsip_blockadmit_f(block_a, VSIP_TRUE);
vsip_vview_f *b = vsip_vbind_f(block_b, offset, stride, BUFFER_SIZE_T);
vsip_blockadmit_f(block_a, VSIP_TRUE);
vsip_vview_f *c = vsip_vbind_f(block_c, offset, stride, BUFFER_SIZE_T);
vsip_blockadmit_f(block_a, VSIP_TRUE);
vsip_vview_f *r = vsip_vbind_f(block_r, offset, stride, BUFFER_SIZE_T);
vsip_blockadmit_f(block_r, VSIP_TRUE);
vsip_vma_f(a, b, c, r);
vsip_valldestroy_f(a);
vsip_valldestroy_f(b);
vsip_valldestroy_f(c);
vsip_valldestroy_f(r);
printf("src1:\n");
for (int32_t i = 0; i < BUFFER_SIZE_T; ++i) {
printf("%.4f ", src1[i]);
}
printf("\nsrc2:\n");
for (int32_t i = 0; i < BUFFER_SIZE_T; ++i) {
printf("%.4f ", src2[i]);
}
printf("\nsrc3:\n");
for (int32_t i = 0; i < BUFFER_SIZE_T; ++i) {
printf("%.4f ", src3[i]);
}
printf("\ndst:\n");
for (int32_t i = 0; i < BUFFER_SIZE_T; ++i) {
printf("%.4f ", dst[i]);
}
printf("\n");
}
int main(void) {
VmaExample();
return 0;
}
Output:
src1: 1.6400 1.6300 -1.0900 0.7100 -3.2000 -0.4300 0.4100 -4.8300 5.3600 -4.4000 src2: -0.2300 3.1500 -7.1100 5.9400 4.3800 6.5100 -7.2800 -3.2700 1.0800 3.2800 src3: 0.1000 2.2000 -1.3100 4.2300 0.3800 1.3100 -2.5700 -5.1300 0.0300 1.9400 dst: -0.2772 7.3345 6.4399 8.4474 -13.6360 -1.4893 -5.5548 10.6641 5.8188 -12.4920
Parent topic: Vector Operation Functions