我要评分
获取效率
正确性
完整性
易理解

AVX Instruction Class

AVX instructions are Intel internal instructions and can be used only on x86 servers. The instruction names and functions implemented by the AVX2KI library are the same as those of the AVX instructions.

Example

  1. Create a testavx.cpp file.
  2. Press i to enter the insert mode and add the following content to the file:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    #include <stdio.h>
    #include <stdlib.h>
    #include <stdint.h>
    #include "avx2ki.h"
    
    void AvxExample()
    {
        int32_t a[4] = {-5, 13, 4, -20};
        int32_t b[4] = {12, 3, 0, 7};
        int32_t c[4] = {0};
        __m128i t1 = _mm_load_epi32(a);
        __m128i t2 = _mm_load_epi32(b);
        __m128i dst = _mm_add_epi32(t1, t2);
        _mm_store_epi32(c, dst);
        printf("dst: %d %d %d %d\n", c[0], c[1], c[2], c[3]);
    }
    
    int main(void) {
        AvxExample();
        return 0;
    }
    
  3. Press Esc, type :wq!, and press Enter to save the file and exit.
  4. Compile the testavx.cpp file and specify the name of the output executable file as testavx.
    g++ testavx.cpp -o testavx -I/usr/local/ksl/include -L/usr/local/ksl/lib -lavx2ki
  5. Run the testavx executable file.
    ./testavx
    The execution result is as follows:
    dst: 7 16 4 -13