Vectorization Method of the BiSheng Compiler
When using the BiSheng Compiler, add -lksvml -fveclib=MATHLIB -lkm -lm to the link option and add the -O3 or -O2 option to enable the vector interface. -O3/-O2 is used to enable vectorization optimization, which is the prerequisite for the vectorized math library to take effect.
Examples
test.c:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include <km.h> #include <stdio.h> #include <stdlib.h> int main() { long loop = 1e7; int len = 8192; float *a = (float*)malloc(sizeof(float) * len); float *b = (float*)malloc(sizeof(float) * len); float *d = (float*)malloc(sizeof(float) * len); for (int i = 0; i < len; i++) { a[i] = rand() * 7.7680f - 6.3840f; b[i] = rand() * 8.7680f - 6.3840f; d[i] = 0; } for (int i = 0; i < loop; i++) { for (int j = 0; j < len; j++) { d[j] = expf(a[j]); } } printf("%f\n", d[0]); return 1; } |
Compile command:
1 | clang test.c -lksvml -fveclib=MATHLIB -lkm -lm -O3 |
Run the nm command to check the called interface.
1 | nm -D a.out |

If the _ZGVnN4v_ prefix interface is displayed, the calling is successful.
Parent topic: Compiler Automatic Vectorization