# Linux Kernel Module Cheat

##### 28.6.5.1. GCC x86 intrinsics

Good official cheatsheet with all intrinsics and what they expand to: https://software.intel.com/sites/landingpage/IntrinsicsGuide

The functions use the the following naming convention:

    <vector_size>_<intrin_op>_<suffix>

where:

- `<vector_size>`:

  - `mm`: 128-bit vectors (SSE)

  - `mm256`: 256-bit vectors (AVX and AVX2)

  - `mm512`: 512-bit vectors (AVX512)

- `<intrin_op>`: operation of the intrinsic function, e.g. add, sub, mul, etc.

- `<suffix>`: data type:

  - `ps`: 4 floats (Packed Single)

  - `pd`: 2 doubles (Packed Double)

  - `ss`: 1 float (Single Single), often the lowest order one

  - `sd`: 1 double (Single Double)

  - `si128`: 128-bits of integers of any size

  - `ep<int_type>` integer types, e.g.:

    - `epi32`: 32 bit signed integers

    - `epu16`: 16 bit unsigned integers

Data types:

- `__m128`: four floats

- `__m128d`: two doubles

- `__m128i`: integers: 8 x 16-bit, 4 x 32-bit, 2 x 64-bit

The headers to include are clarified at: https://stackoverflow.com/questions/11228855/header-files-for-x86-simd-intrinsics

    x86intrin.h everything
    mmintrin.h  MMX
    xmmintrin.h SSE
    emmintrin.h SSE2
    pmmintrin.h SSE3
    tmmintrin.h SSSE3
    smmintrin.h SSE4.1
    nmmintrin.h SSE4.2
    ammintrin.h SSE4A
    wmmintrin.h AES
    immintrin.h AVX
    zmmintrin.h AVX512

Present in `gcc-7_3_0-release` tree at: `gcc/config/i386/x86intrin.h`.

Bibliography:

- https://www.cs.virginia.edu/~cr4bd/3330/S2018/simdref.html

- https://software.intel.com/en-us/articles/how-to-use-intrinsics