Get started
There are several ways to use SIMD in your C/C++ program. The most direct way is to embed SIMD assembly in your code, which is apparently cumbersome and error-prone. You can also let the compiler automatically optimize your code with SIMD by using openMP (we will cover openMP later in this course). For example:
However, the code patterns that can be automatically detected and optimized by Compiler are limited.
SIMD intrinsics are convenient if you want to manually optimize your code using SIMD without touching assembly. It is basically a library that wraps SIMD assembly as C functions. Let's re-write our vector addition example by SIMD intrinsics.
Before we explain the details of the code, let's compile and run the program first. To compile the above code with SSE enabled, run the following code:
Run the compiled executable, you can see the result is as expected:
Last updated
Was this helpful?